Skip to content

Commit 47a9602

Browse files
committed
Pass Ident by reference
1 parent ba06226 commit 47a9602

File tree

10 files changed

+59
-53
lines changed

10 files changed

+59
-53
lines changed

compiler/rustc_ast/src/visitors.rs

+29-30
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ macro_rules! make_ast_visitor {
298298
make_visit!{Variant; visit_variant, walk_variant}
299299
make_visit!{VariantData; visit_variant_data, walk_struct_def}
300300

301-
fn visit_ident(&mut self, _ident: Ident) -> Self::Result {
301+
fn visit_ident(&mut self, _ident: &'ast Ident) -> Self::Result {
302302
Self::Result::output()
303303
}
304304
/// This method is a hack to workaround unstable of `stmt_expr_attributes`.
@@ -427,7 +427,7 @@ pub mod visit {
427427
#[derive(Copy, Clone, Debug)]
428428
pub enum FnKind<'a> {
429429
/// E.g., `fn foo()`, `fn foo(&self)`, or `extern "Abi" fn foo()`.
430-
Fn(FnCtxt, Ident, &'a FnSig, &'a Visibility, &'a Generics, Option<&'a Block>),
430+
Fn(FnCtxt, &'a Ident, &'a FnSig, &'a Visibility, &'a Generics, Option<&'a Block>),
431431

432432
/// E.g., `|x, y| body`.
433433
Closure(&'a ClosureBinder, &'a Option<CoroutineKind>, &'a FnDecl, &'a Expr),
@@ -507,12 +507,12 @@ pub mod visit {
507507
visitor: &mut V,
508508
Label { ident }: &'a Label,
509509
) -> V::Result {
510-
visitor.visit_ident(*ident)
510+
visitor.visit_ident(ident)
511511
}
512512

513513
pub fn walk_lifetime<'a, V: Visitor<'a>>(visitor: &mut V, lifetime: &'a Lifetime) -> V::Result {
514514
let Lifetime { id: _, ident } = lifetime;
515-
visitor.visit_ident(*ident)
515+
visitor.visit_ident(ident)
516516
}
517517

518518
pub fn walk_poly_trait_ref<'a, V>(visitor: &mut V, trait_ref: &'a PolyTraitRef) -> V::Result
@@ -553,8 +553,7 @@ pub mod visit {
553553
visit_opt!(visitor, visit_expr, expr);
554554
}
555555
ItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
556-
let kind =
557-
FnKind::Fn(FnCtxt::Free, *ident, sig, vis, generics, body.as_deref());
556+
let kind = FnKind::Fn(FnCtxt::Free, ident, sig, vis, generics, body.as_deref());
558557
try_visit!(visitor.visit_fn(kind, *span, *id));
559558
}
560559
ItemKind::Mod(_unsafety, mod_kind) => match mod_kind {
@@ -623,17 +622,17 @@ pub mod visit {
623622
}) => {
624623
try_visit!(visitor.visit_qself(qself));
625624
try_visit!(visitor.visit_path(path, *id));
626-
visit_opt!(visitor, visit_ident, *rename);
625+
visit_opt!(visitor, visit_ident, rename);
627626
visit_opt!(visitor, visit_block, body);
628627
}
629628
ItemKind::DelegationMac(box DelegationMac { qself, prefix, suffixes, body }) => {
630629
try_visit!(visitor.visit_qself(qself));
631630
try_visit!(visitor.visit_path(prefix, *id));
632631
if let Some(suffixes) = suffixes {
633632
for (ident, rename) in suffixes {
634-
visitor.visit_ident(*ident);
633+
visitor.visit_ident(ident);
635634
if let Some(rename) = rename {
636-
visitor.visit_ident(*rename);
635+
visitor.visit_ident(rename);
637636
}
638637
}
639638
}
@@ -667,7 +666,7 @@ pub mod visit {
667666
variant;
668667
walk_list!(visitor, visit_attribute, attrs);
669668
try_visit!(visitor.visit_vis(vis));
670-
try_visit!(visitor.visit_ident(*ident));
669+
try_visit!(visitor.visit_ident(ident));
671670
try_visit!(visitor.visit_variant_data(data));
672671
visit_opt!(visitor, visit_variant_discr, disr_expr);
673672
V::Result::output()
@@ -677,15 +676,15 @@ pub mod visit {
677676
let ExprField { attrs, id: _, span: _, ident, expr, is_shorthand: _, is_placeholder: _ } =
678677
f;
679678
walk_list!(visitor, visit_attribute, attrs);
680-
try_visit!(visitor.visit_ident(*ident));
679+
try_visit!(visitor.visit_ident(ident));
681680
try_visit!(visitor.visit_expr(expr));
682681
V::Result::output()
683682
}
684683

685684
pub fn walk_pat_field<'a, V: Visitor<'a>>(visitor: &mut V, fp: &'a PatField) -> V::Result {
686685
let PatField { ident, pat, is_shorthand: _, attrs, id: _, span: _, is_placeholder: _ } = fp;
687686
walk_list!(visitor, visit_attribute, attrs);
688-
try_visit!(visitor.visit_ident(*ident));
687+
try_visit!(visitor.visit_ident(ident));
689688
try_visit!(visitor.visit_pat(pat));
690689
V::Result::output()
691690
}
@@ -759,7 +758,7 @@ pub mod visit {
759758
match kind {
760759
UseTreeKind::Simple(rename) => {
761760
// The extra IDs are handled during AST lowering.
762-
visit_opt!(visitor, visit_ident, *rename);
761+
visit_opt!(visitor, visit_ident, rename);
763762
}
764763
UseTreeKind::Glob => {}
765764
UseTreeKind::Nested { ref items, span: _ } => {
@@ -776,7 +775,7 @@ pub mod visit {
776775
segment: &'a PathSegment,
777776
) -> V::Result {
778777
let PathSegment { ident, id: _, args } = segment;
779-
try_visit!(visitor.visit_ident(*ident));
778+
try_visit!(visitor.visit_ident(ident));
780779
visit_opt!(visitor, visit_generic_args, args);
781780
V::Result::output()
782781
}
@@ -822,7 +821,7 @@ pub mod visit {
822821
constraint: &'a AssocItemConstraint,
823822
) -> V::Result {
824823
let AssocItemConstraint { id: _, ident, gen_args, kind, span: _ } = constraint;
825-
try_visit!(visitor.visit_ident(*ident));
824+
try_visit!(visitor.visit_ident(ident));
826825
visit_opt!(visitor, visit_generic_args, gen_args);
827826
match kind {
828827
AssocItemConstraintKind::Equality { term } => match term {
@@ -860,7 +859,7 @@ pub mod visit {
860859
try_visit!(visitor.visit_pat(subpattern));
861860
}
862861
PatKind::Ident(_bmode, ident, optional_subpattern) => {
863-
try_visit!(visitor.visit_ident(*ident));
862+
try_visit!(visitor.visit_ident(ident));
864863
visit_opt!(visitor, visit_pat, optional_subpattern);
865864
}
866865
PatKind::Lit(expression) => try_visit!(visitor.visit_expr(expression)),
@@ -885,7 +884,7 @@ pub mod visit {
885884
_ctxt: AssocCtxt,
886885
visitor: &mut V,
887886
) -> V::Result {
888-
let &Item { id, span, ident, ref vis, .. } = item;
887+
let Item { id, span, ident, vis, .. } = item;
889888
match self {
890889
ForeignItemKind::Static(box StaticItem { ty, mutability: _, expr, safety: _ }) => {
891890
try_visit!(visitor.visit_ty(ty));
@@ -894,7 +893,7 @@ pub mod visit {
894893
ForeignItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
895894
let kind =
896895
FnKind::Fn(FnCtxt::Foreign, ident, sig, vis, generics, body.as_deref());
897-
try_visit!(visitor.visit_fn(kind, span, id));
896+
try_visit!(visitor.visit_fn(kind, *span, *id));
898897
}
899898
ForeignItemKind::TyAlias(box TyAlias {
900899
generics,
@@ -952,7 +951,7 @@ pub mod visit {
952951
let GenericParam { id: _, ident, attrs, bounds, is_placeholder: _, kind, colon_span: _ } =
953952
param;
954953
walk_list!(visitor, visit_attribute, attrs);
955-
try_visit!(visitor.visit_ident(*ident));
954+
try_visit!(visitor.visit_ident(ident));
956955
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
957956
match kind {
958957
GenericParamKind::Lifetime => (),
@@ -1054,7 +1053,7 @@ pub mod visit {
10541053
ctxt: AssocCtxt,
10551054
visitor: &mut V,
10561055
) -> V::Result {
1057-
let &Item { id, span, ident, ref vis, .. } = item;
1056+
let Item { id, span, ident, vis, .. } = item;
10581057
match self {
10591058
AssocItemKind::Const(box ConstItem { defaultness: _, generics, ty, expr }) => {
10601059
try_visit!(visitor.visit_generics(generics));
@@ -1064,7 +1063,7 @@ pub mod visit {
10641063
AssocItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
10651064
let kind =
10661065
FnKind::Fn(FnCtxt::Assoc(ctxt), ident, sig, vis, generics, body.as_deref());
1067-
try_visit!(visitor.visit_fn(kind, span, id));
1066+
try_visit!(visitor.visit_fn(kind, *span, *id));
10681067
}
10691068
AssocItemKind::Type(box TyAlias {
10701069
generics,
@@ -1090,7 +1089,7 @@ pub mod visit {
10901089
}) => {
10911090
try_visit!(visitor.visit_qself(qself));
10921091
try_visit!(visitor.visit_path(path, *id));
1093-
visit_opt!(visitor, visit_ident, *rename);
1092+
visit_opt!(visitor, visit_ident, rename);
10941093
visit_opt!(visitor, visit_block, body);
10951094
}
10961095
AssocItemKind::DelegationMac(box DelegationMac {
@@ -1100,12 +1099,12 @@ pub mod visit {
11001099
body,
11011100
}) => {
11021101
try_visit!(visitor.visit_qself(qself));
1103-
try_visit!(visitor.visit_path(prefix, id));
1102+
try_visit!(visitor.visit_path(prefix, *id));
11041103
if let Some(suffixes) = suffixes {
11051104
for (ident, rename) in suffixes {
1106-
visitor.visit_ident(*ident);
1105+
visitor.visit_ident(ident);
11071106
if let Some(rename) = rename {
1108-
visitor.visit_ident(*rename);
1107+
visitor.visit_ident(rename);
11091108
}
11101109
}
11111110
}
@@ -1121,7 +1120,7 @@ pub mod visit {
11211120
item: &'a Item<impl WalkItemKind>,
11221121
ctxt: AssocCtxt,
11231122
) -> V::Result {
1124-
let &Item { id: _, span: _, ident, ref vis, ref attrs, ref kind, tokens: _ } = item;
1123+
let Item { id: _, span: _, ident, vis, attrs, kind, tokens: _ } = item;
11251124
walk_list!(visitor, visit_attribute, attrs);
11261125
try_visit!(visitor.visit_vis(vis));
11271126
try_visit!(visitor.visit_ident(ident));
@@ -1141,7 +1140,7 @@ pub mod visit {
11411140
let FieldDef { attrs, id: _, span: _, vis, ident, ty, is_placeholder: _ } = field;
11421141
walk_list!(visitor, visit_attribute, attrs);
11431142
try_visit!(visitor.visit_vis(vis));
1144-
visit_opt!(visitor, visit_ident, *ident);
1143+
visit_opt!(visitor, visit_ident, ident);
11451144
try_visit!(visitor.visit_ty(ty));
11461145
V::Result::output()
11471146
}
@@ -1226,7 +1225,7 @@ pub mod visit {
12261225
for FormatArgument { kind, expr } in arguments.all_args() {
12271226
match kind {
12281227
FormatArgumentKind::Named(ident) | FormatArgumentKind::Captured(ident) => {
1229-
try_visit!(visitor.visit_ident(*ident))
1228+
try_visit!(visitor.visit_ident(ident))
12301229
}
12311230
FormatArgumentKind::Normal => {}
12321231
}
@@ -1346,7 +1345,7 @@ pub mod visit {
13461345
}
13471346
ExprKind::Field(subexpression, ident) => {
13481347
try_visit!(visitor.visit_expr(subexpression));
1349-
try_visit!(visitor.visit_ident(*ident));
1348+
try_visit!(visitor.visit_ident(ident));
13501349
}
13511350
ExprKind::Index(main_expression, index_expression, _span) => {
13521351
try_visit!(visitor.visit_expr(main_expression));
@@ -1381,7 +1380,7 @@ pub mod visit {
13811380
ExprKind::FormatArgs(f) => try_visit!(visitor.visit_format_args(f)),
13821381
ExprKind::OffsetOf(container, fields) => {
13831382
try_visit!(visitor.visit_ty(container));
1384-
walk_list!(visitor, visit_ident, fields.iter().copied());
1383+
walk_list!(visitor, visit_ident, fields.iter());
13851384
}
13861385
ExprKind::Yield(optional_expression) => {
13871386
visit_opt!(visitor, visit_expr, optional_expression);

compiler/rustc_ast_passes/src/ast_validation.rs

+17-11
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl<'a> AstValidator<'a> {
249249
}
250250

251251
fn visit_struct_field_def(&mut self, field: &'a FieldDef) {
252-
if let Some(ident) = field.ident
252+
if let Some(ref ident) = field.ident
253253
&& ident.name == kw::Underscore
254254
{
255255
self.visit_vis(&field.vis);
@@ -896,7 +896,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
896896
}
897897

898898
this.visit_vis(&item.vis);
899-
this.visit_ident(item.ident);
899+
this.visit_ident(&item.ident);
900900
let disallowed = matches!(constness, Const::No)
901901
.then(|| TildeConstReason::TraitImpl { span: item.span });
902902
this.with_tilde_const(disallowed, |this| this.visit_generics(generics));
@@ -950,7 +950,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
950950
}
951951

952952
this.visit_vis(&item.vis);
953-
this.visit_ident(item.ident);
953+
this.visit_ident(&item.ident);
954954
this.with_tilde_const(
955955
Some(TildeConstReason::Impl { span: item.span }),
956956
|this| this.visit_generics(generics),
@@ -988,9 +988,15 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
988988
}
989989

990990
self.visit_vis(&item.vis);
991-
self.visit_ident(item.ident);
992-
let kind =
993-
FnKind::Fn(FnCtxt::Free, item.ident, sig, &item.vis, generics, body.as_deref());
991+
self.visit_ident(&item.ident);
992+
let kind = FnKind::Fn(
993+
FnCtxt::Free,
994+
&item.ident,
995+
sig,
996+
&item.vis,
997+
generics,
998+
body.as_deref(),
999+
);
9941000
self.visit_fn(kind, item.span, item.id);
9951001
walk_list!(self, visit_attribute, &item.attrs);
9961002
return; // Avoid visiting again.
@@ -1055,7 +1061,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10551061
// Equivalent of `visit::walk_item` for `ItemKind::Trait` that inserts a bound
10561062
// context for the supertraits.
10571063
this.visit_vis(&item.vis);
1058-
this.visit_ident(item.ident);
1064+
this.visit_ident(&item.ident);
10591065
let disallowed = is_const_trait
10601066
.is_none()
10611067
.then(|| TildeConstReason::Trait { span: item.span });
@@ -1082,7 +1088,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10821088
ItemKind::Struct(vdata, generics) => match vdata {
10831089
VariantData::Struct { fields, .. } => {
10841090
self.visit_vis(&item.vis);
1085-
self.visit_ident(item.ident);
1091+
self.visit_ident(&item.ident);
10861092
self.visit_generics(generics);
10871093
// Permit `Anon{Struct,Union}` as field type.
10881094
walk_list!(self, visit_struct_field_def, fields);
@@ -1098,7 +1104,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10981104
match vdata {
10991105
VariantData::Struct { fields, .. } => {
11001106
self.visit_vis(&item.vis);
1101-
self.visit_ident(item.ident);
1107+
self.visit_ident(&item.ident);
11021108
self.visit_generics(generics);
11031109
// Permit `Anon{Struct,Union}` as field type.
11041110
walk_list!(self, visit_struct_field_def, fields);
@@ -1518,10 +1524,10 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
15181524
|| matches!(sig.header.constness, Const::Yes(_)) =>
15191525
{
15201526
self.visit_vis(&item.vis);
1521-
self.visit_ident(item.ident);
1527+
self.visit_ident(&item.ident);
15221528
let kind = FnKind::Fn(
15231529
FnCtxt::Assoc(ctxt),
1524-
item.ident,
1530+
&item.ident,
15251531
sig,
15261532
&item.vis,
15271533
generics,

compiler/rustc_ast_passes/src/node_count.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl NodeCounter {
1616
}
1717

1818
impl<'ast> Visitor<'ast> for NodeCounter {
19-
fn visit_ident(&mut self, _ident: Ident) {
19+
fn visit_ident(&mut self, _ident: &Ident) {
2020
self.count += 1;
2121
}
2222
fn visit_foreign_item(&mut self, i: &ForeignItem) {

compiler/rustc_builtin_macros/src/deriving/default.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl<'a, 'b> rustc_ast::visit::Visitor<'a> for DetectNonVariantDefaultAttr<'a, '
222222
rustc_ast::visit::walk_attribute(self, attr);
223223
}
224224
fn visit_variant(&mut self, v: &'a rustc_ast::Variant) {
225-
self.visit_ident(v.ident);
225+
self.visit_ident(&v.ident);
226226
self.visit_vis(&v.vis);
227227
self.visit_variant_data(&v.data);
228228
visit_opt!(self, visit_anon_const, &v.disr_expr);

compiler/rustc_lint/src/early.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,9 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
190190
ast_visit::walk_ty(self, t);
191191
}
192192

193-
fn visit_ident(&mut self, ident: Ident) {
194-
lint_callback!(self, check_ident, ident);
193+
fn visit_ident(&mut self, ident: &Ident) {
194+
// FIXME: Change check_ident so it receives a reference
195+
lint_callback!(self, check_ident, *ident);
195196
}
196197

197198
fn visit_local(&mut self, l: &'a ast::Local) {

compiler/rustc_resolve/src/build_reduced_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ impl<'a, 'ra, 'tcx> Visitor<'a> for BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
13171317
// Visit attributes after items for backward compatibility.
13181318
// This way they can use `macro_rules` defined later.
13191319
self.visit_vis(&item.vis);
1320-
self.visit_ident(item.ident);
1320+
self.visit_ident(&item.ident);
13211321
item.kind.walk(item, AssocCtxt::Trait, self);
13221322
visit::walk_list!(self, visit_attribute, &item.attrs);
13231323
}

compiler/rustc_resolve/src/late.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r
12051205
}
12061206

12071207
fn visit_assoc_item_constraint(&mut self, constraint: &'ast AssocItemConstraint) {
1208-
self.visit_ident(constraint.ident);
1208+
self.visit_ident(&constraint.ident);
12091209
if let Some(ref gen_args) = constraint.gen_args {
12101210
// Forbid anonymous lifetimes in GAT parameters until proper semantics are decided.
12111211
self.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
@@ -4581,7 +4581,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
45814581

45824582
fn resolve_expr_field(&mut self, f: &'ast ExprField, e: &'ast Expr) {
45834583
self.resolve_expr(&f.expr, Some(e));
4584-
self.visit_ident(f.ident);
4584+
self.visit_ident(&f.ident);
45854585
walk_list!(self, visit_attribute, f.attrs.iter());
45864586
}
45874587

src/tools/clippy/clippy_utils/src/ast_utils/ident_iter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl From<&Attribute> for IdentIter {
3939
struct IdentCollector(Vec<Ident>);
4040

4141
impl Visitor<'_> for IdentCollector {
42-
fn visit_ident(&mut self, ident: Ident) {
43-
self.0.push(ident);
42+
fn visit_ident(&mut self, ident: &Ident) {
43+
self.0.push(*ident);
4444
}
4545
}

0 commit comments

Comments
 (0)