Skip to content

Commit 4ccaf6f

Browse files
committed
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 <[email protected]>
1 parent 5827b5a commit 4ccaf6f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/librustc_middle/ty/instance.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -506,11 +506,19 @@ fn polymorphize<'tcx>(
506506
match ty.kind {
507507
ty::Closure(def_id, substs) => {
508508
let polymorphized_substs = polymorphize(self.tcx, def_id, substs);
509-
self.tcx.mk_closure(def_id, polymorphized_substs)
509+
if substs == polymorphized_substs {
510+
ty
511+
} else {
512+
self.tcx.mk_closure(def_id, polymorphized_substs)
513+
}
510514
}
511515
ty::Generator(def_id, substs, movability) => {
512516
let polymorphized_substs = polymorphize(self.tcx, def_id, substs);
513-
self.tcx.mk_generator(def_id, polymorphized_substs, movability)
517+
if substs == polymorphized_substs {
518+
ty
519+
} else {
520+
self.tcx.mk_generator(def_id, polymorphized_substs, movability)
521+
}
514522
}
515523
_ => ty.super_fold_with(self),
516524
}

0 commit comments

Comments
 (0)