about summary refs log tree commit diff
diff options
context:
space:
mode:
authorjackh726 <jack.huey@umassmed.edu>2021-07-23 00:10:56 -0400
committerjackh726 <jack.huey@umassmed.edu>2021-08-24 22:29:41 -0400
commit07ee86a6fd6ddf0750bf1f1e13b608e92a4e694f (patch)
tree7cd2c6e3e7c552fa986e651a2596d80bbada9f19
parent8d7707f3c4f72e6eb334d897354beca692b265d1 (diff)
downloadrust-07ee86a6fd6ddf0750bf1f1e13b608e92a4e694f.tar.gz
rust-07ee86a6fd6ddf0750bf1f1e13b608e92a4e694f.zip
Normalize only after failure
-rw-r--r--compiler/rustc_mir/src/borrow_check/type_check/input_output.rs76
1 files changed, 40 insertions, 36 deletions
diff --git a/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs b/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs
index ba358135558..1e0a2b0c421 100644
--- a/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs
+++ b/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs
@@ -82,33 +82,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
             let local = Local::new(argument_index + 1);
 
             let mir_input_ty = body.local_decls[local].ty;
-            // FIXME(jackh726): This is a hack. It's somewhat like
-            // `rustc_traits::normalize_after_erasing_regions`. Ideally, we'd
-            // like to normalize *before* inserting into `local_decls`, but I
-            // couldn't figure out where the heck that was.
-            let mir_input_ty = match self
-                .infcx
-                .at(&ObligationCause::dummy(), ty::ParamEnv::empty())
-                .normalize(mir_input_ty)
-            {
-                Ok(n) => {
-                    debug!("equate_inputs_and_outputs: {:?}", n);
-                    if n.obligations.iter().all(|o| {
-                        matches!(
-                            o.predicate.kind().skip_binder(),
-                            ty::PredicateKind::RegionOutlives(_)
-                        )
-                    }) {
-                        n.value
-                    } else {
-                        mir_input_ty
-                    }
-                }
-                Err(_) => {
-                    debug!("equate_inputs_and_outputs: NoSolution");
-                    mir_input_ty
-                }
-            };
             let mir_input_span = body.local_decls[local].source_info.span;
             self.equate_normalized_input_or_output(
                 normalized_input_ty,
@@ -191,17 +164,48 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
     fn equate_normalized_input_or_output(&mut self, a: Ty<'tcx>, b: Ty<'tcx>, span: Span) {
         debug!("equate_normalized_input_or_output(a={:?}, b={:?})", a, b);
 
-        if let Err(terr) =
+        if let Err(_) =
             self.eq_types(a, b, Locations::All(span), ConstraintCategory::BoringNoLocation)
         {
-            span_mirbug!(
-                self,
-                Location::START,
-                "equate_normalized_input_or_output: `{:?}=={:?}` failed with `{:?}`",
-                a,
-                b,
-                terr
-            );
+            // FIXME(jackh726): This is a hack. It's somewhat like
+            // `rustc_traits::normalize_after_erasing_regions`. Ideally, we'd
+            // like to normalize *before* inserting into `local_decls`, but I
+            // couldn't figure out where the heck that was.
+            let b = match self
+                .infcx
+                .at(&ObligationCause::dummy(), ty::ParamEnv::empty())
+                .normalize(b)
+            {
+                Ok(n) => {
+                    debug!("equate_inputs_and_outputs: {:?}", n);
+                    if n.obligations.iter().all(|o| {
+                        matches!(
+                            o.predicate.kind().skip_binder(),
+                            ty::PredicateKind::RegionOutlives(_)
+                        )
+                    }) {
+                        n.value
+                    } else {
+                        b
+                    }
+                }
+                Err(_) => {
+                    debug!("equate_inputs_and_outputs: NoSolution");
+                    b
+                }
+            };
+            if let Err(terr) =
+                self.eq_types(a, b, Locations::All(span), ConstraintCategory::BoringNoLocation)
+            {
+                span_mirbug!(
+                    self,
+                    Location::START,
+                    "equate_normalized_input_or_output: `{:?}=={:?}` failed with `{:?}`",
+                    a,
+                    b,
+                    terr
+                );
+            }
         }
     }
 }