I hit this ice when trying implement https://github.com/rust-lang/rust/issues/60735.
The ice message looks very similar to https://github.com/rust-lang/rust/issues/70291, which has been closed already.
#![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);
}
}
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`.
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 https://github.com/rust-lang/rust/commit/1edd389cc4c7b5be7a3dd4fe4b986f6017018e54 to https://github.com/rust-lang/rust/commit/02046a5d402c789c006d0da7662f800fe3c45faf
regressed commit: https://github.com/rust-lang/rust/commit/342c5f33d097b2dc07a2dbc0ca45a37379d2ff60
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})
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>();
}
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 https://github.com/rust-lang/rust/issues/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
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: https://github.com/rust-lang/rust/blob/b2c1a606feb1fbdb0ac0acba76f881ef172ed474/src/librustc_typeck/check/writeback.rs#L673-L674
cc @varkor @yodaldevoid @lcnr
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.
This in turn depends on
https://github.com/rust-lang/rust/blob/8d67f576b56e8fc98a31123e5963f8d00e40611c/src/librustc_infer/infer/error_reporting/need_type_info.rs#L226-L233
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?