Skip to content

Commit 6568ef3

Browse files
committed
Remove path_span argument to the visit_path_segment methods.
The `visit_path_segment` method of both the AST and HIR visitors has a `path_span` argument that isn't necessary. This commit removes it. There are two very small and inconsequential functional changes. - One call to `NodeCollector::insert` now is passed a path segment identifier span instead of a full path span. This span is only used in a panic message printed in the case of an internal compiler bug. - Likewise, one call to `LifetimeCollectVisitor::record_elided_anchor` now uses a path segment identifier span instead of a full path span. This span is used to make some `'_` lifetimes.
1 parent 59e7a30 commit 6568ef3

File tree

13 files changed

+57
-75
lines changed

13 files changed

+57
-75
lines changed

compiler/rustc_ast/src/visit.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ pub trait Visitor<'ast>: Sized {
201201
fn visit_use_tree(&mut self, use_tree: &'ast UseTree, id: NodeId, _nested: bool) {
202202
walk_use_tree(self, use_tree, id)
203203
}
204-
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'ast PathSegment) {
205-
walk_path_segment(self, path_span, path_segment)
204+
fn visit_path_segment(&mut self, path_segment: &'ast PathSegment) {
205+
walk_path_segment(self, path_segment)
206206
}
207-
fn visit_generic_args(&mut self, path_span: Span, generic_args: &'ast GenericArgs) {
208-
walk_generic_args(self, path_span, generic_args)
207+
fn visit_generic_args(&mut self, generic_args: &'ast GenericArgs) {
208+
walk_generic_args(self, generic_args)
209209
}
210210
fn visit_generic_arg(&mut self, generic_arg: &'ast GenericArg) {
211211
walk_generic_arg(self, generic_arg)
@@ -435,7 +435,7 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
435435

436436
pub fn walk_path<'a, V: Visitor<'a>>(visitor: &mut V, path: &'a Path) {
437437
for segment in &path.segments {
438-
visitor.visit_path_segment(path.span, segment);
438+
visitor.visit_path_segment(segment);
439439
}
440440
}
441441

@@ -457,18 +457,14 @@ pub fn walk_use_tree<'a, V: Visitor<'a>>(visitor: &mut V, use_tree: &'a UseTree,
457457
}
458458
}
459459

460-
pub fn walk_path_segment<'a, V: Visitor<'a>>(
461-
visitor: &mut V,
462-
path_span: Span,
463-
segment: &'a PathSegment,
464-
) {
460+
pub fn walk_path_segment<'a, V: Visitor<'a>>(visitor: &mut V, segment: &'a PathSegment) {
465461
visitor.visit_ident(segment.ident);
466462
if let Some(ref args) = segment.args {
467-
visitor.visit_generic_args(path_span, args);
463+
visitor.visit_generic_args(args);
468464
}
469465
}
470466

471-
pub fn walk_generic_args<'a, V>(visitor: &mut V, _path_span: Span, generic_args: &'a GenericArgs)
467+
pub fn walk_generic_args<'a, V>(visitor: &mut V, generic_args: &'a GenericArgs)
472468
where
473469
V: Visitor<'a>,
474470
{
@@ -502,7 +498,7 @@ where
502498
pub fn walk_assoc_constraint<'a, V: Visitor<'a>>(visitor: &mut V, constraint: &'a AssocConstraint) {
503499
visitor.visit_ident(constraint.ident);
504500
if let Some(ref gen_args) = constraint.gen_args {
505-
visitor.visit_generic_args(gen_args.span(), gen_args);
501+
visitor.visit_generic_args(gen_args);
506502
}
507503
match constraint.kind {
508504
AssocConstraintKind::Equality { ref term } => match term {
@@ -800,7 +796,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
800796
walk_list!(visitor, visit_expr, arguments);
801797
}
802798
ExprKind::MethodCall(ref segment, ref receiver, ref arguments, _span) => {
803-
visitor.visit_path_segment(expression.span, segment);
799+
visitor.visit_path_segment(segment);
804800
visitor.visit_expr(receiver);
805801
walk_list!(visitor, visit_expr, arguments);
806802
}

compiler/rustc_ast_lowering/src/index.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
245245
});
246246
}
247247

248-
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'hir PathSegment<'hir>) {
249-
self.insert(path_span, path_segment.hir_id, Node::PathSegment(path_segment));
250-
intravisit::walk_path_segment(self, path_span, path_segment);
248+
fn visit_path_segment(&mut self, path_segment: &'hir PathSegment<'hir>) {
249+
self.insert(path_segment.ident.span, path_segment.hir_id, Node::PathSegment(path_segment));
250+
intravisit::walk_path_segment(self, path_segment);
251251
}
252252

253253
fn visit_ty(&mut self, ty: &'hir Ty<'hir>) {

compiler/rustc_ast_lowering/src/lifetime_collector.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ impl<'ast> Visitor<'ast> for LifetimeCollectVisitor<'ast> {
6363
self.record_lifetime_use(*lifetime);
6464
}
6565

66-
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'ast PathSegment) {
67-
self.record_elided_anchor(path_segment.id, path_span);
68-
visit::walk_path_segment(self, path_span, path_segment);
66+
fn visit_path_segment(&mut self, path_segment: &'ast PathSegment) {
67+
self.record_elided_anchor(path_segment.id, path_segment.ident.span);
68+
visit::walk_path_segment(self, path_segment);
6969
}
7070

7171
fn visit_poly_trait_ref(&mut self, t: &'ast PolyTraitRef) {

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,9 @@ impl<'a> AstValidator<'a> {
223223
for (i, segment) in path.segments.iter().enumerate() {
224224
// Allow `impl Trait` iff we're on the final path segment
225225
if i == path.segments.len() - 1 {
226-
self.visit_path_segment(path.span, segment);
226+
self.visit_path_segment(segment);
227227
} else {
228-
self.with_banned_impl_trait(|this| {
229-
this.visit_path_segment(path.span, segment)
230-
});
228+
self.with_banned_impl_trait(|this| this.visit_path_segment(segment));
231229
}
232230
}
233231
}
@@ -1293,7 +1291,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12931291
}
12941292

12951293
// Mirrors `visit::walk_generic_args`, but tracks relevant state.
1296-
fn visit_generic_args(&mut self, _: Span, generic_args: &'a GenericArgs) {
1294+
fn visit_generic_args(&mut self, generic_args: &'a GenericArgs) {
12971295
match *generic_args {
12981296
GenericArgs::AngleBracketed(ref data) => {
12991297
self.check_generic_args_before_constraints(data);

compiler/rustc_ast_passes/src/node_count.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ impl<'ast> Visitor<'ast> for NodeCounter {
115115
self.count += 1;
116116
walk_use_tree(self, use_tree, id)
117117
}
118-
fn visit_generic_args(&mut self, path_span: Span, generic_args: &GenericArgs) {
118+
fn visit_generic_args(&mut self, generic_args: &GenericArgs) {
119119
self.count += 1;
120-
walk_generic_args(self, path_span, generic_args)
120+
walk_generic_args(self, generic_args)
121121
}
122122
fn visit_assoc_constraint(&mut self, constraint: &AssocConstraint) {
123123
self.count += 1;

compiler/rustc_hir/src/intravisit.rs

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -420,17 +420,18 @@ pub trait Visitor<'v>: Sized {
420420
fn visit_lifetime(&mut self, lifetime: &'v Lifetime) {
421421
walk_lifetime(self, lifetime)
422422
}
423-
fn visit_qpath(&mut self, qpath: &'v QPath<'v>, id: HirId, span: Span) {
424-
walk_qpath(self, qpath, id, span)
423+
// The span is that of the surrounding type/pattern/expr/whatever.
424+
fn visit_qpath(&mut self, qpath: &'v QPath<'v>, id: HirId, _span: Span) {
425+
walk_qpath(self, qpath, id)
425426
}
426427
fn visit_path(&mut self, path: &'v Path<'v>, _id: HirId) {
427428
walk_path(self, path)
428429
}
429-
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v PathSegment<'v>) {
430-
walk_path_segment(self, path_span, path_segment)
430+
fn visit_path_segment(&mut self, path_segment: &'v PathSegment<'v>) {
431+
walk_path_segment(self, path_segment)
431432
}
432-
fn visit_generic_args(&mut self, path_span: Span, generic_args: &'v GenericArgs<'v>) {
433-
walk_generic_args(self, path_span, generic_args)
433+
fn visit_generic_args(&mut self, generic_args: &'v GenericArgs<'v>) {
434+
walk_generic_args(self, generic_args)
434435
}
435436
fn visit_assoc_type_binding(&mut self, type_binding: &'v TypeBinding<'v>) {
436437
walk_assoc_type_binding(self, type_binding)
@@ -693,48 +694,35 @@ pub fn walk_inf<'v, V: Visitor<'v>>(visitor: &mut V, inf: &'v InferArg) {
693694
visitor.visit_id(inf.hir_id);
694695
}
695696

696-
pub fn walk_qpath<'v, V: Visitor<'v>>(
697-
visitor: &mut V,
698-
qpath: &'v QPath<'v>,
699-
id: HirId,
700-
span: Span,
701-
) {
697+
pub fn walk_qpath<'v, V: Visitor<'v>>(visitor: &mut V, qpath: &'v QPath<'v>, id: HirId) {
702698
match *qpath {
703699
QPath::Resolved(ref maybe_qself, ref path) => {
704700
walk_list!(visitor, visit_ty, maybe_qself);
705701
visitor.visit_path(path, id)
706702
}
707703
QPath::TypeRelative(ref qself, ref segment) => {
708704
visitor.visit_ty(qself);
709-
visitor.visit_path_segment(span, segment);
705+
visitor.visit_path_segment(segment);
710706
}
711707
QPath::LangItem(..) => {}
712708
}
713709
}
714710

715711
pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path<'v>) {
716712
for segment in path.segments {
717-
visitor.visit_path_segment(path.span, segment);
713+
visitor.visit_path_segment(segment);
718714
}
719715
}
720716

721-
pub fn walk_path_segment<'v, V: Visitor<'v>>(
722-
visitor: &mut V,
723-
path_span: Span,
724-
segment: &'v PathSegment<'v>,
725-
) {
717+
pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V, segment: &'v PathSegment<'v>) {
726718
visitor.visit_ident(segment.ident);
727719
visitor.visit_id(segment.hir_id);
728720
if let Some(ref args) = segment.args {
729-
visitor.visit_generic_args(path_span, args);
721+
visitor.visit_generic_args(args);
730722
}
731723
}
732724

733-
pub fn walk_generic_args<'v, V: Visitor<'v>>(
734-
visitor: &mut V,
735-
_path_span: Span,
736-
generic_args: &'v GenericArgs<'v>,
737-
) {
725+
pub fn walk_generic_args<'v, V: Visitor<'v>>(visitor: &mut V, generic_args: &'v GenericArgs<'v>) {
738726
walk_list!(visitor, visit_generic_arg, generic_args.args);
739727
walk_list!(visitor, visit_assoc_type_binding, generic_args.bindings);
740728
}
@@ -745,7 +733,7 @@ pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(
745733
) {
746734
visitor.visit_id(type_binding.hir_id);
747735
visitor.visit_ident(type_binding.ident);
748-
visitor.visit_generic_args(type_binding.span, type_binding.gen_args);
736+
visitor.visit_generic_args(type_binding.gen_args);
749737
match type_binding.kind {
750738
TypeBindingKind::Equality { ref term } => match term {
751739
Term::Ty(ref ty) => visitor.visit_ty(ty),
@@ -822,9 +810,9 @@ pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v GenericB
822810
GenericBound::Trait(ref typ, modifier) => {
823811
visitor.visit_poly_trait_ref(typ, modifier);
824812
}
825-
GenericBound::LangItemTrait(_, span, hir_id, args) => {
813+
GenericBound::LangItemTrait(_, _span, hir_id, args) => {
826814
visitor.visit_id(hir_id);
827-
visitor.visit_generic_args(span, args);
815+
visitor.visit_generic_args(args);
828816
}
829817
GenericBound::Outlives(ref lifetime) => visitor.visit_lifetime(lifetime),
830818
}
@@ -1095,7 +1083,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
10951083
walk_list!(visitor, visit_expr, arguments);
10961084
}
10971085
ExprKind::MethodCall(ref segment, receiver, arguments, _) => {
1098-
visitor.visit_path_segment(expression.span, segment);
1086+
visitor.visit_path_segment(segment);
10991087
visitor.visit_expr(receiver);
11001088
walk_list!(visitor, visit_expr, arguments);
11011089
}

compiler/rustc_lint/src/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,7 @@ impl TypeAliasBounds {
14671467
if TypeAliasBounds::is_type_variable_assoc(qpath) {
14681468
self.err.span_help(span, fluent::lint::builtin_type_alias_bounds_help);
14691469
}
1470-
intravisit::walk_qpath(self, qpath, id, span)
1470+
intravisit::walk_qpath(self, qpath, id)
14711471
}
14721472
}
14731473

compiler/rustc_lint/src/early.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,9 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
266266
ast_visit::walk_path(self, p);
267267
}
268268

269-
fn visit_path_segment(&mut self, path_span: Span, s: &'a ast::PathSegment) {
269+
fn visit_path_segment(&mut self, s: &'a ast::PathSegment) {
270270
self.check_id(s.id);
271-
ast_visit::walk_path_segment(self, path_span, s);
271+
ast_visit::walk_path_segment(self, s);
272272
}
273273

274274
fn visit_attribute(&mut self, attr: &'a ast::Attribute) {

compiler/rustc_passes/src/hir_stats.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -447,14 +447,14 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
447447
hir_visit::walk_path(self, path)
448448
}
449449

450-
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v hir::PathSegment<'v>) {
450+
fn visit_path_segment(&mut self, path_segment: &'v hir::PathSegment<'v>) {
451451
self.record("PathSegment", Id::None, path_segment);
452-
hir_visit::walk_path_segment(self, path_span, path_segment)
452+
hir_visit::walk_path_segment(self, path_segment)
453453
}
454454

455-
fn visit_generic_args(&mut self, sp: Span, ga: &'v hir::GenericArgs<'v>) {
455+
fn visit_generic_args(&mut self, ga: &'v hir::GenericArgs<'v>) {
456456
self.record("GenericArgs", Id::None, ga);
457-
hir_visit::walk_generic_args(self, sp, ga)
457+
hir_visit::walk_generic_args(self, ga)
458458
}
459459

460460
fn visit_assoc_type_binding(&mut self, type_binding: &'v hir::TypeBinding<'v>) {
@@ -652,21 +652,21 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
652652
// one non-inline use (in `ast::Path::segments`). The latter case is more
653653
// common than the former case, so we implement this visitor and tolerate
654654
// the double counting in the former case.
655-
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v ast::PathSegment) {
655+
fn visit_path_segment(&mut self, path_segment: &'v ast::PathSegment) {
656656
self.record("PathSegment", Id::None, path_segment);
657-
ast_visit::walk_path_segment(self, path_span, path_segment)
657+
ast_visit::walk_path_segment(self, path_segment)
658658
}
659659

660660
// `GenericArgs` has one inline use (in `ast::AssocConstraint::gen_args`) and one
661661
// non-inline use (in `ast::PathSegment::args`). The latter case is more
662662
// common, so we implement `visit_generic_args` and tolerate the double
663663
// counting in the former case.
664-
fn visit_generic_args(&mut self, sp: Span, g: &'v ast::GenericArgs) {
664+
fn visit_generic_args(&mut self, g: &'v ast::GenericArgs) {
665665
record_variants!(
666666
(self, g, g, Id::None, ast, GenericArgs, GenericArgs),
667667
[AngleBracketed, Parenthesized]
668668
);
669-
ast_visit::walk_generic_args(self, sp, g)
669+
ast_visit::walk_generic_args(self, g)
670670
}
671671

672672
fn visit_attribute(&mut self, attr: &'v ast::Attribute) {

compiler/rustc_privacy/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
13151315
}
13161316
}
13171317

1318-
intravisit::walk_qpath(self, qpath, id, span);
1318+
intravisit::walk_qpath(self, qpath, id);
13191319
}
13201320

13211321
// Check types of patterns.

compiler/rustc_resolve/src/late.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
10301030
if let Some(ref gen_args) = constraint.gen_args {
10311031
// Forbid anonymous lifetimes in GAT parameters until proper semantics are decided.
10321032
self.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
1033-
this.visit_generic_args(gen_args.span(), gen_args)
1033+
this.visit_generic_args(gen_args)
10341034
});
10351035
}
10361036
match constraint.kind {
@@ -1044,10 +1044,10 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
10441044
}
10451045
}
10461046

1047-
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'ast PathSegment) {
1047+
fn visit_path_segment(&mut self, path_segment: &'ast PathSegment) {
10481048
if let Some(ref args) = path_segment.args {
10491049
match &**args {
1050-
GenericArgs::AngleBracketed(..) => visit::walk_generic_args(self, path_span, args),
1050+
GenericArgs::AngleBracketed(..) => visit::walk_generic_args(self, args),
10511051
GenericArgs::Parenthesized(p_args) => {
10521052
// Probe the lifetime ribs to know how to behave.
10531053
for rib in self.lifetime_ribs.iter().rev() {
@@ -1078,7 +1078,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
10781078
// We have nowhere to introduce generics. Code is malformed,
10791079
// so use regular lifetime resolution to avoid spurious errors.
10801080
LifetimeRibKind::Item | LifetimeRibKind::Generics { .. } => {
1081-
visit::walk_generic_args(self, path_span, args);
1081+
visit::walk_generic_args(self, args);
10821082
break;
10831083
}
10841084
LifetimeRibKind::AnonymousCreateParameter { .. }
@@ -3798,7 +3798,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
37983798
for argument in arguments {
37993799
self.resolve_expr(argument, None);
38003800
}
3801-
self.visit_path_segment(expr.span, segment);
3801+
self.visit_path_segment(segment);
38023802
}
38033803

38043804
ExprKind::Call(ref callee, ref arguments) => {

compiler/rustc_resolve/src/late/lifetimes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1827,7 +1827,7 @@ fn is_late_bound_map(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<&FxIndexSet<
18271827
// is, those would be potentially inputs to
18281828
// projections
18291829
if let Some(last_segment) = path.segments.last() {
1830-
self.visit_path_segment(path.span, last_segment);
1830+
self.visit_path_segment(last_segment);
18311831
}
18321832
}
18331833

compiler/rustc_save_analysis/src/dump_visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
13061306
if let hir::QPath::Resolved(_, path) = path {
13071307
self.write_sub_paths_truncated(path);
13081308
}
1309-
intravisit::walk_qpath(self, path, t.hir_id, t.span);
1309+
intravisit::walk_qpath(self, path, t.hir_id);
13101310
}
13111311
hir::TyKind::Array(ref ty, ref length) => {
13121312
self.visit_ty(ty);

0 commit comments

Comments
 (0)