Skip to content

Const generics ICE: no type-dependent def for method #70586

Description

@DutchGhost

Code

#![feature(const_generics)]

use core::marker::PhantomData;

// this namespace is necessary for the ICE to trigger
struct namespace;

impl namespace {
    pub fn const_chunks_exact<T, const N: usize>() -> ConstChunksExact<'static, T, { N }> {
        ConstChunksExact { inner: PhantomData }
    }
}


#[derive(Debug)]
pub struct ConstChunksExact<'a, T, const N: usize> {
    inner:  PhantomData<&'a T>
}

impl <'a, T, const N: usize> Iterator for ConstChunksExact<'a, T, { N }> {
    type Item = &'a [T; N];

    fn next(&mut self) -> Option<Self::Item> {
        unreachable!()
    }
}

fn main() {
    let mut chunks = namespace::const_chunks_exact::<i32, {3usize}>();
    let next: &[i32; 3] = chunks.next().unwrap();
}

Meta

rustc --version --verbose:

rustc 1.44.0-nightly (699f83f52 2020-03-29) running on x86_64-unknown-linux-gnu

Error output

error: internal compiler error: src/librustc_passes/dead.rs:111: no type-dependent def for method
Backtrace

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:880:9
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.life-white.uk-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.life-white.uk-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1069
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1439
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:218
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:515
  12: std::panicking::begin_panic
  13: rustc_errors::HandlerInner::bug
  14: rustc_errors::Handler::bug
  15: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  16: rustc::ty::context::tls::with_opt::{{closure}}
  17: rustc::ty::context::tls::with_opt
  18: rustc::util::bug::opt_span_bug_fmt
  19: rustc::util::bug::bug_fmt
  20: <rustc_passes::dead::MarkSymbolVisitor as rustc_hir::intravisit::Visitor>::visit_expr
  21: rustc_hir::intravisit::walk_stmt
  22: rustc_hir::intravisit::walk_expr
  23: rustc_hir::intravisit::walk_fn
  24: rustc_hir::intravisit::Visitor::visit_fn
  25: rustc_hir::intravisit::walk_item
  26: rustc_passes::dead::check_crate
  27: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  28: rustc_session::utils::<impl rustc_session::session::Session>::time
  29: rustc_interface::passes::analysis
  30: rustc::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc::ty::context::TyCtxt> for rustc::ty::query::queries::analysis>::compute
  31: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  32: rustc_query_system::query::plumbing::get_query
  33: rustc::ty::context::tls::enter_global
  34: rustc_interface::interface::run_compiler_in_existing_thread_pool
  35: scoped_tls::ScopedKey<T>::set
  36: rustc_ast::attr::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.44.0-nightly (699f83f52 2020-03-29) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

error: could not compile `playground`.

Activity

  1. added
    C-bugCategory: This is a bug.
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Mar 30, 2020
  2. added
    A-const-genericsArea: const generics (parameters and arguments)
    requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
    on Mar 30, 2020
  3. steffahn commented on Mar 31, 2020

    @steffahn
    Member

    Example made smaller

    #![feature(const_generics)]
    
    struct T;
    impl T {
        fn new_s<const N: u8>() -> S<N> { S }
    }
    
    struct S<const N: u8>;
    impl<const N: u8> S<N> {
        fn method(&self) {}
    }
    
    fn main() {
        T::new_s::<1u8>().method();
    }

    (Playground)

    Errors:
       Compiling playground v0.0.1 (/playground)
    warning: the feature `const_generics` is incomplete and may cause the compiler to crash
     --> src/main.rs:1:12
      |
    1 | #![feature(const_generics)]
      |            ^^^^^^^^^^^^^^
      |
      = note: `#[warn(incomplete_features)]` on by default
    
    error: internal compiler error: src/librustc_passes/dead.rs:111: no type-dependent def for method
    
    thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:880:9
    stack backtrace:
       0: backtrace::backtrace::libunwind::trace
                 at /cargo/registry/src/github.life-white.uk-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
       1: backtrace::backtrace::trace_unsynchronized
                 at /cargo/registry/src/github.life-white.uk-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
       2: std::sys_common::backtrace::_print_fmt
                 at src/libstd/sys_common/backtrace.rs:78
       3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
                 at src/libstd/sys_common/backtrace.rs:59
       4: core::fmt::write
                 at src/libcore/fmt/mod.rs:1069
       5: std::io::Write::write_fmt
                 at src/libstd/io/mod.rs:1439
       6: std::sys_common::backtrace::_print
                 at src/libstd/sys_common/backtrace.rs:62
       7: std::sys_common::backtrace::print
                 at src/libstd/sys_common/backtrace.rs:49
       8: std::panicking::default_hook::{{closure}}
                 at src/libstd/panicking.rs:198
       9: std::panicking::default_hook
                 at src/libstd/panicking.rs:218
      10: rustc_driver::report_ice
      11: std::panicking::rust_panic_with_hook
                 at src/libstd/panicking.rs:515
      12: std::panicking::begin_panic
      13: rustc_errors::HandlerInner::bug
      14: rustc_errors::Handler::bug
      15: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
      16: rustc_middle::ty::context::tls::with_opt::{{closure}}
      17: rustc_middle::ty::context::tls::with_opt
      18: rustc_middle::util::bug::opt_span_bug_fmt
      19: rustc_middle::util::bug::bug_fmt
      20: <rustc_passes::dead::MarkSymbolVisitor as rustc_hir::intravisit::Visitor>::visit_expr
      21: rustc_hir::intravisit::walk_expr
      22: rustc_hir::intravisit::walk_fn
      23: rustc_hir::intravisit::Visitor::visit_fn
      24: rustc_hir::intravisit::walk_item
      25: rustc_passes::dead::check_crate
      26: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
      27: rustc_session::utils::<impl rustc_session::session::Session>::time
      28: rustc_interface::passes::analysis
      29: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
      30: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
      31: rustc_query_system::query::plumbing::get_query
      32: rustc_middle::ty::context::tls::enter_global
      33: rustc_interface::interface::run_compiler_in_existing_thread_pool
      34: scoped_tls::ScopedKey<T>::set
      35: rustc_ast::attr::with_globals
    note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
    
    note: the compiler unexpectedly panicked. this is a bug.
    
    note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
    
    note: rustc 1.44.0-nightly (211365947 2020-03-30) running on x86_64-unknown-linux-gnu
    
    note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type bin
    
    note: some of the compiler flags provided by cargo are hidden
    
    query stack during panic:
    #0 [analysis] running analysis passes on this crate
    end of query stack
    error: aborting due to previous error
    
    error: could not compile `playground`.
    
    To learn more, run the command again with --verbose.
    

    Edit: The current error message “no type-dependent def for method” happens (on the smaller example) since nightly-2020-03-25. This is the same nightly as in #70507. Downloading the relevant CI builds in bisect-rustc is impossibly slow (i.e. not working) for me at the moment, but I’d be surprised if it isn’t 342c5f3 for this one as well.

  4. added 2 commits that reference this issue on Jul 16, 2020
    658d5d0
    c354524
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)A-lazy-normalizationArea: Lazy normalization (tracking issue: #60471)C-bugCategory: This is a bug.F-const_generics`#![feature(const_generics)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions