diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs index fd991100879..b9a569d25e3 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs @@ -1252,8 +1252,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } 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()) { diff --git a/tests/ui/traits/next-solver/diagnostics/deeply-normalize-type-expectation.rs b/tests/ui/traits/next-solver/diagnostics/deeply-normalize-type-expectation.rs new file mode 100644 index 00000000000..5c53b745933 --- /dev/null +++ b/tests/ui/traits/next-solver/diagnostics/deeply-normalize-type-expectation.rs @@ -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 Mirror for T { + type Assoc = T; +} + +fn needs(_: ::Assoc) {} + +fn main() { + needs::(()); + //~^ ERROR mismatched types +} diff --git a/tests/ui/traits/next-solver/diagnostics/deeply-normalize-type-expectation.stderr b/tests/ui/traits/next-solver/diagnostics/deeply-normalize-type-expectation.stderr new file mode 100644 index 00000000000..88643945863 --- /dev/null +++ b/tests/ui/traits/next-solver/diagnostics/deeply-normalize-type-expectation.stderr @@ -0,0 +1,17 @@ +error[E0308]: mismatched types + --> $DIR/deeply-normalize-type-expectation.rs:15:18 + | +LL | needs::(()); + | ------------ ^^ expected `i32`, found `()` + | | + | arguments to this function are incorrect + | +note: function defined here + --> $DIR/deeply-normalize-type-expectation.rs:12:4 + | +LL | fn needs(_: ::Assoc) {} + | ^^^^^ ----------------------- + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`.