about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Wood <david@davidtw.co>2020-08-07 17:51:40 +0100
committerDavid Wood <david@davidtw.co>2020-08-07 18:41:43 +0100
commit4ccaf6f38ce5b617635ec5dc738275c681090eff (patch)
tree1ec0d255decac72e31311093100ea0e54b752ff1
parent5827b5a4bd0bb35251da12fc972aa1d5a210116f (diff)
downloadrust-4ccaf6f38ce5b617635ec5dc738275c681090eff.tar.gz
rust-4ccaf6f38ce5b617635ec5dc738275c681090eff.zip
instance: avoid unnecessary `mk_` calls
This commit avoids unnecessary calls to `mk_closure` and `mk_generator`
by checking if the polymorphized substs match the original substs.

Signed-off-by: David Wood <david@davidtw.co>
-rw-r--r--src/librustc_middle/ty/instance.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/librustc_middle/ty/instance.rs b/src/librustc_middle/ty/instance.rs
index 439e35c9757..0eea10513d1 100644
--- a/src/librustc_middle/ty/instance.rs
+++ b/src/librustc_middle/ty/instance.rs
@@ -506,11 +506,19 @@ fn polymorphize<'tcx>(
             match ty.kind {
                 ty::Closure(def_id, substs) => {
                     let polymorphized_substs = polymorphize(self.tcx, def_id, substs);
-                    self.tcx.mk_closure(def_id, polymorphized_substs)
+                    if substs == polymorphized_substs {
+                        ty
+                    } else {
+                        self.tcx.mk_closure(def_id, polymorphized_substs)
+                    }
                 }
                 ty::Generator(def_id, substs, movability) => {
                     let polymorphized_substs = polymorphize(self.tcx, def_id, substs);
-                    self.tcx.mk_generator(def_id, polymorphized_substs, movability)
+                    if substs == polymorphized_substs {
+                        ty
+                    } else {
+                        self.tcx.mk_generator(def_id, polymorphized_substs, movability)
+                    }
                 }
                 _ => ty.super_fold_with(self),
             }