Skip to content

Commit 6f82bf1

Browse files
Auto merge of #142289 - fmease:maybe-perf-gen-args, r=<try>
[perf] Tweak `GenericArgs`-related functions
2 parents 40daf23 + e5e876a commit 6f82bf1

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

compiler/rustc_middle/src/ty/context.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,15 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
263263
}
264264
}
265265

266+
fn own_args_for_alias(
267+
self,
268+
def_id: DefId,
269+
args: ty::GenericArgsRef<'tcx>,
270+
) -> &'tcx [ty::GenericArg<'tcx>] {
271+
assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst);
272+
&args[self.generics_of(def_id).parent_count..]
273+
}
274+
266275
fn trait_ref_and_own_args_for_alias(
267276
self,
268277
def_id: DefId,

compiler/rustc_type_ir/src/interner.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ pub trait Interner:
176176

177177
fn alias_term_kind(self, alias: ty::AliasTerm<Self>) -> ty::AliasTermKind;
178178

179+
fn own_args_for_alias(
180+
self,
181+
def_id: Self::DefId,
182+
args: Self::GenericArgs,
183+
) -> Self::GenericArgsSlice;
184+
179185
fn trait_ref_and_own_args_for_alias(
180186
self,
181187
def_id: Self::DefId,

compiler/rustc_type_ir/src/predicate.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -664,14 +664,6 @@ impl<I: Interner> AliasTerm<I> {
664664
interner.parent(self.def_id)
665665
}
666666

667-
/// Extracts the underlying trait reference and own args from this projection.
668-
/// For example, if this is a projection of `<T as StreamingIterator>::Item<'a>`,
669-
/// then this function would return a `T: StreamingIterator` trait reference and
670-
/// `['a]` as the own args.
671-
pub fn trait_ref_and_own_args(self, interner: I) -> (TraitRef<I>, I::GenericArgsSlice) {
672-
interner.trait_ref_and_own_args_for_alias(self.def_id, self.args)
673-
}
674-
675667
/// Extracts the underlying trait reference from this projection.
676668
/// For example, if this is a projection of `<T as Iterator>::Item`,
677669
/// then this function would return a `T: Iterator` trait reference.
@@ -687,7 +679,15 @@ impl<I: Interner> AliasTerm<I> {
687679
/// For example, if this is a projection of `<T as StreamingIterator>::Item<'a>`,
688680
/// then this function would return the slice `['a]` as the own args.
689681
pub fn own_args(self, interner: I) -> I::GenericArgsSlice {
690-
self.trait_ref_and_own_args(interner).1
682+
interner.own_args_for_alias(self.def_id, self.args)
683+
}
684+
685+
/// Extracts the underlying trait reference and own args from this projection.
686+
/// For example, if this is a projection of `<T as StreamingIterator>::Item<'a>`,
687+
/// then this function would return a `T: StreamingIterator` trait reference and
688+
/// `['a]` as the own args.
689+
pub fn trait_ref_and_own_args(self, interner: I) -> (TraitRef<I>, I::GenericArgsSlice) {
690+
interner.trait_ref_and_own_args_for_alias(self.def_id, self.args)
691691
}
692692
}
693693

0 commit comments

Comments
 (0)