Deeply normalize type trace in type error reporting

This commit is contained in:
Michael Goulet 2024-10-15 15:24:22 -04:00
parent 1920c66a8d
commit 4217b8702d
3 changed files with 38 additions and 1 deletions

View File

@ -1252,8 +1252,11 @@ enum Mismatch<'a> {
}
let (expected_found, exp_found, is_simple_error, values) = match values {
None => (None, Mismatch::Fixed("type"), false, None),
Some(ty::ParamEnvAnd { param_env: _, value: values }) => {
Some(ty::ParamEnvAnd { param_env, value: values }) => {
let mut values = self.resolve_vars_if_possible(values);
if self.next_trait_solver() {
values = deeply_normalize_for_diagnostics(self, param_env, values);
}
let (is_simple_error, exp_found) = match values {
ValuePairs::Terms(ExpectedFound { expected, found }) => {
match (expected.unpack(), found.unpack()) {

View File

@ -0,0 +1,17 @@
//@ compile-flags: -Znext-solver
// Make sure we try to mention a deeply normalized type in a type mismatch error.
trait Mirror {
type Assoc;
}
impl<T> Mirror for T {
type Assoc = T;
}
fn needs<T>(_: <T as Mirror>::Assoc) {}
fn main() {
needs::<i32>(());
//~^ ERROR mismatched types
}

View File

@ -0,0 +1,17 @@
error[E0308]: mismatched types
--> $DIR/deeply-normalize-type-expectation.rs:15:18
|
LL | needs::<i32>(());
| ------------ ^^ expected `i32`, found `()`
| |
| arguments to this function are incorrect
|
note: function defined here
--> $DIR/deeply-normalize-type-expectation.rs:12:4
|
LL | fn needs<T>(_: <T as Mirror>::Assoc) {}
| ^^^^^ -----------------------
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0308`.