Skip to content

Commit a3e0795

Browse files
committed
Heat up the ICE-y error reporting
rest in peace match bool <3
1 parent 218bf8d commit a3e0795

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

compiler/rustc_middle/src/ty/error.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,17 @@ impl<'tcx> ty::TyS<'tcx> {
228228
ty::Adt(def, _) => format!("{} `{}`", def.descr(), tcx.def_path_str(def.did)).into(),
229229
ty::Foreign(def_id) => format!("extern type `{}`", tcx.def_path_str(def_id)).into(),
230230
ty::Array(t, n) => {
231+
if t.is_simple_ty() {
232+
return format!("array `{}`", self).into();
233+
}
234+
231235
let n = tcx.lift(n).unwrap();
232-
match n.try_eval_usize(tcx, ty::ParamEnv::empty()) {
233-
_ if t.is_simple_ty() => format!("array `{}`", self).into(),
234-
Some(n) => format!("array of {} element{}", n, pluralize!(n)).into(),
235-
None => "array".into(),
236+
if let ty::ConstKind::Value(v) = n.val {
237+
if let Some(n) = v.try_to_machine_usize(tcx) {
238+
return format!("array of {} element{}", n, pluralize!(n)).into();
239+
}
236240
}
241+
"array".into()
237242
}
238243
ty::Slice(ty) if ty.is_simple_ty() => format!("slice `{}`", self).into(),
239244
ty::Slice(_) => "slice".into(),

compiler/rustc_mir/src/const_eval/eval_queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ pub fn eval_to_const_value_raw_provider<'tcx>(
208208
tcx: TyCtxt<'tcx>,
209209
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
210210
) -> ::rustc_middle::mir::interpret::EvalToConstValueResult<'tcx> {
211-
// see comment in const_eval_raw_provider for what we're doing here
211+
// see comment in eval_to_allocation_raw_provider for what we're doing here
212212
if key.param_env.reveal() == Reveal::All {
213213
let mut key = key;
214214
key.param_env = key.param_env.with_user_facing();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![feature(const_generics, const_evaluatable_checked)]
2+
#![allow(incomplete_features)]
3+
4+
// This test is a minimized reproduction for #79518 where
5+
// during error handling for the type mismatch we would try
6+
// to evaluate std::mem::size_of::<Self::Assoc> causing an ICE
7+
8+
trait Foo {
9+
type Assoc: PartialEq;
10+
const AssocInstance: Self::Assoc;
11+
12+
fn foo()
13+
where
14+
[(); std::mem::size_of::<Self::Assoc>()]: ,
15+
{
16+
Self::AssocInstance == [(); std::mem::size_of::<Self::Assoc>()];
17+
//~^ Error: mismatched types
18+
}
19+
}
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-79518-default_trait_method_normalization.rs:16:32
3+
|
4+
LL | Self::AssocInstance == [(); std::mem::size_of::<Self::Assoc>()];
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found array `[(); _]`
6+
|
7+
= note: expected associated type `<Self as Foo>::Assoc`
8+
found array `[(); _]`
9+
= help: consider constraining the associated type `<Self as Foo>::Assoc` to `[(); _]` or calling a method that returns `<Self as Foo>::Assoc`
10+
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)