diff options
| author | bors <bors@rust-lang.org> | 2025-07-27 15:56:47 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-07-27 15:56:47 +0000 |
| commit | 4b596bbd847672da87763b76171687d3544863c2 (patch) | |
| tree | a1c9b7563092ab8033258339f275c760d4fb7f1e | |
| parent | edc3841c5d28e0f54c6d3c7e906ad083129f3903 (diff) | |
| parent | 9d57f5e296d2f734c46b67ce7edbd709ebdcc774 (diff) | |
| download | rust-4b596bbd847672da87763b76171687d3544863c2.tar.gz rust-4b596bbd847672da87763b76171687d3544863c2.zip | |
Auto merge of #144425 - nnethercote:avoid-new_adt-new_fn_def, r=compiler-errors
Avoid unnecessary `new_adt`/`new_fn_def` calls. They can be skipped if there are no arguments, avoiding the "relate" operation work and also the subsequent interning. r? `@ghost`
| -rw-r--r-- | compiler/rustc_type_ir/src/relate.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/compiler/rustc_type_ir/src/relate.rs b/compiler/rustc_type_ir/src/relate.rs index e3c4a793b37..3a00fe89360 100644 --- a/compiler/rustc_type_ir/src/relate.rs +++ b/compiler/rustc_type_ir/src/relate.rs @@ -400,8 +400,12 @@ pub fn structurally_relate_tys<I: Interner, R: TypeRelation<I>>( (ty::Placeholder(p1), ty::Placeholder(p2)) if p1 == p2 => Ok(a), (ty::Adt(a_def, a_args), ty::Adt(b_def, b_args)) if a_def == b_def => { - let args = relation.relate_item_args(a_def.def_id(), a_args, b_args)?; - Ok(Ty::new_adt(cx, a_def, args)) + Ok(if a_args.is_empty() { + a + } else { + let args = relation.relate_item_args(a_def.def_id(), a_args, b_args)?; + if args == a_args { a } else { Ty::new_adt(cx, a_def, args) } + }) } (ty::Foreign(a_id), ty::Foreign(b_id)) if a_id == b_id => Ok(Ty::new_foreign(cx, a_id)), @@ -515,8 +519,12 @@ pub fn structurally_relate_tys<I: Interner, R: TypeRelation<I>>( } (ty::FnDef(a_def_id, a_args), ty::FnDef(b_def_id, b_args)) if a_def_id == b_def_id => { - let args = relation.relate_item_args(a_def_id, a_args, b_args)?; - Ok(Ty::new_fn_def(cx, a_def_id, args)) + Ok(if a_args.is_empty() { + a + } else { + let args = relation.relate_item_args(a_def_id, a_args, b_args)?; + if args == a_args { a } else { Ty::new_fn_def(cx, a_def_id, args) } + }) } (ty::FnPtr(a_sig_tys, a_hdr), ty::FnPtr(b_sig_tys, b_hdr)) => { |
