Skip to content

Commit 61daee6

Browse files
Get rid of some sub_exp and eq_exp
1 parent 801dd1d commit 61daee6

File tree

12 files changed

+48
-60
lines changed

12 files changed

+48
-60
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
10661066
&cause,
10671067
param_env,
10681068
hidden_ty.ty,
1069-
true,
10701069
&mut obligations,
10711070
)?;
10721071

compiler/rustc_hir_typeck/src/coercion.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,21 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
14931493
return;
14941494
}
14951495

1496+
let (expected, found) = if label_expression_as_expected {
1497+
// In the case where this is a "forced unit", like
1498+
// `break`, we want to call the `()` "expected"
1499+
// since it is implied by the syntax.
1500+
// (Note: not all force-units work this way.)"
1501+
(expression_ty, self.merged_ty())
1502+
} else {
1503+
// Otherwise, the "expected" type for error
1504+
// reporting is the current unification type,
1505+
// which is basically the LUB of the expressions
1506+
// we've seen so far (combined with the expected
1507+
// type)
1508+
(self.merged_ty(), expression_ty)
1509+
};
1510+
14961511
// Handle the actual type unification etc.
14971512
let result = if let Some(expression) = expression {
14981513
if self.pushed == 0 {
@@ -1540,12 +1555,11 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15401555
// Another example is `break` with no argument expression.
15411556
assert!(expression_ty.is_unit(), "if let hack without unit type");
15421557
fcx.at(cause, fcx.param_env)
1543-
// needed for tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs
1544-
.eq_exp(
1558+
.eq(
1559+
// needed for tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs
15451560
DefineOpaqueTypes::Yes,
1546-
label_expression_as_expected,
1547-
expression_ty,
1548-
self.merged_ty(),
1561+
expected,
1562+
found,
15491563
)
15501564
.map(|infer_ok| {
15511565
fcx.register_infer_ok_obligations(infer_ok);
@@ -1579,20 +1593,6 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15791593
fcx.set_tainted_by_errors(
15801594
fcx.dcx().span_delayed_bug(cause.span, "coercion error but no error emitted"),
15811595
);
1582-
let (expected, found) = if label_expression_as_expected {
1583-
// In the case where this is a "forced unit", like
1584-
// `break`, we want to call the `()` "expected"
1585-
// since it is implied by the syntax.
1586-
// (Note: not all force-units work this way.)"
1587-
(expression_ty, self.merged_ty())
1588-
} else {
1589-
// Otherwise, the "expected" type for error
1590-
// reporting is the current unification type,
1591-
// which is basically the LUB of the expressions
1592-
// we've seen so far (combined with the expected
1593-
// type)
1594-
(self.merged_ty(), expression_ty)
1595-
};
15961596
let (expected, found) = fcx.resolve_vars_if_possible((expected, found));
15971597

15981598
let mut err;

compiler/rustc_infer/src/infer/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,11 @@ impl<'tcx> InferCtxt<'tcx> {
10321032
}
10331033

10341034
self.enter_forall(predicate, |ty::SubtypePredicate { a_is_expected, a, b }| {
1035-
Ok(self.at(cause, param_env).sub_exp(DefineOpaqueTypes::No, a_is_expected, a, b))
1035+
if a_is_expected {
1036+
Ok(self.at(cause, param_env).sub(DefineOpaqueTypes::No, a, b))
1037+
} else {
1038+
Ok(self.at(cause, param_env).sup(DefineOpaqueTypes::No, b, a))
1039+
}
10361040
})
10371041
}
10381042

compiler/rustc_infer/src/infer/opaque_types.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl<'tcx> InferCtxt<'tcx> {
102102
return Ok(InferOk { value: (), obligations: vec![] });
103103
}
104104
let (a, b) = if a_is_expected { (a, b) } else { (b, a) };
105-
let process = |a: Ty<'tcx>, b: Ty<'tcx>, a_is_expected| match *a.kind() {
105+
let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() {
106106
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) if def_id.is_local() => {
107107
let def_id = def_id.expect_local();
108108
match self.defining_use_anchor {
@@ -169,14 +169,13 @@ impl<'tcx> InferCtxt<'tcx> {
169169
cause.clone(),
170170
param_env,
171171
b,
172-
a_is_expected,
173172
))
174173
}
175174
_ => None,
176175
};
177-
if let Some(res) = process(a, b, true) {
176+
if let Some(res) = process(a, b) {
178177
res
179-
} else if let Some(res) = process(b, a, false) {
178+
} else if let Some(res) = process(b, a) {
180179
res
181180
} else {
182181
let (a, b) = self.resolve_vars_if_possible((a, b));
@@ -520,7 +519,6 @@ impl<'tcx> InferCtxt<'tcx> {
520519
cause: ObligationCause<'tcx>,
521520
param_env: ty::ParamEnv<'tcx>,
522521
hidden_ty: Ty<'tcx>,
523-
a_is_expected: bool,
524522
) -> InferResult<'tcx, ()> {
525523
let mut obligations = Vec::new();
526524

@@ -529,7 +527,6 @@ impl<'tcx> InferCtxt<'tcx> {
529527
&cause,
530528
param_env,
531529
hidden_ty,
532-
a_is_expected,
533530
&mut obligations,
534531
)?;
535532

@@ -558,7 +555,6 @@ impl<'tcx> InferCtxt<'tcx> {
558555
cause: &ObligationCause<'tcx>,
559556
param_env: ty::ParamEnv<'tcx>,
560557
hidden_ty: Ty<'tcx>,
561-
a_is_expected: bool,
562558
obligations: &mut Vec<PredicateObligation<'tcx>>,
563559
) -> Result<(), TypeError<'tcx>> {
564560
// Ideally, we'd get the span where *this specific `ty` came
@@ -586,7 +582,7 @@ impl<'tcx> InferCtxt<'tcx> {
586582
if let Some(prev) = prev {
587583
obligations.extend(
588584
self.at(cause, param_env)
589-
.eq_exp(DefineOpaqueTypes::Yes, a_is_expected, prev, hidden_ty)?
585+
.eq(DefineOpaqueTypes::Yes, prev, hidden_ty)?
590586
.obligations,
591587
);
592588
}

compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,6 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
904904
&ObligationCause::dummy(),
905905
param_env,
906906
hidden_ty,
907-
true,
908907
&mut obligations,
909908
)?;
910909
self.add_goals(GoalSource::Misc, obligations.into_iter().map(|o| o.into()));

compiler/rustc_trait_selection/src/traits/engine.rs

-18
Original file line numberDiff line numberDiff line change
@@ -116,24 +116,6 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
116116
self.infcx.at(cause, param_env).deeply_normalize(value, &mut **self.engine.borrow_mut())
117117
}
118118

119-
/// Makes `expected <: actual`.
120-
pub fn eq_exp<T>(
121-
&self,
122-
cause: &ObligationCause<'tcx>,
123-
param_env: ty::ParamEnv<'tcx>,
124-
a_is_expected: bool,
125-
a: T,
126-
b: T,
127-
) -> Result<(), TypeError<'tcx>>
128-
where
129-
T: ToTrace<'tcx>,
130-
{
131-
self.infcx
132-
.at(cause, param_env)
133-
.eq_exp(DefineOpaqueTypes::Yes, a_is_expected, a, b)
134-
.map(|infer_ok| self.register_infer_ok_obligations(infer_ok))
135-
}
136-
137119
pub fn eq<T: ToTrace<'tcx>>(
138120
&self,
139121
cause: &ObligationCause<'tcx>,

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

+9-4
Original file line numberDiff line numberDiff line change
@@ -1528,19 +1528,24 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
15281528
| ObligationCauseCode::Coercion { .. }
15291529
);
15301530

1531+
let (expected, actual) = if is_normalized_term_expected {
1532+
(normalized_term, data.term)
1533+
} else {
1534+
(data.term, normalized_term)
1535+
};
1536+
15311537
// constrain inference variables a bit more to nested obligations from normalize so
15321538
// we can have more helpful errors.
15331539
//
15341540
// we intentionally drop errors from normalization here,
15351541
// since the normalization is just done to improve the error message.
15361542
let _ = ocx.select_where_possible();
15371543

1538-
if let Err(new_err) = ocx.eq_exp(
1544+
if let Err(new_err) = ocx.eq(
15391545
&obligation.cause,
15401546
obligation.param_env,
1541-
is_normalized_term_expected,
1542-
normalized_term,
1543-
data.term,
1547+
expected,
1548+
actual,
15441549
) {
15451550
(Some((data, is_normalized_term_expected, normalized_term, data.term)), new_err)
15461551
} else {

tests/ui/traits/negative-bounds/opaque-type-unsatisfied-bound.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ fn main() {
1313
}
1414

1515
fn weird0() -> impl Sized + !Sized {}
16-
//~^ ERROR type mismatch resolving `() == impl !Sized + Sized`
16+
//~^ ERROR type mismatch resolving `impl !Sized + Sized == ()`
1717
fn weird1() -> impl !Sized + Sized {}
18-
//~^ ERROR type mismatch resolving `() == impl !Sized + Sized`
18+
//~^ ERROR type mismatch resolving `impl !Sized + Sized == ()`
1919
fn weird2() -> impl !Sized {}
20-
//~^ ERROR type mismatch resolving `() == impl !Sized`
20+
//~^ ERROR type mismatch resolving `impl !Sized == ()`

tests/ui/traits/negative-bounds/opaque-type-unsatisfied-bound.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
error[E0271]: type mismatch resolving `() == impl !Sized + Sized`
1+
error[E0271]: type mismatch resolving `impl !Sized + Sized == ()`
22
--> $DIR/opaque-type-unsatisfied-bound.rs:15:16
33
|
44
LL | fn weird0() -> impl Sized + !Sized {}
55
| ^^^^^^^^^^^^^^^^^^^ types differ
66

7-
error[E0271]: type mismatch resolving `() == impl !Sized + Sized`
7+
error[E0271]: type mismatch resolving `impl !Sized + Sized == ()`
88
--> $DIR/opaque-type-unsatisfied-bound.rs:17:16
99
|
1010
LL | fn weird1() -> impl !Sized + Sized {}
1111
| ^^^^^^^^^^^^^^^^^^^ types differ
1212

13-
error[E0271]: type mismatch resolving `() == impl !Sized`
13+
error[E0271]: type mismatch resolving `impl !Sized == ()`
1414
--> $DIR/opaque-type-unsatisfied-bound.rs:19:16
1515
|
1616
LL | fn weird2() -> impl !Sized {}

tests/ui/traits/negative-bounds/opaque-type-unsatisfied-fn-bound.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
#![feature(negative_bounds, unboxed_closures)]
44

55
fn produce() -> impl !Fn<(u32,)> {}
6-
//~^ ERROR type mismatch resolving `() == impl !Fn<(u32,)>`
6+
//~^ ERROR type mismatch resolving `impl !Fn<(u32,)> == ()`
77

88
fn main() {}

tests/ui/traits/negative-bounds/opaque-type-unsatisfied-fn-bound.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0271]: type mismatch resolving `() == impl !Fn<(u32,)>`
1+
error[E0271]: type mismatch resolving `impl !Fn<(u32,)> == ()`
22
--> $DIR/opaque-type-unsatisfied-fn-bound.rs:5:17
33
|
44
LL | fn produce() -> impl !Fn<(u32,)> {}

tests/ui/type-alias-impl-trait/itiat-allow-nested-closures.bad.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ LL | let _: i32 = closure();
88
| --- ^^^^^^^^^ expected `i32`, found opaque type
99
| |
1010
| expected due to this
11+
|
12+
= note: expected type `i32`
13+
found opaque type `<() as Foo>::Assoc`
1114

1215
error[E0308]: mismatched types
1316
--> $DIR/itiat-allow-nested-closures.rs:22:9

0 commit comments

Comments
 (0)