]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_middle/src/ty/instance.rs
Auto merge of #91959 - matthiaskrgr:rollup-rhajuvw, r=matthiaskrgr
[rust.git] / compiler / rustc_middle / src / ty / instance.rs
index 4b38105e44717e52300e5b6f9e789e58f8093d12..2d301262730642aeaefefc3a59f290a82ba507f8 100644 (file)
@@ -7,6 +7,7 @@
 use rustc_hir::def_id::{CrateNum, DefId};
 use rustc_hir::lang_items::LangItem;
 use rustc_macros::HashStable;
+use rustc_middle::ty::normalize_erasing_regions::NormalizationError;
 
 use std::fmt;
 
@@ -575,6 +576,23 @@ pub fn subst_mir_and_normalize_erasing_regions<T>(
         }
     }
 
+    #[inline(always)]
+    pub fn try_subst_mir_and_normalize_erasing_regions<T>(
+        &self,
+        tcx: TyCtxt<'tcx>,
+        param_env: ty::ParamEnv<'tcx>,
+        v: T,
+    ) -> Result<T, NormalizationError<'tcx>>
+    where
+        T: TypeFoldable<'tcx> + Clone,
+    {
+        if let Some(substs) = self.substs_for_mir_body() {
+            tcx.try_subst_and_normalize_erasing_regions(substs, param_env, v)
+        } else {
+            tcx.try_normalize_erasing_regions(param_env, v)
+        }
+    }
+
     /// Returns a new `Instance` where generic parameters in `instance.substs` are replaced by
     /// identity parameters if they are determined to be unused in `instance.def`.
     pub fn polymorphize(self, tcx: TyCtxt<'tcx>) -> Self {