Closed
Description
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>,
{
}
}
- playground link (nightly — ICE)
- playground link (beta — error as expected)
- playground link (stable — error as expected)
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 paramsN
forself
(as the receiver oftrigger
) andself
(as the receiver ofunsatisfied
). They should both havekind: Param(N/#1)
, but one of them haskind: Infer(_)
.This only happens if the trait bound is not satisfied. If we add
where T: Bar<N>
totrigger
, then the program compiles.
Metadata
Metadata
Assignees
Labels
Area: const generics (parameters and arguments)Area: Messages for errors, warnings, and lintsCategory: This is a bug.Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️High priorityRelevant to the compiler team, which will review and decide on the PR/issue.Performance or correctness regression from stable to nightly.