Skip to content

Commit be236d7

Browse files
committed
Rm ValuePairs::Ty/Const
Remove old value pairs which is a strict subset of Terms.
1 parent fdd6f4e commit be236d7

File tree

8 files changed

+67
-74
lines changed

8 files changed

+67
-74
lines changed

compiler/rustc_infer/src/infer/at.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,10 @@ impl<'tcx> ToTrace<'tcx> for Ty<'tcx> {
258258
a: Self,
259259
b: Self,
260260
) -> TypeTrace<'tcx> {
261-
TypeTrace { cause: cause.clone(), values: Types(ExpectedFound::new(a_is_expected, a, b)) }
261+
TypeTrace {
262+
cause: cause.clone(),
263+
values: Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
264+
}
262265
}
263266
}
264267

@@ -282,7 +285,10 @@ impl<'tcx> ToTrace<'tcx> for &'tcx Const<'tcx> {
282285
a: Self,
283286
b: Self,
284287
) -> TypeTrace<'tcx> {
285-
TypeTrace { cause: cause.clone(), values: Consts(ExpectedFound::new(a_is_expected, a, b)) }
288+
TypeTrace {
289+
cause: cause.clone(),
290+
values: Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
291+
}
286292
}
287293
}
288294

@@ -340,7 +346,7 @@ impl<'tcx> ToTrace<'tcx> for ty::ProjectionTy<'tcx> {
340346
let b_ty = tcx.mk_projection(b.item_def_id, b.substs);
341347
TypeTrace {
342348
cause: cause.clone(),
343-
values: Types(ExpectedFound::new(a_is_expected, a_ty, b_ty)),
349+
values: Terms(ExpectedFound::new(a_is_expected, a_ty.into(), b_ty.into())),
344350
}
345351
}
346352
}

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+13-29
Original file line numberDiff line numberDiff line change
@@ -1582,18 +1582,18 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15821582
None => (None, Mismatch::Fixed("type"), false),
15831583
Some(values) => {
15841584
let (is_simple_error, exp_found) = match values {
1585-
ValuePairs::Types(exp_found) => {
1586-
let is_simple_err =
1587-
exp_found.expected.is_simple_text() && exp_found.found.is_simple_text();
1588-
OpaqueTypesVisitor::visit_expected_found(
1589-
self.tcx,
1590-
exp_found.expected,
1591-
exp_found.found,
1592-
span,
1593-
)
1594-
.report(diag);
1585+
ValuePairs::Terms(infer::ExpectedFound {
1586+
expected: ty::Term::Ty(expected),
1587+
found: ty::Term::Ty(found),
1588+
}) => {
1589+
let is_simple_err = expected.is_simple_text() && found.is_simple_text();
1590+
OpaqueTypesVisitor::visit_expected_found(self.tcx, expected, found, span)
1591+
.report(diag);
15951592

1596-
(is_simple_err, Mismatch::Variable(exp_found))
1593+
(
1594+
is_simple_err,
1595+
Mismatch::Variable(infer::ExpectedFound { expected, found }),
1596+
)
15971597
}
15981598
ValuePairs::TraitRefs(_) => (false, Mismatch::Fixed("trait")),
15991599
_ => (false, Mismatch::Fixed("type")),
@@ -1624,7 +1624,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
16241624
};
16251625
if let Some((sp, msg)) = secondary_span {
16261626
if swap_secondary_and_primary {
1627-
let terr = if let Some(infer::ValuePairs::Types(infer::ExpectedFound {
1627+
let terr = if let Some(infer::ValuePairs::Terms(infer::ExpectedFound {
16281628
expected,
16291629
..
16301630
})) = values
@@ -2036,9 +2036,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
20362036
}
20372037
FailureCode::Error0308(failure_str) => {
20382038
let mut err = struct_span_err!(self.tcx.sess, span, E0308, "{}", failure_str);
2039-
if let ValuePairs::Types(ty::error::ExpectedFound { expected, found }) =
2040-
trace.values
2041-
{
2039+
if let Some((expected, found)) = trace.values.ty() {
20422040
match (expected.kind(), found.kind()) {
20432041
(ty::Tuple(_), ty::Tuple(_)) => {}
20442042
// If a tuple of length one was expected and the found expression has
@@ -2124,9 +2122,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
21242122
values: ValuePairs<'tcx>,
21252123
) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> {
21262124
match values {
2127-
infer::Types(exp_found) => self.expected_found_str_ty(exp_found),
21282125
infer::Regions(exp_found) => self.expected_found_str(exp_found),
2129-
infer::Consts(exp_found) => self.expected_found_str(exp_found),
21302126
infer::Terms(exp_found) => self.expected_found_str_term(exp_found),
21312127
infer::TraitRefs(exp_found) => {
21322128
let pretty_exp_found = ty::error::ExpectedFound {
@@ -2155,18 +2151,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
21552151
}
21562152
}
21572153

2158-
fn expected_found_str_ty(
2159-
&self,
2160-
exp_found: ty::error::ExpectedFound<Ty<'tcx>>,
2161-
) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> {
2162-
let exp_found = self.resolve_vars_if_possible(exp_found);
2163-
if exp_found.references_error() {
2164-
return None;
2165-
}
2166-
2167-
Some(self.cmp(exp_found.expected, exp_found.found))
2168-
}
2169-
21702154
fn expected_found_str_term(
21712155
&self,
21722156
exp_found: ty::error::ExpectedFound<ty::Term<'tcx>>,

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
44
use crate::infer::lexical_region_resolve::RegionResolutionError;
5-
use crate::infer::{SubregionOrigin, Subtype, ValuePairs};
5+
use crate::infer::{SubregionOrigin, Subtype};
66
use crate::traits::ObligationCauseCode::CompareImplMethodObligation;
77
use rustc_errors::ErrorReported;
88
use rustc_hir as hir;
@@ -34,16 +34,16 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
3434
{
3535
if let (&Subtype(ref sup_trace), &Subtype(ref sub_trace)) = (&sup_origin, &sub_origin) {
3636
if let (
37-
ValuePairs::Types(sub_expected_found),
38-
ValuePairs::Types(sup_expected_found),
37+
sub_expected_found @ Some((sub_expected, sub_found)),
38+
sup_expected_found @ Some(_),
3939
CompareImplMethodObligation { trait_item_def_id, .. },
40-
) = (&sub_trace.values, &sup_trace.values, sub_trace.cause.code())
40+
) = (&sub_trace.values.ty(), &sup_trace.values.ty(), sub_trace.cause.code())
4141
{
4242
if sup_expected_found == sub_expected_found {
4343
self.emit_err(
4444
var_origin.span(),
45-
sub_expected_found.expected,
46-
sub_expected_found.found,
45+
sub_expected,
46+
sub_found,
4747
*trait_item_def_id,
4848
);
4949
return Some(ErrorReported);

compiler/rustc_infer/src/infer/mod.rs

+22-4
Original file line numberDiff line numberDiff line change
@@ -368,14 +368,26 @@ pub struct InferCtxt<'a, 'tcx> {
368368
/// See the `error_reporting` module for more details.
369369
#[derive(Clone, Copy, Debug, PartialEq, Eq, TypeFoldable)]
370370
pub enum ValuePairs<'tcx> {
371-
Types(ExpectedFound<Ty<'tcx>>),
372371
Regions(ExpectedFound<ty::Region<'tcx>>),
373-
Consts(ExpectedFound<&'tcx ty::Const<'tcx>>),
374372
Terms(ExpectedFound<ty::Term<'tcx>>),
375373
TraitRefs(ExpectedFound<ty::TraitRef<'tcx>>),
376374
PolyTraitRefs(ExpectedFound<ty::PolyTraitRef<'tcx>>),
377375
}
378376

377+
impl<'tcx> ValuePairs<'tcx> {
378+
pub fn ty(&self) -> Option<(Ty<'tcx>, Ty<'tcx>)> {
379+
if let ValuePairs::Terms(ExpectedFound {
380+
expected: ty::Term::Ty(expected),
381+
found: ty::Term::Ty(found),
382+
}) = self
383+
{
384+
Some((expected, found))
385+
} else {
386+
None
387+
}
388+
}
389+
}
390+
379391
/// The trace designates the path through inference that we took to
380392
/// encounter an error or subtyping constraint.
381393
///
@@ -1791,7 +1803,10 @@ impl<'tcx> TypeTrace<'tcx> {
17911803
a: Ty<'tcx>,
17921804
b: Ty<'tcx>,
17931805
) -> TypeTrace<'tcx> {
1794-
TypeTrace { cause: cause.clone(), values: Types(ExpectedFound::new(a_is_expected, a, b)) }
1806+
TypeTrace {
1807+
cause: cause.clone(),
1808+
values: Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
1809+
}
17951810
}
17961811

17971812
pub fn consts(
@@ -1800,7 +1815,10 @@ impl<'tcx> TypeTrace<'tcx> {
18001815
a: &'tcx ty::Const<'tcx>,
18011816
b: &'tcx ty::Const<'tcx>,
18021817
) -> TypeTrace<'tcx> {
1803-
TypeTrace { cause: cause.clone(), values: Consts(ExpectedFound::new(a_is_expected, a, b)) }
1818+
TypeTrace {
1819+
cause: cause.clone(),
1820+
values: Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
1821+
}
18041822
}
18051823
}
18061824

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+5-20
Original file line numberDiff line numberDiff line change
@@ -1378,26 +1378,11 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
13781378
normalized_ty,
13791379
data.term,
13801380
) {
1381-
values = Some(match (normalized_ty, data.term) {
1382-
(ty::Term::Ty(normalized_ty), ty::Term::Ty(ty)) => {
1383-
infer::ValuePairs::Types(ExpectedFound::new(
1384-
is_normalized_ty_expected,
1385-
normalized_ty,
1386-
ty,
1387-
))
1388-
}
1389-
(ty::Term::Const(normalized_ct), ty::Term::Const(ct)) => {
1390-
infer::ValuePairs::Consts(ExpectedFound::new(
1391-
is_normalized_ty_expected,
1392-
normalized_ct,
1393-
ct,
1394-
))
1395-
}
1396-
(_, _) => span_bug!(
1397-
obligation.cause.span,
1398-
"found const or type where other expected"
1399-
),
1400-
});
1381+
values = Some(infer::ValuePairs::Terms(ExpectedFound::new(
1382+
is_normalized_ty_expected,
1383+
normalized_ty,
1384+
data.term,
1385+
)));
14011386
err_buf = error;
14021387
err = &err_buf;
14031388
}

compiler/rustc_typeck/src/check/compare_method.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,9 @@ fn compare_predicate_entailment<'tcx>(
377377
&mut diag,
378378
&cause,
379379
trait_err_span.map(|sp| (sp, "type in trait".to_owned())),
380-
Some(infer::ValuePairs::Types(ExpectedFound {
381-
expected: trait_fty,
382-
found: impl_fty,
380+
Some(infer::ValuePairs::Terms(ExpectedFound {
381+
expected: trait_fty.into(),
382+
found: impl_fty.into(),
383383
})),
384384
&terr,
385385
false,
@@ -1068,9 +1068,9 @@ crate fn compare_const_impl<'tcx>(
10681068
&mut diag,
10691069
&cause,
10701070
trait_c_span.map(|span| (span, "type in trait".to_owned())),
1071-
Some(infer::ValuePairs::Types(ExpectedFound {
1072-
expected: trait_ty,
1073-
found: impl_ty,
1071+
Some(infer::ValuePairs::Terms(ExpectedFound {
1072+
expected: trait_ty.into(),
1073+
found: impl_ty.into(),
10741074
})),
10751075
&terr,
10761076
false,

src/test/ui/associated-types/higher-ranked-projection.bad.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0308]: mismatched types
44
LL | foo(());
55
| ^^^ lifetime mismatch
66
|
7-
= note: expected type `&'a ()`
8-
found type `&()`
7+
= note: expected reference `&'a ()`
8+
found type `&()`
99
note: the lifetime requirement is introduced here
1010
--> $DIR/higher-ranked-projection.rs:15:33
1111
|

src/test/ui/lifetimes/issue-79187-2.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ error[E0308]: mismatched types
2323
LL | take_foo(|a: &i32| a);
2424
| ^^^^^^^^ lifetime mismatch
2525
|
26-
= note: expected type `&i32`
27-
found type `&i32`
26+
= note: expected reference `&i32`
27+
found reference `&i32`
2828
note: the anonymous lifetime #1 defined here doesn't meet the lifetime requirements
2929
--> $DIR/issue-79187-2.rs:9:14
3030
|
@@ -42,8 +42,8 @@ error[E0308]: mismatched types
4242
LL | take_foo(|a: &i32| -> &i32 { a });
4343
| ^^^^^^^^ lifetime mismatch
4444
|
45-
= note: expected type `&i32`
46-
found type `&i32`
45+
= note: expected reference `&i32`
46+
found reference `&i32`
4747
note: the anonymous lifetime #1 defined here doesn't meet the lifetime requirements
4848
--> $DIR/issue-79187-2.rs:10:14
4949
|

0 commit comments

Comments
 (0)