Skip to content

Commit 3947c9e

Browse files
committed
Stop passing the Span in HIR visiting.
1 parent 0d98c91 commit 3947c9e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+117
-178
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,15 +1600,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16001600
intravisit::NestedVisitorMap::None
16011601
}
16021602

1603-
fn visit_generic_args(&mut self, span: Span, parameters: &'v hir::GenericArgs<'v>) {
1603+
fn visit_generic_args(&mut self, parameters: &'v hir::GenericArgs<'v>) {
16041604
// Don't collect elided lifetimes used inside of `Fn()` syntax.
16051605
if parameters.parenthesized {
16061606
let old_collect_elided_lifetimes = self.collect_elided_lifetimes;
16071607
self.collect_elided_lifetimes = false;
1608-
intravisit::walk_generic_args(self, span, parameters);
1608+
intravisit::walk_generic_args(self, parameters);
16091609
self.collect_elided_lifetimes = old_collect_elided_lifetimes;
16101610
} else {
1611-
intravisit::walk_generic_args(self, span, parameters);
1611+
intravisit::walk_generic_args(self, parameters);
16121612
}
16131613
}
16141614

compiler/rustc_hir/src/intravisit.rs

Lines changed: 32 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ use crate::itemlikevisit::{ItemLikeVisitor, ParItemLikeVisitor};
3737
use rustc_ast::walk_list;
3838
use rustc_ast::{Attribute, Label};
3939
use rustc_span::symbol::{Ident, Symbol};
40-
use rustc_span::Span;
4140

4241
pub struct DeepVisitor<'v, V> {
4342
visitor: &'v mut V,
@@ -335,13 +334,13 @@ pub trait Visitor<'v>: Sized {
335334
fn visit_id(&mut self, _hir_id: HirId) {
336335
// Nothing to do.
337336
}
338-
fn visit_name(&mut self, _span: Span, _name: Symbol) {
337+
fn visit_name(&mut self, _name: Symbol) {
339338
// Nothing to do.
340339
}
341340
fn visit_ident(&mut self, ident: Ident) {
342341
walk_ident(self, ident)
343342
}
344-
fn visit_mod(&mut self, m: &'v Mod<'v>, _s: Span, n: HirId) {
343+
fn visit_mod(&mut self, m: &'v Mod<'v>, n: HirId) {
345344
walk_mod(self, m, n)
346345
}
347346
fn visit_foreign_item(&mut self, i: &'v ForeignItem<'v>) {
@@ -383,8 +382,8 @@ pub trait Visitor<'v>: Sized {
383382
fn visit_fn_decl(&mut self, fd: &'v FnDecl<'v>) {
384383
walk_fn_decl(self, fd)
385384
}
386-
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl<'v>, b: BodyId, s: Span, id: HirId) {
387-
walk_fn(self, fk, fd, b, s, id)
385+
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl<'v>, b: BodyId, id: HirId) {
386+
walk_fn(self, fk, fd, b, id)
388387
}
389388
fn visit_use(&mut self, path: &'v Path<'v>, hir_id: HirId) {
390389
walk_use(self, path, hir_id)
@@ -419,7 +418,6 @@ pub trait Visitor<'v>: Sized {
419418
_: Symbol,
420419
_: &'v Generics<'v>,
421420
_parent_id: HirId,
422-
_: Span,
423421
) {
424422
walk_struct_def(self, s)
425423
}
@@ -431,7 +429,6 @@ pub trait Visitor<'v>: Sized {
431429
enum_definition: &'v EnumDef<'v>,
432430
generics: &'v Generics<'v>,
433431
item_id: HirId,
434-
_: Span,
435432
) {
436433
walk_enum_def(self, enum_definition, generics, item_id)
437434
}
@@ -451,17 +448,17 @@ pub trait Visitor<'v>: Sized {
451448
fn visit_lifetime(&mut self, lifetime: &'v Lifetime) {
452449
walk_lifetime(self, lifetime)
453450
}
454-
fn visit_qpath(&mut self, qpath: &'v QPath<'v>, id: HirId, span: Span) {
455-
walk_qpath(self, qpath, id, span)
451+
fn visit_qpath(&mut self, qpath: &'v QPath<'v>, id: HirId) {
452+
walk_qpath(self, qpath, id)
456453
}
457454
fn visit_path(&mut self, path: &'v Path<'v>, _id: HirId) {
458455
walk_path(self, path)
459456
}
460-
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v PathSegment<'v>) {
461-
walk_path_segment(self, path_span, path_segment)
457+
fn visit_path_segment(&mut self, path_segment: &'v PathSegment<'v>) {
458+
walk_path_segment(self, path_segment)
462459
}
463-
fn visit_generic_args(&mut self, path_span: Span, generic_args: &'v GenericArgs<'v>) {
464-
walk_generic_args(self, path_span, generic_args)
460+
fn visit_generic_args(&mut self, generic_args: &'v GenericArgs<'v>) {
461+
walk_generic_args(self, generic_args)
465462
}
466463
fn visit_assoc_type_binding(&mut self, type_binding: &'v TypeBinding<'v>) {
467464
walk_assoc_type_binding(self, type_binding)
@@ -483,7 +480,7 @@ pub trait Visitor<'v>: Sized {
483480

484481
/// Walks the contents of a crate. See also `Crate::visit_all_items`.
485482
pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate<'v>) {
486-
visitor.visit_mod(&krate.item.module, krate.item.span, CRATE_HIR_ID);
483+
visitor.visit_mod(&krate.item.module, CRATE_HIR_ID);
487484
walk_list!(visitor, visit_attribute, krate.item.attrs);
488485
walk_list!(visitor, visit_macro_def, krate.exported_macros);
489486
}
@@ -517,7 +514,7 @@ pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local<'v>) {
517514
}
518515

519516
pub fn walk_ident<'v, V: Visitor<'v>>(visitor: &mut V, ident: Ident) {
520-
visitor.visit_name(ident.span, ident.name);
517+
visitor.visit_name(ident.name);
521518
}
522519

523520
pub fn walk_label<'v, V: Visitor<'v>>(visitor: &mut V, label: &'v Label) {
@@ -567,7 +564,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
567564
ItemKind::ExternCrate(orig_name) => {
568565
visitor.visit_id(item.hir_id);
569566
if let Some(orig_name) = orig_name {
570-
visitor.visit_name(item.span, orig_name);
567+
visitor.visit_name(orig_name);
571568
}
572569
}
573570
ItemKind::Use(ref path, _) => {
@@ -582,12 +579,11 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
582579
FnKind::ItemFn(item.ident, generics, sig.header, &item.vis, &item.attrs),
583580
&sig.decl,
584581
body_id,
585-
item.span,
586582
item.hir_id,
587583
),
588584
ItemKind::Mod(ref module) => {
589585
// `visit_mod()` takes care of visiting the `Item`'s `HirId`.
590-
visitor.visit_mod(module, item.span, item.hir_id)
586+
visitor.visit_mod(module, item.hir_id)
591587
}
592588
ItemKind::ForeignMod { abi: _, items } => {
593589
visitor.visit_id(item.hir_id);
@@ -609,7 +605,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
609605
ItemKind::Enum(ref enum_definition, ref generics) => {
610606
visitor.visit_generics(generics);
611607
// `visit_enum_def()` takes care of visiting the `Item`'s `HirId`.
612-
visitor.visit_enum_def(enum_definition, generics, item.hir_id, item.span)
608+
visitor.visit_enum_def(enum_definition, generics, item.hir_id)
613609
}
614610
ItemKind::Impl {
615611
unsafety: _,
@@ -632,13 +628,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
632628
| ItemKind::Union(ref struct_definition, ref generics) => {
633629
visitor.visit_generics(generics);
634630
visitor.visit_id(item.hir_id);
635-
visitor.visit_variant_data(
636-
struct_definition,
637-
item.ident.name,
638-
generics,
639-
item.hir_id,
640-
item.span,
641-
);
631+
visitor.visit_variant_data(struct_definition, item.ident.name, generics, item.hir_id);
642632
}
643633
ItemKind::Trait(.., ref generics, bounds, trait_item_refs) => {
644634
visitor.visit_id(item.hir_id);
@@ -678,13 +668,7 @@ pub fn walk_variant<'v, V: Visitor<'v>>(
678668
) {
679669
visitor.visit_ident(variant.ident);
680670
visitor.visit_id(variant.id);
681-
visitor.visit_variant_data(
682-
&variant.data,
683-
variant.ident.name,
684-
generics,
685-
parent_item_id,
686-
variant.span,
687-
);
671+
visitor.visit_variant_data(&variant.data, variant.ident.name, generics, parent_item_id);
688672
walk_list!(visitor, visit_anon_const, &variant.disr_expr);
689673
walk_list!(visitor, visit_attribute, variant.attrs);
690674
}
@@ -708,7 +692,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) {
708692
visitor.visit_fn_decl(&function_declaration.decl);
709693
}
710694
TyKind::Path(ref qpath) => {
711-
visitor.visit_qpath(qpath, typ.hir_id, typ.span);
695+
visitor.visit_qpath(qpath, typ.hir_id);
712696
}
713697
TyKind::OpaqueDef(item_id, lifetimes) => {
714698
visitor.visit_nested_item(item_id);
@@ -729,48 +713,35 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) {
729713
}
730714
}
731715

732-
pub fn walk_qpath<'v, V: Visitor<'v>>(
733-
visitor: &mut V,
734-
qpath: &'v QPath<'v>,
735-
id: HirId,
736-
span: Span,
737-
) {
716+
pub fn walk_qpath<'v, V: Visitor<'v>>(visitor: &mut V, qpath: &'v QPath<'v>, id: HirId) {
738717
match *qpath {
739718
QPath::Resolved(ref maybe_qself, ref path) => {
740719
walk_list!(visitor, visit_ty, maybe_qself);
741720
visitor.visit_path(path, id)
742721
}
743722
QPath::TypeRelative(ref qself, ref segment) => {
744723
visitor.visit_ty(qself);
745-
visitor.visit_path_segment(span, segment);
724+
visitor.visit_path_segment(segment);
746725
}
747726
QPath::LangItem(..) => {}
748727
}
749728
}
750729

751730
pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path<'v>) {
752731
for segment in path.segments {
753-
visitor.visit_path_segment(path.span, segment);
732+
visitor.visit_path_segment(segment);
754733
}
755734
}
756735

757-
pub fn walk_path_segment<'v, V: Visitor<'v>>(
758-
visitor: &mut V,
759-
path_span: Span,
760-
segment: &'v PathSegment<'v>,
761-
) {
736+
pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V, segment: &'v PathSegment<'v>) {
762737
visitor.visit_ident(segment.ident);
763738
walk_list!(visitor, visit_id, segment.hir_id);
764739
if let Some(ref args) = segment.args {
765-
visitor.visit_generic_args(path_span, args);
740+
visitor.visit_generic_args(args);
766741
}
767742
}
768743

769-
pub fn walk_generic_args<'v, V: Visitor<'v>>(
770-
visitor: &mut V,
771-
_path_span: Span,
772-
generic_args: &'v GenericArgs<'v>,
773-
) {
744+
pub fn walk_generic_args<'v, V: Visitor<'v>>(visitor: &mut V, generic_args: &'v GenericArgs<'v>) {
774745
walk_list!(visitor, visit_generic_arg, generic_args.args);
775746
walk_list!(visitor, visit_assoc_type_binding, generic_args.bindings);
776747
}
@@ -795,14 +766,14 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) {
795766
visitor.visit_id(pattern.hir_id);
796767
match pattern.kind {
797768
PatKind::TupleStruct(ref qpath, children, _) => {
798-
visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
769+
visitor.visit_qpath(qpath, pattern.hir_id);
799770
walk_list!(visitor, visit_pat, children);
800771
}
801772
PatKind::Path(ref qpath) => {
802-
visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
773+
visitor.visit_qpath(qpath, pattern.hir_id);
803774
}
804775
PatKind::Struct(ref qpath, fields, _) => {
805-
visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
776+
visitor.visit_qpath(qpath, pattern.hir_id);
806777
for field in fields {
807778
visitor.visit_id(field.hir_id);
808779
visitor.visit_ident(field.ident);
@@ -859,9 +830,9 @@ pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v GenericB
859830
GenericBound::Trait(ref typ, modifier) => {
860831
visitor.visit_poly_trait_ref(typ, modifier);
861832
}
862-
GenericBound::LangItemTrait(_, span, hir_id, args) => {
833+
GenericBound::LangItemTrait(_, _, hir_id, args) => {
863834
visitor.visit_id(hir_id);
864-
visitor.visit_generic_args(span, args);
835+
visitor.visit_generic_args(args);
865836
}
866837
GenericBound::Outlives(ref lifetime) => visitor.visit_lifetime(lifetime),
867838
}
@@ -948,7 +919,6 @@ pub fn walk_fn<'v, V: Visitor<'v>>(
948919
function_kind: FnKind<'v>,
949920
function_declaration: &'v FnDecl<'v>,
950921
body_id: BodyId,
951-
_span: Span,
952922
id: HirId,
953923
) {
954924
visitor.visit_id(id);
@@ -979,7 +949,6 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
979949
FnKind::Method(trait_item.ident, sig, None, &trait_item.attrs),
980950
&sig.decl,
981951
body_id,
982-
trait_item.span,
983952
trait_item.hir_id,
984953
);
985954
}
@@ -1029,7 +998,6 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
1029998
FnKind::Method(impl_item.ident, sig, Some(&impl_item.vis), &impl_item.attrs),
1030999
&sig.decl,
10311000
body_id,
1032-
impl_item.span,
10331001
impl_item.hir_id,
10341002
);
10351003
}
@@ -1113,7 +1081,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
11131081
visitor.visit_anon_const(count)
11141082
}
11151083
ExprKind::Struct(ref qpath, fields, ref optional_base) => {
1116-
visitor.visit_qpath(qpath, expression.hir_id, expression.span);
1084+
visitor.visit_qpath(qpath, expression.hir_id);
11171085
for field in fields {
11181086
visitor.visit_id(field.hir_id);
11191087
visitor.visit_ident(field.ident);
@@ -1129,7 +1097,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
11291097
walk_list!(visitor, visit_expr, arguments);
11301098
}
11311099
ExprKind::MethodCall(ref segment, _, arguments, _) => {
1132-
visitor.visit_path_segment(expression.span, segment);
1100+
visitor.visit_path_segment(segment);
11331101
walk_list!(visitor, visit_expr, arguments);
11341102
}
11351103
ExprKind::Binary(_, ref left_expression, ref right_expression) => {
@@ -1159,7 +1127,6 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
11591127
FnKind::Closure(&expression.attrs),
11601128
function_declaration,
11611129
body,
1162-
expression.span,
11631130
expression.hir_id,
11641131
),
11651132
ExprKind::Block(ref block, ref opt_label) => {
@@ -1183,7 +1150,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
11831150
visitor.visit_expr(index_expression)
11841151
}
11851152
ExprKind::Path(ref qpath) => {
1186-
visitor.visit_qpath(qpath, expression.hir_id, expression.span);
1153+
visitor.visit_qpath(qpath, expression.hir_id);
11871154
}
11881155
ExprKind::Break(ref destination, ref opt_expr) => {
11891156
walk_list!(visitor, visit_label, &destination.label);

compiler/rustc_lint/src/builtin.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,36 +1378,42 @@ impl TypeAliasBounds {
13781378
}
13791379
}
13801380

1381-
fn suggest_changing_assoc_types(ty: &hir::Ty<'_>, err: &mut DiagnosticBuilder<'_>) {
1381+
fn suggest_changing_assoc_types(
1382+
tcx: TyCtxt<'_>,
1383+
ty: &hir::Ty<'_>,
1384+
err: &mut DiagnosticBuilder<'_>,
1385+
) {
13821386
// Access to associates types should use `<T as Bound>::Assoc`, which does not need a
13831387
// bound. Let's see if this type does that.
13841388

13851389
// We use a HIR visitor to walk the type.
13861390
use rustc_hir::intravisit::{self, Visitor};
1387-
struct WalkAssocTypes<'a, 'db> {
1391+
struct WalkAssocTypes<'a, 'db, 'tcx> {
13881392
err: &'a mut DiagnosticBuilder<'db>,
1393+
tcx: TyCtxt<'tcx>,
13891394
}
1390-
impl<'a, 'db, 'v> Visitor<'v> for WalkAssocTypes<'a, 'db> {
1395+
impl<'a, 'db, 'tcx, 'v> Visitor<'v> for WalkAssocTypes<'a, 'db, 'tcx> {
13911396
type Map = intravisit::ErasedMap<'v>;
13921397

13931398
fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<Self::Map> {
13941399
intravisit::NestedVisitorMap::None
13951400
}
13961401

1397-
fn visit_qpath(&mut self, qpath: &'v hir::QPath<'v>, id: hir::HirId, span: Span) {
1402+
fn visit_qpath(&mut self, qpath: &'v hir::QPath<'v>, id: hir::HirId) {
13981403
if TypeAliasBounds::is_type_variable_assoc(qpath) {
1404+
let span = self.tcx.hir().span(id);
13991405
self.err.span_help(
14001406
span,
14011407
"use fully disambiguated paths (i.e., `<T as Trait>::Assoc`) to refer to \
14021408
associated types in type aliases",
14031409
);
14041410
}
1405-
intravisit::walk_qpath(self, qpath, id, span)
1411+
intravisit::walk_qpath(self, qpath, id)
14061412
}
14071413
}
14081414

14091415
// Let's go for a walk!
1410-
let mut visitor = WalkAssocTypes { err };
1416+
let mut visitor = WalkAssocTypes { err, tcx };
14111417
visitor.visit_ty(ty);
14121418
}
14131419
}
@@ -1443,7 +1449,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
14431449
Applicability::MachineApplicable,
14441450
);
14451451
if !suggested_changing_assoc_types {
1446-
TypeAliasBounds::suggest_changing_assoc_types(ty, &mut err);
1452+
TypeAliasBounds::suggest_changing_assoc_types(cx.tcx, ty, &mut err);
14471453
suggested_changing_assoc_types = true;
14481454
}
14491455
err.emit();
@@ -1468,7 +1474,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
14681474
and should be removed";
14691475
err.multipart_suggestion(&msg, suggestion, Applicability::MachineApplicable);
14701476
if !suggested_changing_assoc_types {
1471-
TypeAliasBounds::suggest_changing_assoc_types(ty, &mut err);
1477+
TypeAliasBounds::suggest_changing_assoc_types(cx.tcx, ty, &mut err);
14721478
suggested_changing_assoc_types = true;
14731479
}
14741480
err.emit();

0 commit comments

Comments
 (0)