Skip to content

Commit 5eca626

Browse files
nikomatsakisMark-Simulacrum
authored andcommitted
shallow resolve target type in coercion
We used to avoid doing this because we didn't want to make coercion depend on the state of inference. For better or worse, we have moved away from this position over time. Therefore, I am going to go ahead and resolve the `b` target type early on so that it is done uniformly. (The older technique for managing this was always something of a hack regardless; if we really wanted to avoid integrating coercion and inference we needed to be more disciplined about it.)
1 parent 7e0ae7d commit 5eca626

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

compiler/rustc_typeck/src/check/coercion.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
147147

148148
fn coerce(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> CoerceResult<'tcx> {
149149
let a = self.shallow_resolve(a);
150+
let b = self.shallow_resolve(b);
150151
debug!("Coerce.tys({:?} => {:?})", a, b);
151152

152153
// Just ignore error types.
@@ -162,8 +163,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
162163
// let _: Option<?T> = Some({ return; });
163164
//
164165
// here, we would coerce from `!` to `?T`.
165-
let b = self.shallow_resolve(b);
166-
return if self.shallow_resolve(b).is_ty_var() {
166+
return if b.is_ty_var() {
167167
// Micro-optimization: no need for this if `b` is
168168
// already resolved in some way.
169169
let diverging_ty = self.next_diverging_ty_var(TypeVariableOrigin {
@@ -196,9 +196,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
196196
debug!("coerce: unsize failed");
197197

198198
// Examine the supertype and consider auto-borrowing.
199-
//
200-
// Note: does not attempt to resolve type variables we encounter.
201-
// See above for details.
202199
match *b.kind() {
203200
ty::RawPtr(mt_b) => {
204201
return self.coerce_unsafe_ptr(a, b, mt_b.mutbl);

0 commit comments

Comments
 (0)