Skip to content

Commit 39b5936

Browse files
Always structurally resolve coercion target
1 parent a1eceec commit 39b5936

File tree

6 files changed

+25
-33
lines changed

6 files changed

+25
-33
lines changed

compiler/rustc_hir_typeck/src/coercion.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1051,17 +1051,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10511051
&self,
10521052
expr: &'tcx hir::Expr<'tcx>,
10531053
expr_ty: Ty<'tcx>,
1054-
mut target: Ty<'tcx>,
1054+
target: Ty<'tcx>,
10551055
allow_two_phase: AllowTwoPhase,
10561056
cause: Option<ObligationCause<'tcx>>,
10571057
) -> RelateResult<'tcx, Ty<'tcx>> {
10581058
let source = self.try_structurally_resolve_type(expr.span, expr_ty);
1059-
if self.next_trait_solver() {
1060-
target = self.try_structurally_resolve_type(
1061-
cause.as_ref().map_or(expr.span, |cause| cause.span),
1062-
target,
1063-
);
1064-
}
1059+
let target = self.try_structurally_resolve_type(
1060+
cause.as_ref().map_or(expr.span, |cause| cause.span),
1061+
target,
1062+
);
10651063
debug!("coercion::try({:?}: {:?} -> {:?})", expr, source, target);
10661064

10671065
let cause =

compiler/rustc_hir_typeck/src/demand.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
251251
&'a self,
252252
mut expr: &'tcx hir::Expr<'tcx>,
253253
checked_ty: Ty<'tcx>,
254-
expected: Ty<'tcx>,
254+
expected_ty: Ty<'tcx>,
255255
mut expected_ty_expr: Option<&'tcx hir::Expr<'tcx>>,
256256
allow_two_phase: AllowTwoPhase,
257257
) -> Result<Ty<'tcx>, Diag<'a>> {
258-
let expected = self.resolve_vars_with_obligations(expected);
259-
260-
let e = match self.coerce(expr, checked_ty, expected, allow_two_phase, None) {
258+
let e = match self.coerce(expr, checked_ty, expected_ty, allow_two_phase, None) {
261259
Ok(ty) => return Ok(ty),
262260
Err(e) => e,
263261
};
@@ -271,6 +269,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
271269
let expr = expr.peel_drop_temps();
272270
let cause = self.misc(expr.span);
273271
let expr_ty = self.resolve_vars_if_possible(checked_ty);
272+
let expected = self.resolve_vars_if_possible(expected_ty);
274273
let mut err = self.err_ctxt().report_mismatched_types(&cause, expected, expr_ty, e);
275274

276275
self.emit_coerce_suggestions(&mut err, expr, expr_ty, expected, expected_ty_expr, Some(e));

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

-5
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
317317
// `ExpectHasType(expected_ty)`, or the `formal_ty` otherwise.
318318
let coerced_ty = expectation.only_has_type(self).unwrap_or(formal_input_ty);
319319

320-
// Cause selection errors caused by resolving a single argument to point at the
321-
// argument and not the call. This lets us customize the span pointed to in the
322-
// fulfillment error to be more accurate.
323-
let coerced_ty = self.resolve_vars_with_obligations(coerced_ty);
324-
325320
let coerce_error =
326321
self.coerce(provided_arg, checked_ty, coerced_ty, AllowTwoPhase::Yes, None).err();
327322
if coerce_error.is_some() {

compiler/rustc_hir_typeck/src/op.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
250250

251251
// see `NB` above
252252
let rhs_ty = self.check_expr_coercible_to_type(rhs_expr, rhs_ty_var, Some(lhs_expr));
253-
let rhs_ty = self.resolve_vars_with_obligations(rhs_ty);
253+
let rhs_ty = self.resolve_vars_if_possible(rhs_ty);
254254

255255
let return_ty = match result {
256256
Ok(method) => {

tests/ui/offset-of/offset-of-dst-field.stderr

+14-14
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ LL | offset_of!((u8, dyn Trait), 1);
3434
= help: the trait `Sized` is not implemented for `dyn Trait`
3535
= note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)
3636

37+
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
38+
--> $DIR/offset-of-dst-field.rs:44:5
39+
|
40+
LL | offset_of!(Delta<Alpha>, z);
41+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
42+
|
43+
= help: within `Alpha`, the trait `Sized` is not implemented for `[u8]`, which is required by `Alpha: Sized`
44+
note: required because it appears within the type `Alpha`
45+
--> $DIR/offset-of-dst-field.rs:5:8
46+
|
47+
LL | struct Alpha {
48+
| ^^^^^
49+
= note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)
50+
3751
error[E0277]: the size for values of type `Extern` cannot be known at compilation time
3852
--> $DIR/offset-of-dst-field.rs:45:5
3953
|
@@ -52,20 +66,6 @@ LL | offset_of!(Delta<dyn Trait>, z);
5266
= help: the trait `Sized` is not implemented for `dyn Trait`
5367
= note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)
5468

55-
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
56-
--> $DIR/offset-of-dst-field.rs:44:5
57-
|
58-
LL | offset_of!(Delta<Alpha>, z);
59-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
60-
|
61-
= help: within `Alpha`, the trait `Sized` is not implemented for `[u8]`, which is required by `Alpha: Sized`
62-
note: required because it appears within the type `Alpha`
63-
--> $DIR/offset-of-dst-field.rs:5:8
64-
|
65-
LL | struct Alpha {
66-
| ^^^^^
67-
= note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)
68-
6969
error[E0277]: the size for values of type `T` cannot be known at compilation time
7070
--> $DIR/offset-of-dst-field.rs:50:5
7171
|

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ error[E0308]: mismatched types
2020
--> $DIR/lazy_subtyping_of_opaques.rs:11:5
2121
|
2222
LL | Thunk::new(|cont| cont)
23-
| ^^^^^^^^^^^^^^^^^^^^^^^ expected `Thunk<_>`, found `()`
23+
| ^^^^^^^^^^^^^^^^^^^^^^^ expected `Thunk<()>`, found `()`
2424
|
25-
= note: expected struct `Thunk<_>`
25+
= note: expected struct `Thunk<()>`
2626
found unit type `()`
2727

2828
error: aborting due to 3 previous errors

0 commit comments

Comments
 (0)