Skip to content

Commit 46a7e24

Browse files
Get rid of some sub_exp and eq_exp
1 parent cce7bca commit 46a7e24

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
@@ -1483,6 +1483,21 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
14831483
return;
14841484
}
14851485

1486+
let (expected, found) = if label_expression_as_expected {
1487+
// In the case where this is a "forced unit", like
1488+
// `break`, we want to call the `()` "expected"
1489+
// since it is implied by the syntax.
1490+
// (Note: not all force-units work this way.)"
1491+
(expression_ty, self.merged_ty())
1492+
} else {
1493+
// Otherwise, the "expected" type for error
1494+
// reporting is the current unification type,
1495+
// which is basically the LUB of the expressions
1496+
// we've seen so far (combined with the expected
1497+
// type)
1498+
(self.merged_ty(), expression_ty)
1499+
};
1500+
14861501
// Handle the actual type unification etc.
14871502
let result = if let Some(expression) = expression {
14881503
if self.pushed == 0 {
@@ -1530,12 +1545,11 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15301545
// Another example is `break` with no argument expression.
15311546
assert!(expression_ty.is_unit(), "if let hack without unit type");
15321547
fcx.at(cause, fcx.param_env)
1533-
// needed for tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs
1534-
.eq_exp(
1548+
.eq(
1549+
// needed for tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs
15351550
DefineOpaqueTypes::Yes,
1536-
label_expression_as_expected,
1537-
expression_ty,
1538-
self.merged_ty(),
1551+
expected,
1552+
found,
15391553
)
15401554
.map(|infer_ok| {
15411555
fcx.register_infer_ok_obligations(infer_ok);
@@ -1569,20 +1583,6 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15691583
fcx.set_tainted_by_errors(
15701584
fcx.dcx().span_delayed_bug(cause.span, "coercion error but no error emitted"),
15711585
);
1572-
let (expected, found) = if label_expression_as_expected {
1573-
// In the case where this is a "forced unit", like
1574-
// `break`, we want to call the `()` "expected"
1575-
// since it is implied by the syntax.
1576-
// (Note: not all force-units work this way.)"
1577-
(expression_ty, self.merged_ty())
1578-
} else {
1579-
// Otherwise, the "expected" type for error
1580-
// reporting is the current unification type,
1581-
// which is basically the LUB of the expressions
1582-
// we've seen so far (combined with the expected
1583-
// type)
1584-
(self.merged_ty(), expression_ty)
1585-
};
15861586
let (expected, found) = fcx.resolve_vars_if_possible((expected, found));
15871587

15881588
let mut err;

compiler/rustc_infer/src/infer/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,11 @@ impl<'tcx> InferCtxt<'tcx> {
10391039
}
10401040

10411041
self.enter_forall(predicate, |ty::SubtypePredicate { a_is_expected, a, b }| {
1042-
Ok(self.at(cause, param_env).sub_exp(DefineOpaqueTypes::No, a_is_expected, a, b))
1042+
if a_is_expected {
1043+
Ok(self.at(cause, param_env).sub(DefineOpaqueTypes::No, a, b))
1044+
} else {
1045+
Ok(self.at(cause, param_env).sup(DefineOpaqueTypes::No, b, a))
1046+
}
10431047
})
10441048
}
10451049

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
@@ -906,7 +906,6 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
906906
&ObligationCause::dummy(),
907907
param_env,
908908
hidden_ty,
909-
true,
910909
&mut obligations,
911910
)?;
912911
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
@@ -107,24 +107,6 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
107107
self.register_infer_ok_obligations(infer_ok)
108108
}
109109

110-
/// Makes `expected <: actual`.
111-
pub fn eq_exp<T>(
112-
&self,
113-
cause: &ObligationCause<'tcx>,
114-
param_env: ty::ParamEnv<'tcx>,
115-
a_is_expected: bool,
116-
a: T,
117-
b: T,
118-
) -> Result<(), TypeError<'tcx>>
119-
where
120-
T: ToTrace<'tcx>,
121-
{
122-
self.infcx
123-
.at(cause, param_env)
124-
.eq_exp(DefineOpaqueTypes::Yes, a_is_expected, a, b)
125-
.map(|infer_ok| self.register_infer_ok_obligations(infer_ok))
126-
}
127-
128110
pub fn eq<T: ToTrace<'tcx>>(
129111
&self,
130112
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)