Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE: Failed to get layout for [type error]: #70507

Closed
DutchGhost opened this issue Mar 28, 2020 · 6 comments · Fixed by #74392
Closed

ICE: Failed to get layout for [type error]: #70507

DutchGhost opened this issue Mar 28, 2020 · 6 comments · Fixed by #74392
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@DutchGhost
Copy link
Contributor

DutchGhost commented Mar 28, 2020

I hit this ice when trying implement #60735.
The ice message looks very similar to #70291, which has been closed already.

Code

#![feature(const_generics)]

trait ConstChunksExactTrait<T> {
    fn const_chunks_exact<const N: usize>(&self) -> ConstChunksExact<'_, T, {N}>;
}

impl <T> ConstChunksExactTrait<T> for [T] {
    fn const_chunks_exact<const N: usize>(&self) -> ConstChunksExact<'_, T, {N}> {

        assert!(N != 0);
        let rem = self.len() % N;
        let len = self.len() - rem;
        let (fst, snd) = self.split_at(len);
        ConstChunksExact { v: fst, rem: snd }
    }
}

struct ConstChunksExact<'a, T: 'a, const N: usize> {
    v: &'a [T],
    rem: &'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> {
        if self.v.len() < N {
            None
        } else {
            let (fst, snd) = self.v.split_at(N);
            
            self.v = snd;
            
            let ptr = fst.as_ptr() as *const _;
            Some(unsafe { *ptr})
        }
    }
}

fn main() {
    let slice = &[1i32, 2, 3, 4, 5, 6, 7, 8, 9, 10];
    
    for a in slice.const_chunks_exact::<{3usize}>() {
        dbg!(a);
    }
}

Meta

rustc --version --verbose:

rustc 1.44.0-nightly (75208942f 2020-03-27)
Backtrace

error: internal compiler error: src/librustc_codegen_llvm/context.rs:854: failed to get layout for `[type error]`: the type `[type error]` has an unknown layout

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.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-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_codegen_llvm::context::CodegenCx as rustc_target::abi::LayoutOf>::spanned_layout_of::{{closure}}
  21: <rustc_codegen_llvm::context::CodegenCx as rustc_target::abi::LayoutOf>::spanned_layout_of
  22: rustc_codegen_ssa::mir::analyze::non_ssa_locals
  23: rustc_codegen_ssa::mir::codegen_mir
  24: <rustc::mir::mono::MonoItem as rustc_codegen_ssa::mono_item::MonoItemExt>::define
  25: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
  26: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  27: rustc_codegen_llvm::base::compile_codegen_unit
  28: rustc_codegen_ssa::base::codegen_crate
  29: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  30: rustc_interface::passes::start_codegen
  31: rustc::ty::context::tls::enter_global
  32: rustc_interface::queries::Queries::ongoing_codegen
  33: rustc_interface::interface::run_compiler_in_existing_thread_pool
  34: 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 (75208942f 2020-03-27) 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:
end of query stack
error: aborting due to previous error

error: could not compile `playground`.

@DutchGhost DutchGhost added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 28, 2020
@DutchGhost DutchGhost changed the title ailed to get layout for [type error]: ICE: Failed to get layout for [type error]: Mar 28, 2020
@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. labels Mar 28, 2020
@steffahn
Copy link
Member

steffahn commented Mar 28, 2020

When I switch from “Run” to “Build” in the playground, the error changes.

Long error message (collapsed)
   Compiling playground v0.0.1 (/playground)
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
 --> src/lib.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default

warning: field is never read: `rem`
  --> src/lib.rs:20:5
   |
20 |     rem: &'a [T]
   |     ^^^^^^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: function is never used: `main`
  --> src/lib.rs:40:4
   |
40 | fn main() {
   |    ^^^^

error: internal compiler error: unexpected const parent in type_of_def_id(): Expr(Expr { hir_id: HirId { owner: DefId(0:27 ~ playground[7ff2]::main[0]), local_id: 30 }, kind: MethodCall(PathSegment { ident: const_chunks_exact#0, hir_id: Some(HirId { owner: DefId(0:27 ~ playground[7ff2]::main[0]), local_id: 27 }), res: Some(Err), args: Some(GenericArgs { args: [Const(ConstArg { value: AnonConst { hir_id: HirId { owner: DefId(0:27 ~ playground[7ff2]::main[0]), local_id: 23 }, body: BodyId { hir_id: HirId { owner: DefId(0:27 ~ playground[7ff2]::main[0]), local_id: 26 } } }, span: src/lib.rs:43:41: 43:49 })], bindings: [], parenthesized: false }), infer_args: false }, src/lib.rs:43:20: 43:38, [Expr { hir_id: HirId { owner: DefId(0:27 ~ playground[7ff2]::main[0]), local_id: 29 }, kind: Path(Resolved(None, Path { span: src/lib.rs:43:14: 43:19, res: Local(HirId { owner: DefId(0:27 ~ playground[7ff2]::main[0]), local_id: 1 }), segments: [PathSegment { ident: slice#0, hir_id: Some(HirId { owner: DefId(0:27 ~ playground[7ff2]::main[0]), local_id: 28 }), res: Some(Local(HirId { owner: DefId(0:27 ~ playground[7ff2]::main[0]), local_id: 1 })), args: None, infer_args: true }] })), attrs: ThinVec(None), span: src/lib.rs:43:14: 43:19 }]), attrs: ThinVec(None), span: src/lib.rs:43:14: 43:52 })

error: internal compiler error: cat_expr Errd
  --> src/lib.rs:43:41
   |
43 |     for a in slice.const_chunks_exact::<{3usize}>() {
   |                                         ^^^^^^^^

error: internal compiler error: cat_expr Errd
  --> src/lib.rs:40:11
   |
40 |   fn main() {
   |  ___________^
41 | |     let slice = &[1i32, 2, 3, 4, 5, 6, 7, 8, 9, 10];
42 | |     
43 | |     for a in slice.const_chunks_exact::<{3usize}>() {
44 | |         dbg!(a);
45 | |     }
46 | | }
   | |_^

error: internal compiler error: cat_expr Errd
  --> src/lib.rs:43:14
   |
43 |     for a in slice.const_chunks_exact::<{3usize}>() {
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: cat_expr Errd
  --> src/lib.rs:43:9
   |
43 |     for a in slice.const_chunks_exact::<{3usize}>() {
   |         ^

error: internal compiler error: cat_expr Errd
  --> src/lib.rs:44:9
   |
44 |         dbg!(a);
   |         ^^^^^^^^
   |
   = note: this error: internal compiler error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: internal compiler error: cat_expr Errd
  --> src/lib.rs:44:14
   |
44 |         dbg!(a);
   |              ^

error: internal compiler error: cat_expr Errd
  --> src/lib.rs:44:9
   |
44 |         dbg!(a);
   |         ^^^^^^^^
   |
   = note: this error: internal compiler error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: internal compiler error: cat_expr Errd
  --> src/lib.rs:44:9
   |
44 |         dbg!(a);
   |         ^^^^^^^^
   |
   = note: this error: internal compiler error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: internal compiler error: cat_expr Errd
  --> src/lib.rs:44:9
   |
44 |         dbg!(a);
   |         ^^^^^^^^
   |
   = note: this error: internal compiler error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: internal compiler error: cat_expr Errd
  --> src/lib.rs:44:9
   |
44 |         dbg!(a);
   |         ^^^^^^^^
   |
   = note: this error: internal compiler error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: internal compiler error: cat_expr Errd
  --> src/lib.rs:44:9
   |
44 |         dbg!(a);
   |         ^^^^^^^^
   |
   = note: this error: internal compiler error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: internal compiler error: cat_expr Errd
  --> src/lib.rs:44:9
   |
44 |         dbg!(a);
   |         ^^^^^^^^
   |
   = note: this error: internal compiler error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: internal compiler error: PromoteTemps: MIR had errors
  --> src/lib.rs:40:1
   |
40 | / fn main() {
41 | |     let slice = &[1i32, 2, 3, 4, 5, 6, 7, 8, 9, 10];
42 | |     
43 | |     for a in slice.const_chunks_exact::<{3usize}>() {
44 | |         dbg!(a);
45 | |     }
46 | | }
   | |_^

error: internal compiler error: broken MIR in DefId(0:27 ~ playground[7ff2]::main[0]) ("return type"): bad type [type error]
  --> src/lib.rs:40:1
   |
40 | / fn main() {
41 | |     let slice = &[1i32, 2, 3, 4, 5, 6, 7, 8, 9, 10];
42 | |     
43 | |     for a in slice.const_chunks_exact::<{3usize}>() {
44 | |         dbg!(a);
45 | |     }
46 | | }
   | |_^

error: internal compiler error: broken MIR in DefId(0:27 ~ playground[7ff2]::main[0]) (LocalDecl { mutability: Mut, local_info: Other, internal: false, is_block_tail: None, ty: [type error], user_ty: UserTypeProjections { contents: [] }, source_info: SourceInfo { span: src/lib.rs:40:1: 46:2, scope: scope[0] } }): bad type [type error]
  --> src/lib.rs:40:1
   |
40 | / fn main() {
41 | |     let slice = &[1i32, 2, 3, 4, 5, 6, 7, 8, 9, 10];
42 | |     
43 | |     for a in slice.const_chunks_exact::<{3usize}>() {
44 | |         dbg!(a);
45 | |     }
46 | | }
   | |_^

error: internal compiler error: mir_const_qualif: MIR had errors
  --> src/lib.rs:43:41
   |
43 |     for a in slice.const_chunks_exact::<{3usize}>() {
   |                                         ^^^^^^^^

error: internal compiler error: PromoteTemps: MIR had errors
  --> src/lib.rs:43:41
   |
43 |     for a in slice.const_chunks_exact::<{3usize}>() {
   |                                         ^^^^^^^^

error: internal compiler error: broken MIR in DefId(0:28 ~ playground[7ff2]::main[0]::{{constant}}[0]) ("return type"): bad type [type error]
  --> src/lib.rs:43:41
   |
43 |     for a in slice.const_chunks_exact::<{3usize}>() {
   |                                         ^^^^^^^^

error: internal compiler error: broken MIR in DefId(0:28 ~ playground[7ff2]::main[0]::{{constant}}[0]) (LocalDecl { mutability: Mut, local_info: Other, internal: false, is_block_tail: None, ty: [type error], user_ty: UserTypeProjections { contents: [] }, source_info: SourceInfo { span: src/lib.rs:43:41: 43:49, scope: scope[0] } }): bad type [type error]
  --> src/lib.rs:43:41
   |
43 |     for a in slice.const_chunks_exact::<{3usize}>() {
   |                                         ^^^^^^^^

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:360:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

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 (75208942f 2020-03-27) running on x86_64-unknown-linux-gnu

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

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

error: could not compile `playground`.

To learn more, run the command again with --verbose.



When I change the call

slice.const_chunks_exact::<{3usize}>()

into

<[i32] as ConstChunksExactTrait<i32>>::const_chunks_exact::<{3usize}>(slice)

the ICE disappears. (The code segfaults though.)



Bisection gives:
searched nightlies: from nightly-2020-03-24 to nightly-2020-03-26
regressed nightly: nightly-2020-03-25
searched commits: from 1edd389 to 02046a5
regressed commit: 342c5f3

@DutchGhost
Copy link
Contributor Author

DutchGhost commented Mar 28, 2020

On that segfault, thats my own mistake, the Iterator should yield items of type &'a [T; N], rather than [&'a T; N] and the return expression should be Some(unsafe { &*ptr})

@steffahn
Copy link
Member

steffahn commented Mar 28, 2020

Yeah, that’s what I thought, the segfault being a bug in the unsafe code.

Here’s a smaller example:

#![feature(const_generics)]

struct R;
impl R {
    fn method<const N: u8>(&self) {}
}
fn main() {
    R.method::<1u8>();
}

(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_codegen_llvm/context.rs:854: failed to get layout for `[type error]`: the type `[type error]` has an unknown layout

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.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-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_codegen_llvm::context::CodegenCx as rustc_target::abi::LayoutOf>::spanned_layout_of::{{closure}}
  21: <rustc_codegen_llvm::context::CodegenCx as rustc_target::abi::LayoutOf>::spanned_layout_of
  22: rustc_codegen_ssa::mir::analyze::non_ssa_locals
  23: rustc_codegen_ssa::mir::codegen_mir
  24: <rustc::mir::mono::MonoItem as rustc_codegen_ssa::mono_item::MonoItemExt>::define
  25: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
  26: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  27: rustc_codegen_llvm::base::compile_codegen_unit
  28: rustc_codegen_ssa::base::codegen_crate
  29: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  30: rustc_interface::passes::start_codegen
  31: rustc::ty::context::tls::enter_global
  32: rustc_interface::queries::Queries::ongoing_codegen
  33: rustc_interface::interface::run_compiler_in_existing_thread_pool
  34: 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 (75208942f 2020-03-27) 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:
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: This smaller example seems to behave slightly different in that it does produce a (however different) ICE even before nightly-2020-03-25. In the original example when compiling as a library (i.e. “Build” vs “Run”), that other ICE appears before that regression, too.

In other words, the bisection above only applies to the error in this issue’s title – the one that OP got.

Edit2: The error before nightly-2020-03-25 looks a lot like #68596.

For the record:

error before nightly-2020-03-25
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
 --> main.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default

error: internal compiler error: unexpected const parent in type_of_def_id(): Expr(expr(HirId { owner: DefIndex(8), local_id: 6 }: R.method::<>()))

error: internal compiler error: mir_const_qualif: MIR had errors
 --> main.rs:8:16
  |
8 |     R.method::<1u8>();
  |                ^^^

error: internal compiler error: PromoteTemps: MIR had errors
 --> main.rs:8:16
  |
8 |     R.method::<1u8>();
  |                ^^^

error: internal compiler error: broken MIR in DefId(0:9 ~ main[317d]::main[0]::{{constant}}[0]) ("return type"): bad type [type error]
 --> main.rs:8:16
  |
8 |     R.method::<1u8>();
  |                ^^^

error: internal compiler error: broken MIR in DefId(0:9 ~ main[317d]::main[0]::{{constant}}[0]) (LocalDecl { mutability: Mut, local_info: Other, internal: false, is_block_tail: None, ty: [type error], user_ty: UserTypeProjections { contents: [] }, source_info: SourceInfo { span: main.rs:8:16: 8:19, scope: scope[0] } }): bad type [type error]
 --> main.rs:8:16
  |
8 |     R.method::<1u8>();
  |                ^^^

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src\librustc_errors\lib.rs:346:17
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: <std::io::IoSliceMut as core::fmt::Debug>::fmt
   3: std::panicking::take_hook
   4: std::panicking::take_hook
   5: rustc_driver::report_ice
   6: std::panicking::rust_panic_with_hook
   7: rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitterWriter::ui_testing
   8: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
   9: rustc_driver::pretty::print_after_hir_lowering
  10: rustc_driver::pretty::print_after_hir_lowering
  11: rustc_driver::pretty::print_after_hir_lowering
  12: rustc_driver::pretty::print_after_hir_lowering
  13: <rustc_span::symbol::SymbolStr as core::fmt::Display>::fmt
  14: <env_logger::filter::inner::Filter as core::fmt::Display>::fmt
  15: <env_logger::filter::inner::Filter as core::fmt::Display>::fmt
  16: _rust_maybe_catch_panic
  17: rustc_driver::pretty::print_after_hir_lowering
  18: ZN244_$LT$std..error..$LT$impl$u20$core..convert..From$LT$alloc..string..String$GT$$u20$for$u20$alloc..boxed..Box$LT$dyn$u20$std..error..Error$u2b$core..marker..Sync$u2b$core..marker..Send$GT$$GT$..from..StringError$u20$as$u20$core..fmt..Display$GT$3fmt17
  19: std::sys::windows::thread::Thread::new
  20: BaseThreadInitThunk
  21: RtlUserThreadStart
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

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.42.0-nightly (8a87b945b 2020-01-14) running on x86_64-pc-windows-msvc

query stack during panic:
end of query stack

@eddyb
Copy link
Member

eddyb commented Apr 17, 2020

Minimal repro (playground):

#![feature(const_generics)]
struct Foo;
impl Foo {
    fn foo<const N: usize>(self) {}
}
fn main() {
    Foo.foo();
}

The problem is a method call with uninferred const parameter, not getting a proper error.
AFAIK it corresponds to this FIXME:

// FIXME: we'd like to use `self.report_error`, but it doesn't yet
// accept a &'tcx ty::Const.

cc @varkor @yodaldevoid @lcnr

@eddyb
Copy link
Member

eddyb commented Apr 17, 2020

When the function doesn't reach codegen, we get delay_span_bugs elsewhere (playground):

#![feature(const_generics)]
struct Foo;
impl Foo {
    fn foo<const N: usize>(self) {}
}
fn test() {
    Foo.foo();
}
error: internal compiler error: PromoteTemps: MIR had errors
 --> src/lib.rs:6:1
  |
6 | / fn test() {
7 | |     Foo.foo();
8 | | }
  | |_^

error: internal compiler error: broken MIR in DefId(0:8 ~ playground[d1c7]::test[0]) ("return type"): bad type [type error]
 --> src/lib.rs:6:1
  |
6 | / fn test() {
7 | |     Foo.foo();
8 | | }
  | |_^

error: internal compiler error: broken MIR in DefId(0:8 ~ playground[d1c7]::test[0]) (LocalDecl { mutability: Mut, local_info: Other, internal: false, is_block_tail: None, ty: [type error], user_ty: UserTypeProjections { contents: [] }, source_info: SourceInfo { span: src/lib.rs:6:1: 8:2, scope: scope[0] } }): bad type [type error]
 --> src/lib.rs:6:1
  |
6 | / fn test() {
7 | |     Foo.foo();
8 | | }
  | |_^

It's important to note that this is the same thing. The ICEs are just a symptom of a tainted_by_errors result from typeck_tables_of, without an error having been emitted.

@varkor
Copy link
Member

varkor commented Apr 17, 2020

This in turn depends on

// FIXME(eddyb) generalize all of this to handle `ty::Const` inference variables as well.
pub fn need_type_info_err(
&self,
body_id: Option<hir::BodyId>,
span: Span,
ty: Ty<'tcx>,
error_code: TypeAnnotationNeeded,
) -> DiagnosticBuilder<'tcx> {

need_type_info_err currently has a lot of special handling for different situations, but maybe we can add in a simple path for consts?

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 18, 2020
correctly handle uninferred consts

fixes the ICE mentioned in rust-lang#70507 (comment)

I originally tried to generalize `need_type_info_err` to also work with consts which was not as much fun as I hoped 😅

It might be easier to have some duplication here and handle consts separately.

r? @varkor
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 19, 2020
correctly handle uninferred consts

fixes the ICE mentioned in rust-lang#70507 (comment)

I originally tried to generalize `need_type_info_err` to also work with consts which was not as much fun as I hoped 😅

It might be easier to have some duplication here and handle consts separately.

r? @varkor
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 16, 2020
const generics triage

I went through all const generics issues and closed all issues which are already fixed.

Some issues already have a regression test but were not closed. Also doing this as part of this PR.

uff r? @eddyb @varkor

closes rust-lang#61936
closes rust-lang#62878
closes rust-lang#63695
closes rust-lang#67144
closes rust-lang#68596
closes rust-lang#69816
closes rust-lang#70217
closes rust-lang#70507
closes rust-lang#70586
closes rust-lang#71348
closes rust-lang#71805
closes rust-lang#73120
closes rust-lang#73508
closes rust-lang#73730
closes rust-lang#74255
@bors bors closed this as completed in c354524 Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants