Skip to content

Commit 4217b87

Browse files
Deeply normalize type trace in type error reporting
1 parent 1920c66 commit 4217b87

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

Diff for: compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1252,8 +1252,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
12521252
}
12531253
let (expected_found, exp_found, is_simple_error, values) = match values {
12541254
None => (None, Mismatch::Fixed("type"), false, None),
1255-
Some(ty::ParamEnvAnd { param_env: _, value: values }) => {
1255+
Some(ty::ParamEnvAnd { param_env, value: values }) => {
12561256
let mut values = self.resolve_vars_if_possible(values);
1257+
if self.next_trait_solver() {
1258+
values = deeply_normalize_for_diagnostics(self, param_env, values);
1259+
}
12571260
let (is_simple_error, exp_found) = match values {
12581261
ValuePairs::Terms(ExpectedFound { expected, found }) => {
12591262
match (expected.unpack(), found.unpack()) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ compile-flags: -Znext-solver
2+
3+
// Make sure we try to mention a deeply normalized type in a type mismatch error.
4+
5+
trait Mirror {
6+
type Assoc;
7+
}
8+
impl<T> Mirror for T {
9+
type Assoc = T;
10+
}
11+
12+
fn needs<T>(_: <T as Mirror>::Assoc) {}
13+
14+
fn main() {
15+
needs::<i32>(());
16+
//~^ ERROR mismatched types
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/deeply-normalize-type-expectation.rs:15:18
3+
|
4+
LL | needs::<i32>(());
5+
| ------------ ^^ expected `i32`, found `()`
6+
| |
7+
| arguments to this function are incorrect
8+
|
9+
note: function defined here
10+
--> $DIR/deeply-normalize-type-expectation.rs:12:4
11+
|
12+
LL | fn needs<T>(_: <T as Mirror>::Assoc) {}
13+
| ^^^^^ -----------------------
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)