Add in ValuePair::Term
This adds in an enum when matching on positions which can either be types or consts. It will default to emitting old special cased error messages for types.
This commit is contained in:
parent
f624427f87
commit
fdd6f4e56c
@ -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)) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<ty::Term<'tcx>>,
|
||||
) -> 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<T: fmt::Display + TypeFoldable<'tcx>>(
|
||||
&self,
|
||||
|
@ -371,6 +371,7 @@ pub enum ValuePairs<'tcx> {
|
||||
Types(ExpectedFound<Ty<'tcx>>),
|
||||
Regions(ExpectedFound<ty::Region<'tcx>>),
|
||||
Consts(ExpectedFound<&'tcx ty::Const<'tcx>>),
|
||||
Terms(ExpectedFound<ty::Term<'tcx>>),
|
||||
TraitRefs(ExpectedFound<ty::TraitRef<'tcx>>),
|
||||
PolyTraitRefs(ExpectedFound<ty::PolyTraitRef<'tcx>>),
|
||||
}
|
||||
|
@ -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
|
||||
|
|
||||
|
@ -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
|
||||
|
|
||||
|
Loading…
Reference in New Issue
Block a user