@@ -103,11 +103,6 @@ fn coerce_mutbls<'tcx>(
103
103
if from_mutbl >= to_mutbl { Ok ( ( ) ) } else { Err ( TypeError :: Mutability ) }
104
104
}
105
105
106
- /// Do not require any adjustments, i.e. coerce `x -> x`.
107
- fn identity ( _: Ty < ' _ > ) -> Vec < Adjustment < ' _ > > {
108
- vec ! [ ]
109
- }
110
-
111
106
fn simple < ' tcx > ( kind : Adjust ) -> impl FnOnce ( Ty < ' tcx > ) -> Vec < Adjustment < ' tcx > > {
112
107
move |target| vec ! [ Adjustment { kind, target } ]
113
108
}
@@ -161,6 +156,12 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
161
156
} )
162
157
}
163
158
159
+ /// Unify two types (using sub or lub).
160
+ fn unify ( & self , a : Ty < ' tcx > , b : Ty < ' tcx > ) -> CoerceResult < ' tcx > {
161
+ self . unify_raw ( a, b)
162
+ . and_then ( |InferOk { value : ty, obligations } | success ( vec ! [ ] , ty, obligations) )
163
+ }
164
+
164
165
/// Unify two types (using sub or lub) and produce a specific coercion.
165
166
fn unify_and < F > ( & self , a : Ty < ' tcx > , b : Ty < ' tcx > , f : F ) -> CoerceResult < ' tcx >
166
167
where
@@ -183,7 +184,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
183
184
return success ( simple ( Adjust :: NeverToAny ) ( b) , b, PredicateObligations :: new ( ) ) ;
184
185
} else {
185
186
// Otherwise the only coercion we can do is unification.
186
- return self . unify_and ( a, b, identity ) ;
187
+ return self . unify ( a, b) ;
187
188
}
188
189
}
189
190
@@ -257,7 +258,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
257
258
}
258
259
_ => {
259
260
// Otherwise, just use unification rules.
260
- self . unify_and ( a, b, identity )
261
+ self . unify ( a, b)
261
262
}
262
263
}
263
264
}
@@ -297,7 +298,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
297
298
} else {
298
299
// One unresolved type variable: just apply subtyping, we may be able
299
300
// to do something useful.
300
- self . unify_and ( a, b, identity )
301
+ self . unify ( a, b)
301
302
}
302
303
}
303
304
@@ -325,7 +326,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
325
326
coerce_mutbls ( mt_a. mutbl , mutbl_b) ?;
326
327
( r_a, mt_a)
327
328
}
328
- _ => return self . unify_and ( a, b, identity ) ,
329
+ _ => return self . unify ( a, b) ,
329
330
} ;
330
331
331
332
let span = self . cause . span ;
@@ -702,7 +703,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
702
703
&& let ty:: Dynamic ( b_data, _, ty:: DynStar ) = b. kind ( )
703
704
&& a_data. principal_def_id ( ) == b_data. principal_def_id ( )
704
705
{
705
- return self . unify_and ( a, b, identity ) ;
706
+ return self . unify ( a, b) ;
706
707
}
707
708
708
709
// Check the obligations of the cast -- for example, when casting
@@ -917,7 +918,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
917
918
obligations. extend ( o2) ;
918
919
Ok ( InferOk { value, obligations } )
919
920
}
920
- _ => self . unify_and ( a, b, identity ) ,
921
+ _ => self . unify ( a, b) ,
921
922
}
922
923
}
923
924
@@ -964,7 +965,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
964
965
simple ( Adjust :: Pointer ( PointerCoercion :: ClosureFnPointer ( safety) ) ) ,
965
966
)
966
967
}
967
- _ => self . unify_and ( a, b, identity ) ,
968
+ _ => self . unify ( a, b) ,
968
969
}
969
970
}
970
971
@@ -979,7 +980,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
979
980
let ( is_ref, mt_a) = match * a. kind ( ) {
980
981
ty:: Ref ( _, ty, mutbl) => ( true , ty:: TypeAndMut { ty, mutbl } ) ,
981
982
ty:: RawPtr ( ty, mutbl) => ( false , ty:: TypeAndMut { ty, mutbl } ) ,
982
- _ => return self . unify_and ( a, b, identity ) ,
983
+ _ => return self . unify ( a, b) ,
983
984
} ;
984
985
coerce_mutbls ( mt_a. mutbl , mutbl_b) ?;
985
986
@@ -998,7 +999,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
998
999
} else if mt_a. mutbl != mutbl_b {
999
1000
self . unify_and ( a_raw, b, simple ( Adjust :: Pointer ( PointerCoercion :: MutToConstPointer ) ) )
1000
1001
} else {
1001
- self . unify_and ( a_raw, b, identity )
1002
+ self . unify ( a_raw, b)
1002
1003
}
1003
1004
}
1004
1005
}
0 commit comments