Skip to content

Commit e3eba2d

Browse files
Don't structurally resolve in may_coerce
1 parent b4e9aad commit e3eba2d

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

compiler/rustc_hir_typeck/src/coercion.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1091,16 +1091,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10911091
///
10921092
/// This should only be used for diagnostics.
10931093
pub(crate) fn may_coerce(&self, expr_ty: Ty<'tcx>, target_ty: Ty<'tcx>) -> bool {
1094-
// FIXME(-Znext-solver): We need to structurally resolve both types here.
1095-
let source = self.resolve_vars_with_obligations(expr_ty);
1096-
debug!("coercion::can_with_predicates({:?} -> {:?})", source, target_ty);
1097-
10981094
let cause = self.cause(DUMMY_SP, ObligationCauseCode::ExprAssignable);
10991095
// We don't ever need two-phase here since we throw out the result of the coercion.
11001096
// We also just always set `coerce_never` to true, since this is a heuristic.
11011097
let coerce = Coerce::new(self, cause, AllowTwoPhase::No, true);
11021098
self.probe(|_| {
1103-
let Ok(ok) = coerce.coerce(source, target_ty) else {
1099+
let Ok(ok) = coerce.coerce(expr_ty, target_ty) else {
11041100
return false;
11051101
};
11061102
let ocx = ObligationCtxt::new(self);

tests/ui/type-alias-impl-trait/lazy_subtyping_of_opaques.stderr

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/lazy_subtyping_of_opaques.rs:11:5
3+
|
4+
LL | fn reify_as_tait() -> Thunk<Tait> {
5+
| ----------- expected `Thunk<_>` because of return type
6+
LL |
7+
LL | Thunk::new(|cont| cont)
8+
| ^^^^^^^^^^^^^^^^^^^^^^^ expected `Thunk<_>`, found `()`
9+
|
10+
= note: expected struct `Thunk<_>`
11+
found unit type `()`
12+
113
error[E0277]: expected a `FnOnce()` closure, found `()`
214
--> $DIR/lazy_subtyping_of_opaques.rs:11:23
315
|
@@ -12,19 +24,13 @@ error[E0277]: expected a `FnOnce()` closure, found `()`
1224
|
1325
LL | fn reify_as_tait() -> Thunk<Tait> {
1426
| ^^^^^^^^^^^ expected an `FnOnce()` closure, found `()`
27+
LL |
28+
LL | Thunk::new(|cont| cont)
29+
| ----------------------- return type was inferred to be `{type error}` here
1530
|
1631
= help: the trait `FnOnce()` is not implemented for `()`
1732
= note: wrap the `()` in a closure with no arguments: `|| { /* code */ }`
1833

19-
error[E0308]: mismatched types
20-
--> $DIR/lazy_subtyping_of_opaques.rs:11:5
21-
|
22-
LL | Thunk::new(|cont| cont)
23-
| ^^^^^^^^^^^^^^^^^^^^^^^ expected `Thunk<_>`, found `()`
24-
|
25-
= note: expected struct `Thunk<_>`
26-
found unit type `()`
27-
2834
error: aborting due to 3 previous errors
2935

3036
Some errors have detailed explanations: E0277, E0308.

0 commit comments

Comments
 (0)