Skip to content

Commit 90b07e5

Browse files
committed
Review: move create_generic_arg_path to LoweringContext
1 parent d6c4723 commit 90b07e5

2 files changed

Lines changed: 35 additions & 40 deletions

File tree

compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ use rustc_span::def_id::{DefId, LocalDefId};
5555
use rustc_span::symbol::kw;
5656
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol};
5757

58-
use crate::delegation::generics::{
59-
DelegationGenericArgsIterator, GenericsGenerationResult, GenericsGenerationResults,
60-
};
58+
use crate::delegation::generics::{GenericsGenerationResult, GenericsGenerationResults};
6159
use crate::diagnostics::{
6260
CycleInDelegationSignatureResolution, DelegationAttemptedBlockWithDefsDeletion,
6361
DelegationBlockSpecifiedWhenNoParams, UnresolvedDelegationCallee,
@@ -631,12 +629,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
631629
// free-to-trait reuses.
632630
let ty = match generics.self_ty_propagation_kind {
633631
Some(hir::DelegationSelfTyPropagationKind::SelfParam) => {
634-
let kind = hir::TyKind::Path(
635-
DelegationGenericArgsIterator::create_generic_arg_path(
636-
self,
637-
generics.parent.generics.find_self_param(),
638-
),
639-
);
632+
let self_param = generics.parent.generics.find_self_param();
633+
let path = self.create_generic_arg_path(self_param);
634+
let kind = hir::TyKind::Path(path);
640635

641636
let ty = match ty {
642637
Some(ty) => hir::Ty { kind, ..ty.clone() },

compiler/rustc_ast_lowering/src/delegation/generics.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ impl<'hir> DelegationGenericArgsIterator<'hir> {
127127
hir::GenericParamKind::Type { .. } => hir::GenericArg::Type(ctx.arena.alloc(hir::Ty {
128128
hir_id,
129129
span: p.span,
130-
kind: hir::TyKind::Path(Self::create_generic_arg_path(ctx, &p)),
130+
kind: hir::TyKind::Path(ctx.create_generic_arg_path(&p)),
131131
})),
132132
hir::GenericParamKind::Const { .. } => {
133133
hir::GenericArg::Const(ctx.arena.alloc(hir::ConstArg {
134134
hir_id,
135-
kind: hir::ConstArgKind::Path(Self::create_generic_arg_path(ctx, &p)),
135+
kind: hir::ConstArgKind::Path(ctx.create_generic_arg_path(&p)),
136136
span: p.span,
137137
}))
138138
}
@@ -150,35 +150,6 @@ impl<'hir> DelegationGenericArgsIterator<'hir> {
150150

151151
args
152152
}
153-
154-
pub(super) fn create_generic_arg_path(
155-
ctx: &mut LoweringContext<'_, 'hir>,
156-
p: &hir::GenericParam<'hir>,
157-
) -> hir::QPath<'hir> {
158-
let res = Res::Def(
159-
match p.kind {
160-
hir::GenericParamKind::Lifetime { .. } => DefKind::LifetimeParam,
161-
hir::GenericParamKind::Type { .. } => DefKind::TyParam,
162-
hir::GenericParamKind::Const { .. } => DefKind::ConstParam,
163-
},
164-
p.def_id.to_def_id(),
165-
);
166-
167-
hir::QPath::Resolved(
168-
None,
169-
ctx.arena.alloc(hir::Path {
170-
segments: ctx.arena.alloc_slice(&[hir::PathSegment {
171-
args: None,
172-
hir_id: ctx.next_id(),
173-
ident: p.name.ident(),
174-
infer_args: false,
175-
res,
176-
}]),
177-
res,
178-
span: p.span,
179-
}),
180-
)
181-
}
182153
}
183154

184155
impl<'hir> HirOrTyGenerics<'hir> {
@@ -596,4 +567,33 @@ impl<'hir> LoweringContext<'_, 'hir> {
596567
)),
597568
}
598569
}
570+
571+
pub(super) fn create_generic_arg_path(
572+
&mut self,
573+
p: &hir::GenericParam<'hir>,
574+
) -> hir::QPath<'hir> {
575+
let res = Res::Def(
576+
match p.kind {
577+
hir::GenericParamKind::Lifetime { .. } => DefKind::LifetimeParam,
578+
hir::GenericParamKind::Type { .. } => DefKind::TyParam,
579+
hir::GenericParamKind::Const { .. } => DefKind::ConstParam,
580+
},
581+
p.def_id.to_def_id(),
582+
);
583+
584+
hir::QPath::Resolved(
585+
None,
586+
self.arena.alloc(hir::Path {
587+
segments: self.arena.alloc_slice(&[hir::PathSegment {
588+
args: None,
589+
hir_id: self.next_id(),
590+
ident: p.name.ident(),
591+
infer_args: false,
592+
res,
593+
}]),
594+
res,
595+
span: p.span,
596+
}),
597+
)
598+
}
599599
}

0 commit comments

Comments
 (0)