]> git.lizzy.rs Git - rust.git/commitdiff
normalize_generic_arg_after in terms of try version
authorb-naber <bn263@gmx.de>
Wed, 8 Dec 2021 17:11:13 +0000 (18:11 +0100)
committerb-naber <bn263@gmx.de>
Mon, 13 Dec 2021 22:04:09 +0000 (23:04 +0100)
compiler/rustc_traits/src/normalize_erasing_regions.rs

index 4f35909df7f6a8d1ff200a93dad4dcbc21fe5b2c..f7d1ebed7d72feec8c1a0c7cb1b623dd9f4a3bbb 100644 (file)
                 .perf_stats
                 .normalize_generic_arg_after_erasing_regions
                 .fetch_add(1, Ordering::Relaxed);
-            normalize_after_erasing_regions(tcx, goal)
+
+            let (param_env, goal) = goal.into_parts();
+            tcx.try_normalize_erasing_regions(param_env, goal).unwrap_or_else(|_| bug!(
+                "Failed to normalize {:?}, maybe try to call `try_normalize_erasing_regions` instead",
+                goal
+            ))
         },
         normalize_mir_const_after_erasing_regions: |tcx, goal| {
-            normalize_after_erasing_regions(tcx, goal)
+            let (param_env, goal) = goal.into_parts();
+            tcx.try_normalize_erasing_regions(param_env, goal).unwrap_or_else(|_| bug!(
+                "Failed to normalize {:?}, maybe try to call `try_normalize_erasing_regions` instead",
+                goal
+            ))
         },
         try_normalize_generic_arg_after_erasing_regions: |tcx, goal| {
             debug!("try_normalize_generic_arg_after_erasing_regions(goal={:#?}", goal);
     };
 }
 
-#[instrument(level = "debug", skip(tcx))]
-fn normalize_after_erasing_regions<'tcx, T: TypeFoldable<'tcx> + PartialEq + Copy>(
-    tcx: TyCtxt<'tcx>,
-    goal: ParamEnvAnd<'tcx, T>,
-) -> T {
-    let ParamEnvAnd { param_env, value } = goal;
-    tcx.infer_ctxt().enter(|infcx| {
-        let cause = ObligationCause::dummy();
-        match infcx.at(&cause, param_env).normalize(value) {
-            Ok(Normalized { value: normalized_value, obligations: normalized_obligations }) => {
-                // We don't care about the `obligations`; they are
-                // always only region relations, and we are about to
-                // erase those anyway:
-                debug_assert_eq!(
-                    normalized_obligations.iter().find(|p| not_outlives_predicate(&p.predicate)),
-                    None,
-                );
-
-                let resolved_value = infcx.resolve_vars_if_possible(normalized_value);
-                // It's unclear when `resolve_vars` would have an effect in a
-                // fresh `InferCtxt`. If this assert does trigger, it will give
-                // us a test case.
-                debug_assert_eq!(normalized_value, resolved_value);
-                let erased = infcx.tcx.erase_regions(resolved_value);
-                debug_assert!(!erased.needs_infer(), "{:?}", erased);
-                erased
-            }
-            Err(NoSolution) => bug!("could not fully normalize `{:?}`", value),
-        }
-    })
-}
-
 #[instrument(level = "debug", skip(tcx))]
 fn try_normalize_after_erasing_regions<'tcx, T: TypeFoldable<'tcx> + PartialEq + Copy>(
     tcx: TyCtxt<'tcx>,