Skip to content

Commit 83dacf7

Browse files
authored
Unrolled build for rust-lang#132106
Rollup merge of rust-lang#132106 - maxcabrajac:ident_ref, r=petrochenkov 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` related to rust-lang#128974
2 parents b188577 + 64a3451 commit 83dacf7

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 {
@@ -314,12 +314,12 @@ pub fn walk_local<'a, V: Visitor<'a>>(visitor: &mut V, local: &'a Local) -> V::R
314314
}
315315

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

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

325325
pub fn walk_poly_trait_ref<'a, V>(visitor: &mut V, trait_ref: &'a PolyTraitRef) -> V::Result
@@ -426,17 +426,17 @@ impl WalkItemKind for ItemKind {
426426
}) => {
427427
try_visit!(walk_qself(visitor, qself));
428428
try_visit!(visitor.visit_path(path, *id));
429-
visit_opt!(visitor, visit_ident, *rename);
429+
visit_opt!(visitor, visit_ident, rename);
430430
visit_opt!(visitor, visit_block, body);
431431
}
432432
ItemKind::DelegationMac(box DelegationMac { qself, prefix, suffixes, body }) => {
433433
try_visit!(walk_qself(visitor, qself));
434434
try_visit!(visitor.visit_path(prefix, *id));
435435
if let Some(suffixes) = suffixes {
436436
for (ident, rename) in suffixes {
437-
visitor.visit_ident(*ident);
437+
visitor.visit_ident(ident);
438438
if let Some(rename) = rename {
439-
visitor.visit_ident(*rename);
439+
visitor.visit_ident(rename);
440440
}
441441
}
442442
}
@@ -469,7 +469,7 @@ where
469469
let Variant { attrs, id: _, span: _, vis, ident, data, disr_expr, is_placeholder: _ } = variant;
470470
walk_list!(visitor, visit_attribute, attrs);
471471
try_visit!(visitor.visit_vis(vis));
472-
try_visit!(visitor.visit_ident(*ident));
472+
try_visit!(visitor.visit_ident(ident));
473473
try_visit!(visitor.visit_variant_data(data));
474474
visit_opt!(visitor, visit_variant_discr, disr_expr);
475475
V::Result::output()
@@ -478,15 +478,15 @@ where
478478
pub fn walk_expr_field<'a, V: Visitor<'a>>(visitor: &mut V, f: &'a ExprField) -> V::Result {
479479
let ExprField { attrs, id: _, span: _, ident, expr, is_shorthand: _, is_placeholder: _ } = f;
480480
walk_list!(visitor, visit_attribute, attrs);
481-
try_visit!(visitor.visit_ident(*ident));
481+
try_visit!(visitor.visit_ident(ident));
482482
try_visit!(visitor.visit_expr(expr));
483483
V::Result::output()
484484
}
485485

486486
pub fn walk_pat_field<'a, V: Visitor<'a>>(visitor: &mut V, fp: &'a PatField) -> V::Result {
487487
let PatField { ident, pat, is_shorthand: _, attrs, id: _, span: _, is_placeholder: _ } = fp;
488488
walk_list!(visitor, visit_attribute, attrs);
489-
try_visit!(visitor.visit_ident(*ident));
489+
try_visit!(visitor.visit_ident(ident));
490490
try_visit!(visitor.visit_pat(pat));
491491
V::Result::output()
492492
}
@@ -561,7 +561,7 @@ pub fn walk_use_tree<'a, V: Visitor<'a>>(
561561
match kind {
562562
UseTreeKind::Simple(rename) => {
563563
// The extra IDs are handled during AST lowering.
564-
visit_opt!(visitor, visit_ident, *rename);
564+
visit_opt!(visitor, visit_ident, rename);
565565
}
566566
UseTreeKind::Glob => {}
567567
UseTreeKind::Nested { ref items, span: _ } => {
@@ -578,7 +578,7 @@ pub fn walk_path_segment<'a, V: Visitor<'a>>(
578578
segment: &'a PathSegment,
579579
) -> V::Result {
580580
let PathSegment { ident, id: _, args } = segment;
581-
try_visit!(visitor.visit_ident(*ident));
581+
try_visit!(visitor.visit_ident(ident));
582582
visit_opt!(visitor, visit_generic_args, args);
583583
V::Result::output()
584584
}
@@ -624,7 +624,7 @@ pub fn walk_assoc_item_constraint<'a, V: Visitor<'a>>(
624624
constraint: &'a AssocItemConstraint,
625625
) -> V::Result {
626626
let AssocItemConstraint { id: _, ident, gen_args, kind, span: _ } = constraint;
627-
try_visit!(visitor.visit_ident(*ident));
627+
try_visit!(visitor.visit_ident(ident));
628628
visit_opt!(visitor, visit_generic_args, gen_args);
629629
match kind {
630630
AssocItemConstraintKind::Equality { term } => match term {
@@ -662,7 +662,7 @@ pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) -> V::Res
662662
try_visit!(visitor.visit_pat(subpattern));
663663
}
664664
PatKind::Ident(_bmode, ident, optional_subpattern) => {
665-
try_visit!(visitor.visit_ident(*ident));
665+
try_visit!(visitor.visit_ident(ident));
666666
visit_opt!(visitor, visit_pat, optional_subpattern);
667667
}
668668
PatKind::Lit(expression) => try_visit!(visitor.visit_expr(expression)),
@@ -748,7 +748,7 @@ pub fn walk_generic_param<'a, V: Visitor<'a>>(
748748
let GenericParam { id: _, ident, attrs, bounds, is_placeholder: _, kind, colon_span: _ } =
749749
param;
750750
walk_list!(visitor, visit_attribute, attrs);
751-
try_visit!(visitor.visit_ident(*ident));
751+
try_visit!(visitor.visit_ident(ident));
752752
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
753753
match kind {
754754
GenericParamKind::Lifetime => (),
@@ -886,17 +886,17 @@ impl WalkItemKind for AssocItemKind {
886886
}) => {
887887
try_visit!(walk_qself(visitor, qself));
888888
try_visit!(visitor.visit_path(path, *id));
889-
visit_opt!(visitor, visit_ident, *rename);
889+
visit_opt!(visitor, visit_ident, rename);
890890
visit_opt!(visitor, visit_block, body);
891891
}
892892
AssocItemKind::DelegationMac(box DelegationMac { qself, prefix, suffixes, body }) => {
893893
try_visit!(walk_qself(visitor, qself));
894894
try_visit!(visitor.visit_path(prefix, id));
895895
if let Some(suffixes) = suffixes {
896896
for (ident, rename) in suffixes {
897-
visitor.visit_ident(*ident);
897+
visitor.visit_ident(ident);
898898
if let Some(rename) = rename {
899-
visitor.visit_ident(*rename);
899+
visitor.visit_ident(rename);
900900
}
901901
}
902902
}
@@ -912,7 +912,7 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(
912912
item: &'a Item<impl WalkItemKind>,
913913
ctxt: AssocCtxt,
914914
) -> V::Result {
915-
let &Item { id: _, span: _, ident, ref vis, ref attrs, ref kind, tokens: _ } = item;
915+
let Item { id: _, span: _, ident, vis, attrs, kind, tokens: _ } = item;
916916
walk_list!(visitor, visit_attribute, attrs);
917917
try_visit!(visitor.visit_vis(vis));
918918
try_visit!(visitor.visit_ident(ident));
@@ -932,7 +932,7 @@ pub fn walk_field_def<'a, V: Visitor<'a>>(visitor: &mut V, field: &'a FieldDef)
932932
let FieldDef { attrs, id: _, span: _, vis, ident, ty, is_placeholder: _ } = field;
933933
walk_list!(visitor, visit_attribute, attrs);
934934
try_visit!(visitor.visit_vis(vis));
935-
visit_opt!(visitor, visit_ident, *ident);
935+
visit_opt!(visitor, visit_ident, ident);
936936
try_visit!(visitor.visit_ty(ty));
937937
V::Result::output()
938938
}
@@ -1014,7 +1014,7 @@ pub fn walk_format_args<'a, V: Visitor<'a>>(visitor: &mut V, fmt: &'a FormatArgs
10141014
for FormatArgument { kind, expr } in arguments.all_args() {
10151015
match kind {
10161016
FormatArgumentKind::Named(ident) | FormatArgumentKind::Captured(ident) => {
1017-
try_visit!(visitor.visit_ident(*ident))
1017+
try_visit!(visitor.visit_ident(ident))
10181018
}
10191019
FormatArgumentKind::Normal => {}
10201020
}
@@ -1134,7 +1134,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V
11341134
}
11351135
ExprKind::Field(subexpression, ident) => {
11361136
try_visit!(visitor.visit_expr(subexpression));
1137-
try_visit!(visitor.visit_ident(*ident));
1137+
try_visit!(visitor.visit_ident(ident));
11381138
}
11391139
ExprKind::Index(main_expression, index_expression, _span) => {
11401140
try_visit!(visitor.visit_expr(main_expression));
@@ -1169,7 +1169,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V
11691169
ExprKind::FormatArgs(f) => try_visit!(visitor.visit_format_args(f)),
11701170
ExprKind::OffsetOf(container, fields) => {
11711171
try_visit!(visitor.visit_ty(container));
1172-
walk_list!(visitor, visit_ident, fields.iter().copied());
1172+
walk_list!(visitor, visit_ident, fields.iter());
11731173
}
11741174
ExprKind::Yield(optional_expression) => {
11751175
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
@@ -1894,11 +1894,11 @@ impl EarlyLintPass for KeywordIdents {
18941894
fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::MacCall) {
18951895
self.check_tokens(cx, &mac.args.tokens);
18961896
}
1897-
fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: Ident) {
1897+
fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: &Ident) {
18981898
if ident.name.as_str().starts_with('\'') {
18991899
self.check_ident_token(cx, UnderMacro(false), ident.without_first_quote(), "'");
19001900
} else {
1901-
self.check_ident_token(cx, UnderMacro(false), ident, "");
1901+
self.check_ident_token(cx, UnderMacro(false), *ident, "");
19021902
}
19031903
}
19041904
}

compiler/rustc_lint/src/early.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
202202
ast_visit::walk_ty(self, t);
203203
}
204204

205-
fn visit_ident(&mut self, ident: Ident) {
205+
fn visit_ident(&mut self, ident: &Ident) {
206206
lint_callback!(self, check_ident, ident);
207207
}
208208

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)