Skip to content

Commit a4d54cd

Browse files
committed
Auto merge of #132106 - maxcabrajac:ident_ref, r=<try>
Pass Ident by reference in ast Visitor `MutVisitor`'s version of `visit_ident` passes around `&Ident`, but `Visitor` copies `Ident`. This PR changes that r? `@petrochenkov`
2 parents 5ae4d75 + 64a3451 commit a4d54cd

File tree

10 files changed

+41
-41
lines changed

10 files changed

+41
-41
lines changed

compiler/rustc_ast/src/visit.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub trait Visitor<'ast>: Sized {
135135
/// or `ControlFlow<T>`.
136136
type Result: VisitorResult = ();
137137

138-
fn visit_ident(&mut self, _ident: Ident) -> Self::Result {
138+
fn visit_ident(&mut self, _ident: &'ast Ident) -> Self::Result {
139139
Self::Result::output()
140140
}
141141
fn visit_foreign_item(&mut self, i: &'ast ForeignItem) -> Self::Result {
@@ -317,12 +317,12 @@ pub fn walk_local<'a, V: Visitor<'a>>(visitor: &mut V, local: &'a Local) -> V::R
317317
}
318318

319319
pub fn walk_label<'a, V: Visitor<'a>>(visitor: &mut V, Label { ident }: &'a Label) -> V::Result {
320-
visitor.visit_ident(*ident)
320+
visitor.visit_ident(ident)
321321
}
322322

323323
pub fn walk_lifetime<'a, V: Visitor<'a>>(visitor: &mut V, lifetime: &'a Lifetime) -> V::Result {
324324
let Lifetime { id: _, ident } = lifetime;
325-
visitor.visit_ident(*ident)
325+
visitor.visit_ident(ident)
326326
}
327327

328328
pub fn walk_poly_trait_ref<'a, V>(visitor: &mut V, trait_ref: &'a PolyTraitRef) -> V::Result
@@ -429,17 +429,17 @@ impl WalkItemKind for ItemKind {
429429
}) => {
430430
try_visit!(walk_qself(visitor, qself));
431431
try_visit!(visitor.visit_path(path, *id));
432-
visit_opt!(visitor, visit_ident, *rename);
432+
visit_opt!(visitor, visit_ident, rename);
433433
visit_opt!(visitor, visit_block, body);
434434
}
435435
ItemKind::DelegationMac(box DelegationMac { qself, prefix, suffixes, body }) => {
436436
try_visit!(walk_qself(visitor, qself));
437437
try_visit!(visitor.visit_path(prefix, *id));
438438
if let Some(suffixes) = suffixes {
439439
for (ident, rename) in suffixes {
440-
visitor.visit_ident(*ident);
440+
visitor.visit_ident(ident);
441441
if let Some(rename) = rename {
442-
visitor.visit_ident(*rename);
442+
visitor.visit_ident(rename);
443443
}
444444
}
445445
}
@@ -472,7 +472,7 @@ where
472472
let Variant { attrs, id: _, span: _, vis, ident, data, disr_expr, is_placeholder: _ } = variant;
473473
walk_list!(visitor, visit_attribute, attrs);
474474
try_visit!(visitor.visit_vis(vis));
475-
try_visit!(visitor.visit_ident(*ident));
475+
try_visit!(visitor.visit_ident(ident));
476476
try_visit!(visitor.visit_variant_data(data));
477477
visit_opt!(visitor, visit_variant_discr, disr_expr);
478478
V::Result::output()
@@ -481,15 +481,15 @@ where
481481
pub fn walk_expr_field<'a, V: Visitor<'a>>(visitor: &mut V, f: &'a ExprField) -> V::Result {
482482
let ExprField { attrs, id: _, span: _, ident, expr, is_shorthand: _, is_placeholder: _ } = f;
483483
walk_list!(visitor, visit_attribute, attrs);
484-
try_visit!(visitor.visit_ident(*ident));
484+
try_visit!(visitor.visit_ident(ident));
485485
try_visit!(visitor.visit_expr(expr));
486486
V::Result::output()
487487
}
488488

489489
pub fn walk_pat_field<'a, V: Visitor<'a>>(visitor: &mut V, fp: &'a PatField) -> V::Result {
490490
let PatField { ident, pat, is_shorthand: _, attrs, id: _, span: _, is_placeholder: _ } = fp;
491491
walk_list!(visitor, visit_attribute, attrs);
492-
try_visit!(visitor.visit_ident(*ident));
492+
try_visit!(visitor.visit_ident(ident));
493493
try_visit!(visitor.visit_pat(pat));
494494
V::Result::output()
495495
}
@@ -564,7 +564,7 @@ pub fn walk_use_tree<'a, V: Visitor<'a>>(
564564
match kind {
565565
UseTreeKind::Simple(rename) => {
566566
// The extra IDs are handled during AST lowering.
567-
visit_opt!(visitor, visit_ident, *rename);
567+
visit_opt!(visitor, visit_ident, rename);
568568
}
569569
UseTreeKind::Glob => {}
570570
UseTreeKind::Nested { ref items, span: _ } => {
@@ -581,7 +581,7 @@ pub fn walk_path_segment<'a, V: Visitor<'a>>(
581581
segment: &'a PathSegment,
582582
) -> V::Result {
583583
let PathSegment { ident, id: _, args } = segment;
584-
try_visit!(visitor.visit_ident(*ident));
584+
try_visit!(visitor.visit_ident(ident));
585585
visit_opt!(visitor, visit_generic_args, args);
586586
V::Result::output()
587587
}
@@ -627,7 +627,7 @@ pub fn walk_assoc_item_constraint<'a, V: Visitor<'a>>(
627627
constraint: &'a AssocItemConstraint,
628628
) -> V::Result {
629629
let AssocItemConstraint { id: _, ident, gen_args, kind, span: _ } = constraint;
630-
try_visit!(visitor.visit_ident(*ident));
630+
try_visit!(visitor.visit_ident(ident));
631631
visit_opt!(visitor, visit_generic_args, gen_args);
632632
match kind {
633633
AssocItemConstraintKind::Equality { term } => match term {
@@ -665,7 +665,7 @@ pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) -> V::Res
665665
try_visit!(visitor.visit_pat(subpattern));
666666
}
667667
PatKind::Ident(_bmode, ident, optional_subpattern) => {
668-
try_visit!(visitor.visit_ident(*ident));
668+
try_visit!(visitor.visit_ident(ident));
669669
visit_opt!(visitor, visit_pat, optional_subpattern);
670670
}
671671
PatKind::Lit(expression) => try_visit!(visitor.visit_expr(expression)),
@@ -751,7 +751,7 @@ pub fn walk_generic_param<'a, V: Visitor<'a>>(
751751
let GenericParam { id: _, ident, attrs, bounds, is_placeholder: _, kind, colon_span: _ } =
752752
param;
753753
walk_list!(visitor, visit_attribute, attrs);
754-
try_visit!(visitor.visit_ident(*ident));
754+
try_visit!(visitor.visit_ident(ident));
755755
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
756756
match kind {
757757
GenericParamKind::Lifetime => (),
@@ -889,17 +889,17 @@ impl WalkItemKind for AssocItemKind {
889889
}) => {
890890
try_visit!(walk_qself(visitor, qself));
891891
try_visit!(visitor.visit_path(path, *id));
892-
visit_opt!(visitor, visit_ident, *rename);
892+
visit_opt!(visitor, visit_ident, rename);
893893
visit_opt!(visitor, visit_block, body);
894894
}
895895
AssocItemKind::DelegationMac(box DelegationMac { qself, prefix, suffixes, body }) => {
896896
try_visit!(walk_qself(visitor, qself));
897897
try_visit!(visitor.visit_path(prefix, id));
898898
if let Some(suffixes) = suffixes {
899899
for (ident, rename) in suffixes {
900-
visitor.visit_ident(*ident);
900+
visitor.visit_ident(ident);
901901
if let Some(rename) = rename {
902-
visitor.visit_ident(*rename);
902+
visitor.visit_ident(rename);
903903
}
904904
}
905905
}
@@ -915,7 +915,7 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(
915915
item: &'a Item<impl WalkItemKind>,
916916
ctxt: AssocCtxt,
917917
) -> V::Result {
918-
let &Item { id: _, span: _, ident, ref vis, ref attrs, ref kind, tokens: _ } = item;
918+
let Item { id: _, span: _, ident, vis, attrs, kind, tokens: _ } = item;
919919
walk_list!(visitor, visit_attribute, attrs);
920920
try_visit!(visitor.visit_vis(vis));
921921
try_visit!(visitor.visit_ident(ident));
@@ -935,7 +935,7 @@ pub fn walk_field_def<'a, V: Visitor<'a>>(visitor: &mut V, field: &'a FieldDef)
935935
let FieldDef { attrs, id: _, span: _, vis, ident, ty, is_placeholder: _ } = field;
936936
walk_list!(visitor, visit_attribute, attrs);
937937
try_visit!(visitor.visit_vis(vis));
938-
visit_opt!(visitor, visit_ident, *ident);
938+
visit_opt!(visitor, visit_ident, ident);
939939
try_visit!(visitor.visit_ty(ty));
940940
V::Result::output()
941941
}
@@ -1017,7 +1017,7 @@ pub fn walk_format_args<'a, V: Visitor<'a>>(visitor: &mut V, fmt: &'a FormatArgs
10171017
for FormatArgument { kind, expr } in arguments.all_args() {
10181018
match kind {
10191019
FormatArgumentKind::Named(ident) | FormatArgumentKind::Captured(ident) => {
1020-
try_visit!(visitor.visit_ident(*ident))
1020+
try_visit!(visitor.visit_ident(ident))
10211021
}
10221022
FormatArgumentKind::Normal => {}
10231023
}
@@ -1137,7 +1137,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V
11371137
}
11381138
ExprKind::Field(subexpression, ident) => {
11391139
try_visit!(visitor.visit_expr(subexpression));
1140-
try_visit!(visitor.visit_ident(*ident));
1140+
try_visit!(visitor.visit_ident(ident));
11411141
}
11421142
ExprKind::Index(main_expression, index_expression, _span) => {
11431143
try_visit!(visitor.visit_expr(main_expression));
@@ -1172,7 +1172,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V
11721172
ExprKind::FormatArgs(f) => try_visit!(visitor.visit_format_args(f)),
11731173
ExprKind::OffsetOf(container, fields) => {
11741174
try_visit!(visitor.visit_ty(container));
1175-
walk_list!(visitor, visit_ident, fields.iter().copied());
1175+
walk_list!(visitor, visit_ident, fields.iter());
11761176
}
11771177
ExprKind::Yield(optional_expression) => {
11781178
visit_opt!(visitor, visit_expr, optional_expression);

compiler/rustc_ast_passes/src/ast_validation.rs

+8-8
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);
@@ -899,7 +899,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
899899
}
900900

901901
this.visit_vis(&item.vis);
902-
this.visit_ident(item.ident);
902+
this.visit_ident(&item.ident);
903903
let disallowed = matches!(constness, Const::No)
904904
.then(|| TildeConstReason::TraitImpl { span: item.span });
905905
this.with_tilde_const(disallowed, |this| this.visit_generics(generics));
@@ -953,7 +953,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
953953
}
954954

955955
this.visit_vis(&item.vis);
956-
this.visit_ident(item.ident);
956+
this.visit_ident(&item.ident);
957957
this.with_tilde_const(
958958
Some(TildeConstReason::Impl { span: item.span }),
959959
|this| this.visit_generics(generics),
@@ -991,7 +991,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
991991
}
992992

993993
self.visit_vis(&item.vis);
994-
self.visit_ident(item.ident);
994+
self.visit_ident(&item.ident);
995995
let kind =
996996
FnKind::Fn(FnCtxt::Free, item.ident, sig, &item.vis, generics, body.as_deref());
997997
self.visit_fn(kind, item.span, item.id);
@@ -1058,7 +1058,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10581058
// Equivalent of `visit::walk_item` for `ItemKind::Trait` that inserts a bound
10591059
// context for the supertraits.
10601060
this.visit_vis(&item.vis);
1061-
this.visit_ident(item.ident);
1061+
this.visit_ident(&item.ident);
10621062
let disallowed = is_const_trait
10631063
.is_none()
10641064
.then(|| TildeConstReason::Trait { span: item.span });
@@ -1085,7 +1085,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10851085
ItemKind::Struct(vdata, generics) => match vdata {
10861086
VariantData::Struct { fields, .. } => {
10871087
self.visit_vis(&item.vis);
1088-
self.visit_ident(item.ident);
1088+
self.visit_ident(&item.ident);
10891089
self.visit_generics(generics);
10901090
// Permit `Anon{Struct,Union}` as field type.
10911091
walk_list!(self, visit_struct_field_def, fields);
@@ -1101,7 +1101,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11011101
match vdata {
11021102
VariantData::Struct { fields, .. } => {
11031103
self.visit_vis(&item.vis);
1104-
self.visit_ident(item.ident);
1104+
self.visit_ident(&item.ident);
11051105
self.visit_generics(generics);
11061106
// Permit `Anon{Struct,Union}` as field type.
11071107
walk_list!(self, visit_struct_field_def, fields);
@@ -1521,7 +1521,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
15211521
|| matches!(sig.header.constness, Const::Yes(_)) =>
15221522
{
15231523
self.visit_vis(&item.vis);
1524-
self.visit_ident(item.ident);
1524+
self.visit_ident(&item.ident);
15251525
let kind = FnKind::Fn(
15261526
FnCtxt::Assoc(ctxt),
15271527
item.ident,

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/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1892,11 +1892,11 @@ impl EarlyLintPass for KeywordIdents {
18921892
fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::MacCall) {
18931893
self.check_tokens(cx, &mac.args.tokens);
18941894
}
1895-
fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: Ident) {
1895+
fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: &Ident) {
18961896
if ident.name.as_str().starts_with('\'') {
18971897
self.check_ident_token(cx, UnderMacro(false), ident.without_first_quote(), "'");
18981898
} else {
1899-
self.check_ident_token(cx, UnderMacro(false), ident, "");
1899+
self.check_ident_token(cx, UnderMacro(false), *ident, "");
19001900
}
19011901
}
19021902
}

compiler/rustc_lint/src/early.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ 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) {
193+
fn visit_ident(&mut self, ident: &Ident) {
194194
lint_callback!(self, check_ident, ident);
195195
}
196196

compiler/rustc_lint/src/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ macro_rules! early_lint_methods {
133133
($macro:path, $args:tt) => (
134134
$macro!($args, [
135135
fn check_param(a: &rustc_ast::Param);
136-
fn check_ident(a: rustc_span::symbol::Ident);
136+
fn check_ident(a: &rustc_span::symbol::Ident);
137137
fn check_crate(a: &rustc_ast::Crate);
138138
fn check_crate_post(a: &rustc_ast::Crate);
139139
fn check_item(a: &rustc_ast::Item);

compiler/rustc_resolve/src/build_reduced_graph.rs

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

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| {
@@ -4582,7 +4582,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
45824582

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

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)