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>
This commit is contained in:
parent
5827b5a4bd
commit
4ccaf6f38c
@ -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),
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user