about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2018-10-11 17:43:05 -0400
committerNiko Matsakis <niko@alum.mit.edu>2018-10-15 16:25:08 -0400
commit0e1d3624e990e84299ab75926c865f19353e9b2f (patch)
treea07e61cce5ecf509f474ed19be9b96252adb454e
parent1443ac0aa7d9c877b8fdbefbbd99092a517802d2 (diff)
downloadrust-0e1d3624e990e84299ab75926c865f19353e9b2f.tar.gz
rust-0e1d3624e990e84299ab75926c865f19353e9b2f.zip
pull the common code across user-ty variants up top
-rw-r--r--src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs56
1 files changed, 34 insertions, 22 deletions
diff --git a/src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs b/src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs
index ebf9c7b4826..f59bcd53fa7 100644
--- a/src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs
+++ b/src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs
@@ -72,26 +72,6 @@ pub(super) fn relate_type_and_user_type<'tcx>(
         a, v, user_ty, locations
     );
 
-    let b = match user_ty {
-        UserTypeAnnotation::Ty(canonical_ty) => {
-            let (ty, _) =
-                infcx.instantiate_canonical_with_fresh_inference_vars(DUMMY_SP, &canonical_ty);
-            ty
-        }
-        UserTypeAnnotation::FnDef(def_id, canonical_substs) => {
-            let (UserSubsts { substs, user_self_ty }, _) =
-                infcx.instantiate_canonical_with_fresh_inference_vars(DUMMY_SP, &canonical_substs);
-            assert!(user_self_ty.is_none()); // TODO for now
-            infcx.tcx.mk_fn_def(def_id, substs)
-        }
-        UserTypeAnnotation::AdtDef(adt_def, canonical_substs) => {
-            let (UserSubsts { substs, user_self_ty }, _) =
-                infcx.instantiate_canonical_with_fresh_inference_vars(DUMMY_SP, &canonical_substs);
-            assert!(user_self_ty.is_none()); // TODO for now
-            infcx.tcx.mk_adt(adt_def, substs)
-        }
-    };
-
     // The `TypeRelating` code assumes that the "canonical variables"
     // appear in the "a" side, so flip `Contravariant` ambient
     // variance to get the right relationship.
@@ -102,9 +82,41 @@ pub(super) fn relate_type_and_user_type<'tcx>(
         NllTypeRelatingDelegate::new(infcx, borrowck_context, locations, category),
         v1,
     );
-    type_relating.relate(&b, &a)?;
 
-    Ok(b)
+    match user_ty {
+        UserTypeAnnotation::Ty(canonical_ty) => {
+            let (ty, _) =
+                infcx.instantiate_canonical_with_fresh_inference_vars(DUMMY_SP, &canonical_ty);
+            type_relating.relate(&ty, &a)?;
+            Ok(ty)
+        }
+        UserTypeAnnotation::FnDef(def_id, canonical_substs) => {
+            let (
+                UserSubsts {
+                    substs,
+                    user_self_ty,
+                },
+                _,
+            ) = infcx.instantiate_canonical_with_fresh_inference_vars(DUMMY_SP, &canonical_substs);
+            assert!(user_self_ty.is_none()); // TODO for now
+            let ty = infcx.tcx.mk_fn_def(def_id, substs);
+            type_relating.relate(&ty, &a)?;
+            Ok(ty)
+        }
+        UserTypeAnnotation::AdtDef(adt_def, canonical_substs) => {
+            let (
+                UserSubsts {
+                    substs,
+                    user_self_ty,
+                },
+                _,
+            ) = infcx.instantiate_canonical_with_fresh_inference_vars(DUMMY_SP, &canonical_substs);
+            assert!(user_self_ty.is_none()); // TODO for now
+            let ty = infcx.tcx.mk_adt(adt_def, substs);
+            type_relating.relate(&ty, &a)?;
+            Ok(ty)
+        }
+    }
 }
 
 struct NllTypeRelatingDelegate<'me, 'bccx: 'me, 'gcx: 'tcx, 'tcx: 'bccx> {