diff --git a/compiler/rustc_infer/src/infer/at.rs b/compiler/rustc_infer/src/infer/at.rs index 147061dafeb..aa74a92ad1f 100644 --- a/compiler/rustc_infer/src/infer/at.rs +++ b/compiler/rustc_infer/src/infer/at.rs @@ -288,21 +288,13 @@ fn to_trace( impl<'tcx> ToTrace<'tcx> for ty::Term<'tcx> { fn to_trace( - tcx: TyCtxt<'tcx>, + _: TyCtxt<'tcx>, cause: &ObligationCause<'tcx>, a_is_expected: bool, a: Self, b: Self, ) -> TypeTrace<'tcx> { - match (a, b) { - (ty::Term::Ty(a), ty::Term::Ty(b)) => { - ToTrace::to_trace(tcx, cause, a_is_expected, a, b) - } - (ty::Term::Const(a), ty::Term::Const(b)) => { - ToTrace::to_trace(tcx, cause, a_is_expected, a, b) - } - (_, _) => todo!(), - } + TypeTrace { cause: cause.clone(), values: Terms(ExpectedFound::new(a_is_expected, a, b)) } } } diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 1eb8190bd7d..7b82b5a8b8f 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -2127,6 +2127,7 @@ fn values_str( infer::Types(exp_found) => self.expected_found_str_ty(exp_found), infer::Regions(exp_found) => self.expected_found_str(exp_found), infer::Consts(exp_found) => self.expected_found_str(exp_found), + infer::Terms(exp_found) => self.expected_found_str_term(exp_found), infer::TraitRefs(exp_found) => { let pretty_exp_found = ty::error::ExpectedFound { expected: exp_found.expected.print_only_trait_path(), @@ -2166,6 +2167,24 @@ fn expected_found_str_ty( Some(self.cmp(exp_found.expected, exp_found.found)) } + fn expected_found_str_term( + &self, + exp_found: ty::error::ExpectedFound>, + ) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> { + let exp_found = self.resolve_vars_if_possible(exp_found); + if exp_found.references_error() { + return None; + } + + Some(match (exp_found.expected, exp_found.found) { + (ty::Term::Ty(expected), ty::Term::Ty(found)) => self.cmp(expected, found), + (expected, found) => ( + DiagnosticStyledString::highlighted(expected.to_string()), + DiagnosticStyledString::highlighted(found.to_string()), + ), + }) + } + /// Returns a string of the form "expected `{}`, found `{}`". fn expected_found_str>( &self, diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index d1b24b332bd..19ac40e7e8a 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -371,6 +371,7 @@ pub enum ValuePairs<'tcx> { Types(ExpectedFound>), Regions(ExpectedFound>), Consts(ExpectedFound<&'tcx ty::Const<'tcx>>), + Terms(ExpectedFound>), TraitRefs(ExpectedFound>), PolyTraitRefs(ExpectedFound>), } diff --git a/src/test/ui/associated-types/higher-ranked-projection.bad.stderr b/src/test/ui/associated-types/higher-ranked-projection.bad.stderr index 1ac72e4b90c..e2847b6b72b 100644 --- a/src/test/ui/associated-types/higher-ranked-projection.bad.stderr +++ b/src/test/ui/associated-types/higher-ranked-projection.bad.stderr @@ -4,8 +4,8 @@ error[E0308]: mismatched types LL | foo(()); | ^^^ lifetime mismatch | - = note: expected reference `&'a ()` - found type `&()` + = note: expected type `&'a ()` + found type `&()` note: the lifetime requirement is introduced here --> $DIR/higher-ranked-projection.rs:15:33 | diff --git a/src/test/ui/lifetimes/issue-79187-2.stderr b/src/test/ui/lifetimes/issue-79187-2.stderr index 2aca8faff9f..9a0b40d43a0 100644 --- a/src/test/ui/lifetimes/issue-79187-2.stderr +++ b/src/test/ui/lifetimes/issue-79187-2.stderr @@ -23,8 +23,8 @@ error[E0308]: mismatched types LL | take_foo(|a: &i32| a); | ^^^^^^^^ lifetime mismatch | - = note: expected reference `&i32` - found reference `&i32` + = note: expected type `&i32` + found type `&i32` note: the anonymous lifetime #1 defined here doesn't meet the lifetime requirements --> $DIR/issue-79187-2.rs:9:14 | @@ -42,8 +42,8 @@ error[E0308]: mismatched types LL | take_foo(|a: &i32| -> &i32 { a }); | ^^^^^^^^ lifetime mismatch | - = note: expected reference `&i32` - found reference `&i32` + = note: expected type `&i32` + found type `&i32` note: the anonymous lifetime #1 defined here doesn't meet the lifetime requirements --> $DIR/issue-79187-2.rs:10:14 |