Skip to content

Add in ValuePair::Term #93728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions compiler/rustc_infer/src/infer/at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,21 +288,13 @@ impl<'tcx> ToTrace<'tcx> for &'tcx Const<'tcx> {

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)) }
}
}

Expand Down
19 changes: 19 additions & 0 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2127,6 +2127,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
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(),
Expand Down Expand Up @@ -2166,6 +2167,24 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
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,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/lifetimes/issue-79187-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand All @@ -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
|
Expand Down