diff --git a/compiler/rustc_type_ir/src/predicate.rs b/compiler/rustc_type_ir/src/predicate.rs index f02d9c988c8de..f8b4ab9788677 100644 --- a/compiler/rustc_type_ir/src/predicate.rs +++ b/compiler/rustc_type_ir/src/predicate.rs @@ -98,6 +98,11 @@ impl TraitRef { } pub fn with_self_ty(self, interner: I, self_ty: I::Ty) -> Self { + // Don't re-intern if the self ty didn't change. + if self_ty == self.args.type_at(0) { + return self; + } + TraitRef::new( interner, self.def_id, @@ -646,6 +651,10 @@ impl AliasTerm { } pub fn with_self_ty(self, interner: I, self_ty: I::Ty) -> Self { + if self_ty == self.args.type_at(0) { + return self; + } + AliasTerm::new( interner, self.def_id, diff --git a/compiler/rustc_type_ir/src/ty_kind.rs b/compiler/rustc_type_ir/src/ty_kind.rs index 0cd98b5aa53b4..decf4428c9094 100644 --- a/compiler/rustc_type_ir/src/ty_kind.rs +++ b/compiler/rustc_type_ir/src/ty_kind.rs @@ -481,6 +481,11 @@ impl AliasTy { } pub fn with_self_ty(self, interner: I, self_ty: I::Ty) -> Self { + // Don't re-intern if the self ty didn't change. + if self_ty == self.args.type_at(0) { + return self; + } + AliasTy::new( interner, self.def_id,