@@ -1230,6 +1230,65 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1230
1230
self . inlined_shallow_resolve ( typ)
1231
1231
}
1232
1232
1233
+ /// A hacky sort of method used by the NLL type-relating code:
1234
+ ///
1235
+ /// - `var` must be some unbound type variable.
1236
+ /// - `value` must be a suitable type to use as its value.
1237
+ ///
1238
+ /// `var` will then be equated with `value`. Note that this
1239
+ /// sidesteps a number of important checks, such as the "occurs
1240
+ /// check" that prevents cyclic types, so it is important not to
1241
+ /// use this method during regular type-check.
1242
+ pub fn force_instantiate_unchecked ( & self , var : Ty < ' tcx > , value : Ty < ' tcx > ) {
1243
+ match ( & var. sty , & value. sty ) {
1244
+ ( & ty:: Infer ( ty:: TyVar ( vid) ) , _) => {
1245
+ let mut type_variables = self . type_variables . borrow_mut ( ) ;
1246
+
1247
+ // In NLL, we don't have type inference variables
1248
+ // floating around, so we can do this rather imprecise
1249
+ // variant of the occurs-check.
1250
+ assert ! ( !value. has_infer_types( ) ) ;
1251
+
1252
+ type_variables. instantiate ( vid, value) ;
1253
+ }
1254
+
1255
+ ( & ty:: Infer ( ty:: IntVar ( vid) ) , & ty:: Int ( value) ) => {
1256
+ let mut int_unification_table = self . int_unification_table . borrow_mut ( ) ;
1257
+ int_unification_table
1258
+ . unify_var_value ( vid, Some ( ty:: IntVarValue :: IntType ( value) ) )
1259
+ . unwrap_or_else ( |_| {
1260
+ bug ! ( "failed to unify int var `{:?}` with `{:?}`" , vid, value) ;
1261
+ } ) ;
1262
+ }
1263
+
1264
+ ( & ty:: Infer ( ty:: IntVar ( vid) ) , & ty:: Uint ( value) ) => {
1265
+ let mut int_unification_table = self . int_unification_table . borrow_mut ( ) ;
1266
+ int_unification_table
1267
+ . unify_var_value ( vid, Some ( ty:: IntVarValue :: UintType ( value) ) )
1268
+ . unwrap_or_else ( |_| {
1269
+ bug ! ( "failed to unify int var `{:?}` with `{:?}`" , vid, value) ;
1270
+ } ) ;
1271
+ }
1272
+
1273
+ ( & ty:: Infer ( ty:: FloatVar ( vid) ) , & ty:: Float ( value) ) => {
1274
+ let mut float_unification_table = self . float_unification_table . borrow_mut ( ) ;
1275
+ float_unification_table
1276
+ . unify_var_value ( vid, Some ( ty:: FloatVarValue ( value) ) )
1277
+ . unwrap_or_else ( |_| {
1278
+ bug ! ( "failed to unify float var `{:?}` with `{:?}`" , vid, value)
1279
+ } ) ;
1280
+ }
1281
+
1282
+ _ => {
1283
+ bug ! (
1284
+ "force_instantiate_unchecked invoked with bad combination: var={:?} value={:?}" ,
1285
+ var,
1286
+ value,
1287
+ ) ;
1288
+ }
1289
+ }
1290
+ }
1291
+
1233
1292
pub fn resolve_type_vars_if_possible < T > ( & self , value : & T ) -> T
1234
1293
where
1235
1294
T : TypeFoldable < ' tcx > ,
0 commit comments