]> git.lizzy.rs Git - rust.git/blobdiff - src/common.rs
Don't perform a double substitution in some cases
[rust.git] / src / common.rs
index ec58a7d3d29e1e6d9e1160b69eed707f8c3f9b96..1d69018be50a4f82e47391d669028165ef18a400 100644 (file)
@@ -305,13 +305,17 @@ fn target_spec(&self) -> &Target {
 impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
     pub(crate) fn monomorphize<T>(&self, value: &T) -> T
     where
-        T: TypeFoldable<'tcx>,
+        T: TypeFoldable<'tcx> + Copy,
     {
-        self.tcx.subst_and_normalize_erasing_regions(
-            self.instance.substs,
-            ty::ParamEnv::reveal_all(),
-            value,
-        )
+        if let Some(substs) = self.instance.substs_for_mir_body() {
+            self.tcx.subst_and_normalize_erasing_regions(
+                substs,
+                ty::ParamEnv::reveal_all(),
+                value,
+            )
+        } else {
+            self.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), *value)
+        }
     }
 
     pub(crate) fn clif_type(&self, ty: Ty<'tcx>) -> Option<Type> {