Regression from stable 1.66 / beta 1.67 -> nightly 1.68 (haven't bisected). Stable/beta correctly produce an error, nightly ICEs. I've also confirmed the behavior on the latest commit to master (9709a43, at time of writing).
Code
struct Foo<T, const N: usize> {
array: [T; N],
}
trait Bar<const N: usize> {}
impl<T, const N: usize> Foo<T, N> {
fn trigger(self) {
self.unsatisfied()
// ^^^^^^^^^^^ expected location of type error (T: Bar<N> isn't satisfied)
// Instead, nightly produces an ICE when
}
fn unsatisfied(self)
where
T: Bar<N>,
{
}
}
Compiler output (ICE text)
error: internal compiler error: /rustc/92c1937a90e5b6f20fa6e87016d6869da363972e/compiler/rustc_middle/src/ty/relate.rs:638:13: var types encountered in super_relate_consts: Const { ty: usize, kind: Infer(Var(_#0c)) } Const { ty: usize, kind: Param(N/#1) }
--- other text omitted ---
query stack during panic:
#0 [typeck] type-checking `<impl at bad.rs:7:1: 7:34>::trigger`
#1 [typeck_item_bodies] type-checking all item bodies
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error
Setting RUST_BACKTRACE=1 produced the same output as above.
Preliminary investigation
I tried to dig into this, struggled to make sense of the typechecking code. I think the following is going on:
super_relate_consts is being called with the const params N for self (as the receiver of trigger) and self (as the receiver of unsatisfied). They should both have kind: Param(N/#1), but one of them has kind: Infer(_).
This only happens if the trait bound is not satisfied. If we add where T: Bar<N> to trigger, then the program compiles.
Regression from stable 1.66 / beta 1.67 -> nightly 1.68 (haven't bisected). Stable/beta correctly produce an error, nightly ICEs. I've also confirmed the behavior on the latest commit to master (9709a43, at time of writing).
Code
Compiler output (ICE text)
Setting
RUST_BACKTRACE=1produced the same output as above.Preliminary investigation
I tried to dig into this, struggled to make sense of the typechecking code. I think the following is going on: