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 @@ impl<'tcx> ToTrace<'tcx> for &'tcx Const<'tcx> {
|
|||||||
|
|
||||||
impl<'tcx> ToTrace<'tcx> for ty::Term<'tcx> {
|
impl<'tcx> ToTrace<'tcx> for ty::Term<'tcx> {
|
||||||
fn to_trace(
|
fn to_trace(
|
||||||
tcx: TyCtxt<'tcx>,
|
_: TyCtxt<'tcx>,
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
a_is_expected: bool,
|
a_is_expected: bool,
|
||||||
a: Self,
|
a: Self,
|
||||||
b: Self,
|
b: Self,
|
||||||
) -> TypeTrace<'tcx> {
|
) -> TypeTrace<'tcx> {
|
||||||
match (a, b) {
|
TypeTrace { cause: cause.clone(), values: Terms(ExpectedFound::new(a_is_expected, 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!(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2127,6 +2127,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
infer::Types(exp_found) => self.expected_found_str_ty(exp_found),
|
infer::Types(exp_found) => self.expected_found_str_ty(exp_found),
|
||||||
infer::Regions(exp_found) => self.expected_found_str(exp_found),
|
infer::Regions(exp_found) => self.expected_found_str(exp_found),
|
||||||
infer::Consts(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) => {
|
infer::TraitRefs(exp_found) => {
|
||||||
let pretty_exp_found = ty::error::ExpectedFound {
|
let pretty_exp_found = ty::error::ExpectedFound {
|
||||||
expected: exp_found.expected.print_only_trait_path(),
|
expected: exp_found.expected.print_only_trait_path(),
|
||||||
@ -2166,6 +2167,24 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
Some(self.cmp(exp_found.expected, exp_found.found))
|
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 `{}`".
|
/// Returns a string of the form "expected `{}`, found `{}`".
|
||||||
fn expected_found_str<T: fmt::Display + TypeFoldable<'tcx>>(
|
fn expected_found_str<T: fmt::Display + TypeFoldable<'tcx>>(
|
||||||
&self,
|
&self,
|
||||||
|
@ -371,6 +371,7 @@ pub enum ValuePairs<'tcx> {
|
|||||||
Types(ExpectedFound<Ty<'tcx>>),
|
Types(ExpectedFound<Ty<'tcx>>),
|
||||||
Regions(ExpectedFound<ty::Region<'tcx>>),
|
Regions(ExpectedFound<ty::Region<'tcx>>),
|
||||||
Consts(ExpectedFound<&'tcx ty::Const<'tcx>>),
|
Consts(ExpectedFound<&'tcx ty::Const<'tcx>>),
|
||||||
|
Terms(ExpectedFound<ty::Term<'tcx>>),
|
||||||
TraitRefs(ExpectedFound<ty::TraitRef<'tcx>>),
|
TraitRefs(ExpectedFound<ty::TraitRef<'tcx>>),
|
||||||
PolyTraitRefs(ExpectedFound<ty::PolyTraitRef<'tcx>>),
|
PolyTraitRefs(ExpectedFound<ty::PolyTraitRef<'tcx>>),
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ error[E0308]: mismatched types
|
|||||||
LL | foo(());
|
LL | foo(());
|
||||||
| ^^^ lifetime mismatch
|
| ^^^ lifetime mismatch
|
||||||
|
|
|
|
||||||
= note: expected reference `&'a ()`
|
= note: expected type `&'a ()`
|
||||||
found type `&()`
|
found type `&()`
|
||||||
note: the lifetime requirement is introduced here
|
note: the lifetime requirement is introduced here
|
||||||
--> $DIR/higher-ranked-projection.rs:15:33
|
--> $DIR/higher-ranked-projection.rs:15:33
|
||||||
|
@ -23,8 +23,8 @@ error[E0308]: mismatched types
|
|||||||
LL | take_foo(|a: &i32| a);
|
LL | take_foo(|a: &i32| a);
|
||||||
| ^^^^^^^^ lifetime mismatch
|
| ^^^^^^^^ lifetime mismatch
|
||||||
|
|
|
|
||||||
= note: expected reference `&i32`
|
= note: expected type `&i32`
|
||||||
found reference `&i32`
|
found type `&i32`
|
||||||
note: the anonymous lifetime #1 defined here doesn't meet the lifetime requirements
|
note: the anonymous lifetime #1 defined here doesn't meet the lifetime requirements
|
||||||
--> $DIR/issue-79187-2.rs:9:14
|
--> $DIR/issue-79187-2.rs:9:14
|
||||||
|
|
|
|
||||||
@ -42,8 +42,8 @@ error[E0308]: mismatched types
|
|||||||
LL | take_foo(|a: &i32| -> &i32 { a });
|
LL | take_foo(|a: &i32| -> &i32 { a });
|
||||||
| ^^^^^^^^ lifetime mismatch
|
| ^^^^^^^^ lifetime mismatch
|
||||||
|
|
|
|
||||||
= note: expected reference `&i32`
|
= note: expected type `&i32`
|
||||||
found reference `&i32`
|
found type `&i32`
|
||||||
note: the anonymous lifetime #1 defined here doesn't meet the lifetime requirements
|
note: the anonymous lifetime #1 defined here doesn't meet the lifetime requirements
|
||||||
--> $DIR/issue-79187-2.rs:10:14
|
--> $DIR/issue-79187-2.rs:10:14
|
||||||
|
|
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user