Skip to content

Commit ff32863

Browse files
committed
Stop passing the Span in HIR visiting.
1 parent 9f00730 commit ff32863

File tree

36 files changed

+111
-177
lines changed

36 files changed

+111
-177
lines changed

src/librustc_ast_lowering/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,15 +1557,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15571557
intravisit::NestedVisitorMap::None
15581558
}
15591559

1560-
fn visit_generic_args(&mut self, span: Span, parameters: &'v hir::GenericArgs<'v>) {
1560+
fn visit_generic_args(&mut self, parameters: &'v hir::GenericArgs<'v>) {
15611561
// Don't collect elided lifetimes used inside of `Fn()` syntax.
15621562
if parameters.parenthesized {
15631563
let old_collect_elided_lifetimes = self.collect_elided_lifetimes;
15641564
self.collect_elided_lifetimes = false;
1565-
intravisit::walk_generic_args(self, span, parameters);
1565+
intravisit::walk_generic_args(self, parameters);
15661566
self.collect_elided_lifetimes = old_collect_elided_lifetimes;
15671567
} else {
1568-
intravisit::walk_generic_args(self, span, parameters);
1568+
intravisit::walk_generic_args(self, parameters);
15691569
}
15701570
}
15711571

src/librustc_hir/intravisit.rs

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

4241
pub struct DeepVisitor<'v, V> {
4342
visitor: &'v mut V,
@@ -318,13 +317,13 @@ pub trait Visitor<'v>: Sized {
318317
fn visit_id(&mut self, _hir_id: HirId) {
319318
// Nothing to do.
320319
}
321-
fn visit_name(&mut self, _span: Span, _name: Symbol) {
320+
fn visit_name(&mut self, _name: Symbol) {
322321
// Nothing to do.
323322
}
324323
fn visit_ident(&mut self, ident: Ident) {
325324
walk_ident(self, ident)
326325
}
327-
fn visit_mod(&mut self, m: &'v Mod<'v>, _s: Span, n: HirId) {
326+
fn visit_mod(&mut self, m: &'v Mod<'v>, n: HirId) {
328327
walk_mod(self, m, n)
329328
}
330329
fn visit_foreign_item(&mut self, i: &'v ForeignItem<'v>) {
@@ -366,8 +365,8 @@ pub trait Visitor<'v>: Sized {
366365
fn visit_fn_decl(&mut self, fd: &'v FnDecl<'v>) {
367366
walk_fn_decl(self, fd)
368367
}
369-
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl<'v>, b: BodyId, s: Span, id: HirId) {
370-
walk_fn(self, fk, fd, b, s, id)
368+
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl<'v>, b: BodyId, id: HirId) {
369+
walk_fn(self, fk, fd, b, id)
371370
}
372371
fn visit_use(&mut self, path: &'v Path<'v>, hir_id: HirId) {
373372
walk_use(self, path, hir_id)
@@ -399,7 +398,6 @@ pub trait Visitor<'v>: Sized {
399398
_: Symbol,
400399
_: &'v Generics<'v>,
401400
_parent_id: HirId,
402-
_: Span,
403401
) {
404402
walk_struct_def(self, s)
405403
}
@@ -411,7 +409,6 @@ pub trait Visitor<'v>: Sized {
411409
enum_definition: &'v EnumDef<'v>,
412410
generics: &'v Generics<'v>,
413411
item_id: HirId,
414-
_: Span,
415412
) {
416413
walk_enum_def(self, enum_definition, generics, item_id)
417414
}
@@ -431,17 +428,17 @@ pub trait Visitor<'v>: Sized {
431428
fn visit_lifetime(&mut self, lifetime: &'v Lifetime) {
432429
walk_lifetime(self, lifetime)
433430
}
434-
fn visit_qpath(&mut self, qpath: &'v QPath<'v>, id: HirId, span: Span) {
435-
walk_qpath(self, qpath, id, span)
431+
fn visit_qpath(&mut self, qpath: &'v QPath<'v>, id: HirId) {
432+
walk_qpath(self, qpath, id)
436433
}
437434
fn visit_path(&mut self, path: &'v Path<'v>, _id: HirId) {
438435
walk_path(self, path)
439436
}
440-
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v PathSegment<'v>) {
441-
walk_path_segment(self, path_span, path_segment)
437+
fn visit_path_segment(&mut self, path_segment: &'v PathSegment<'v>) {
438+
walk_path_segment(self, path_segment)
442439
}
443-
fn visit_generic_args(&mut self, path_span: Span, generic_args: &'v GenericArgs<'v>) {
444-
walk_generic_args(self, path_span, generic_args)
440+
fn visit_generic_args(&mut self, generic_args: &'v GenericArgs<'v>) {
441+
walk_generic_args(self, generic_args)
445442
}
446443
fn visit_assoc_type_binding(&mut self, type_binding: &'v TypeBinding<'v>) {
447444
walk_assoc_type_binding(self, type_binding)
@@ -463,7 +460,7 @@ pub trait Visitor<'v>: Sized {
463460

464461
/// Walks the contents of a crate. See also `Crate::visit_all_items`.
465462
pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate<'v>) {
466-
visitor.visit_mod(&krate.item.module, krate.item.span, CRATE_HIR_ID);
463+
visitor.visit_mod(&krate.item.module, CRATE_HIR_ID);
467464
walk_list!(visitor, visit_attribute, krate.item.attrs);
468465
walk_list!(visitor, visit_macro_def, krate.exported_macros);
469466
}
@@ -497,7 +494,7 @@ pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local<'v>) {
497494
}
498495

499496
pub fn walk_ident<'v, V: Visitor<'v>>(visitor: &mut V, ident: Ident) {
500-
visitor.visit_name(ident.span, ident.name);
497+
visitor.visit_name(ident.name);
501498
}
502499

503500
pub fn walk_label<'v, V: Visitor<'v>>(visitor: &mut V, label: &'v Label) {
@@ -547,7 +544,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
547544
ItemKind::ExternCrate(orig_name) => {
548545
visitor.visit_id(item.hir_id);
549546
if let Some(orig_name) = orig_name {
550-
visitor.visit_name(item.span, orig_name);
547+
visitor.visit_name(orig_name);
551548
}
552549
}
553550
ItemKind::Use(ref path, _) => {
@@ -562,12 +559,11 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
562559
FnKind::ItemFn(item.ident, generics, sig.header, &item.vis, &item.attrs),
563560
&sig.decl,
564561
body_id,
565-
item.span,
566562
item.hir_id,
567563
),
568564
ItemKind::Mod(ref module) => {
569565
// `visit_mod()` takes care of visiting the `Item`'s `HirId`.
570-
visitor.visit_mod(module, item.span, item.hir_id)
566+
visitor.visit_mod(module, item.hir_id)
571567
}
572568
ItemKind::ForeignMod(ref foreign_module) => {
573569
visitor.visit_id(item.hir_id);
@@ -589,7 +585,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
589585
ItemKind::Enum(ref enum_definition, ref generics) => {
590586
visitor.visit_generics(generics);
591587
// `visit_enum_def()` takes care of visiting the `Item`'s `HirId`.
592-
visitor.visit_enum_def(enum_definition, generics, item.hir_id, item.span)
588+
visitor.visit_enum_def(enum_definition, generics, item.hir_id)
593589
}
594590
ItemKind::Impl {
595591
unsafety: _,
@@ -612,13 +608,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
612608
| ItemKind::Union(ref struct_definition, ref generics) => {
613609
visitor.visit_generics(generics);
614610
visitor.visit_id(item.hir_id);
615-
visitor.visit_variant_data(
616-
struct_definition,
617-
item.ident.name,
618-
generics,
619-
item.hir_id,
620-
item.span,
621-
);
611+
visitor.visit_variant_data(struct_definition, item.ident.name, generics, item.hir_id);
622612
}
623613
ItemKind::Trait(.., ref generics, bounds, trait_item_refs) => {
624614
visitor.visit_id(item.hir_id);
@@ -658,13 +648,7 @@ pub fn walk_variant<'v, V: Visitor<'v>>(
658648
) {
659649
visitor.visit_ident(variant.ident);
660650
visitor.visit_id(variant.id);
661-
visitor.visit_variant_data(
662-
&variant.data,
663-
variant.ident.name,
664-
generics,
665-
parent_item_id,
666-
variant.span,
667-
);
651+
visitor.visit_variant_data(&variant.data, variant.ident.name, generics, parent_item_id);
668652
walk_list!(visitor, visit_anon_const, &variant.disr_expr);
669653
walk_list!(visitor, visit_attribute, variant.attrs);
670654
}
@@ -688,7 +672,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) {
688672
visitor.visit_fn_decl(&function_declaration.decl);
689673
}
690674
TyKind::Path(ref qpath) => {
691-
visitor.visit_qpath(qpath, typ.hir_id, typ.span);
675+
visitor.visit_qpath(qpath, typ.hir_id);
692676
}
693677
TyKind::OpaqueDef(item_id, lifetimes) => {
694678
visitor.visit_nested_item(item_id);
@@ -709,47 +693,34 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) {
709693
}
710694
}
711695

712-
pub fn walk_qpath<'v, V: Visitor<'v>>(
713-
visitor: &mut V,
714-
qpath: &'v QPath<'v>,
715-
id: HirId,
716-
span: Span,
717-
) {
696+
pub fn walk_qpath<'v, V: Visitor<'v>>(visitor: &mut V, qpath: &'v QPath<'v>, id: HirId) {
718697
match *qpath {
719698
QPath::Resolved(ref maybe_qself, ref path) => {
720699
walk_list!(visitor, visit_ty, maybe_qself);
721700
visitor.visit_path(path, id)
722701
}
723702
QPath::TypeRelative(ref qself, ref segment) => {
724703
visitor.visit_ty(qself);
725-
visitor.visit_path_segment(span, segment);
704+
visitor.visit_path_segment(segment);
726705
}
727706
}
728707
}
729708

730709
pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path<'v>) {
731710
for segment in path.segments {
732-
visitor.visit_path_segment(path.span, segment);
711+
visitor.visit_path_segment(segment);
733712
}
734713
}
735714

736-
pub fn walk_path_segment<'v, V: Visitor<'v>>(
737-
visitor: &mut V,
738-
path_span: Span,
739-
segment: &'v PathSegment<'v>,
740-
) {
715+
pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V, segment: &'v PathSegment<'v>) {
741716
visitor.visit_ident(segment.ident);
742717
walk_list!(visitor, visit_id, segment.hir_id);
743718
if let Some(ref args) = segment.args {
744-
visitor.visit_generic_args(path_span, args);
719+
visitor.visit_generic_args(args);
745720
}
746721
}
747722

748-
pub fn walk_generic_args<'v, V: Visitor<'v>>(
749-
visitor: &mut V,
750-
_path_span: Span,
751-
generic_args: &'v GenericArgs<'v>,
752-
) {
723+
pub fn walk_generic_args<'v, V: Visitor<'v>>(visitor: &mut V, generic_args: &'v GenericArgs<'v>) {
753724
walk_list!(visitor, visit_generic_arg, generic_args.args);
754725
walk_list!(visitor, visit_assoc_type_binding, generic_args.bindings);
755726
}
@@ -774,14 +745,14 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) {
774745
visitor.visit_id(pattern.hir_id);
775746
match pattern.kind {
776747
PatKind::TupleStruct(ref qpath, children, _) => {
777-
visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
748+
visitor.visit_qpath(qpath, pattern.hir_id);
778749
walk_list!(visitor, visit_pat, children);
779750
}
780751
PatKind::Path(ref qpath) => {
781-
visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
752+
visitor.visit_qpath(qpath, pattern.hir_id);
782753
}
783754
PatKind::Struct(ref qpath, fields, _) => {
784-
visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
755+
visitor.visit_qpath(qpath, pattern.hir_id);
785756
for field in fields {
786757
visitor.visit_id(field.hir_id);
787758
visitor.visit_ident(field.ident);
@@ -918,7 +889,6 @@ pub fn walk_fn<'v, V: Visitor<'v>>(
918889
function_kind: FnKind<'v>,
919890
function_declaration: &'v FnDecl<'v>,
920891
body_id: BodyId,
921-
_span: Span,
922892
id: HirId,
923893
) {
924894
visitor.visit_id(id);
@@ -949,7 +919,6 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
949919
FnKind::Method(trait_item.ident, sig, None, &trait_item.attrs),
950920
&sig.decl,
951921
body_id,
952-
trait_item.span,
953922
trait_item.hir_id,
954923
);
955924
}
@@ -999,7 +968,6 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
999968
FnKind::Method(impl_item.ident, sig, Some(&impl_item.vis), &impl_item.attrs),
1000969
&sig.decl,
1001970
body_id,
1002-
impl_item.span,
1003971
impl_item.hir_id,
1004972
);
1005973
}
@@ -1071,7 +1039,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
10711039
visitor.visit_anon_const(count)
10721040
}
10731041
ExprKind::Struct(ref qpath, fields, ref optional_base) => {
1074-
visitor.visit_qpath(qpath, expression.hir_id, expression.span);
1042+
visitor.visit_qpath(qpath, expression.hir_id);
10751043
for field in fields {
10761044
visitor.visit_id(field.hir_id);
10771045
visitor.visit_ident(field.ident);
@@ -1087,7 +1055,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
10871055
walk_list!(visitor, visit_expr, arguments);
10881056
}
10891057
ExprKind::MethodCall(ref segment, _, arguments, _) => {
1090-
visitor.visit_path_segment(expression.span, segment);
1058+
visitor.visit_path_segment(segment);
10911059
walk_list!(visitor, visit_expr, arguments);
10921060
}
10931061
ExprKind::Binary(_, ref left_expression, ref right_expression) => {
@@ -1117,7 +1085,6 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
11171085
FnKind::Closure(&expression.attrs),
11181086
function_declaration,
11191087
body,
1120-
expression.span,
11211088
expression.hir_id,
11221089
),
11231090
ExprKind::Block(ref block, ref opt_label) => {
@@ -1141,7 +1108,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
11411108
visitor.visit_expr(index_expression)
11421109
}
11431110
ExprKind::Path(ref qpath) => {
1144-
visitor.visit_qpath(qpath, expression.hir_id, expression.span);
1111+
visitor.visit_qpath(qpath, expression.hir_id);
11451112
}
11461113
ExprKind::Break(ref destination, ref opt_expr) => {
11471114
walk_list!(visitor, visit_label, &destination.label);

src/librustc_lint/builtin.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,36 +1062,42 @@ impl TypeAliasBounds {
10621062
}
10631063
}
10641064

1065-
fn suggest_changing_assoc_types(ty: &hir::Ty<'_>, err: &mut DiagnosticBuilder<'_>) {
1065+
fn suggest_changing_assoc_types(
1066+
tcx: TyCtxt<'_>,
1067+
ty: &hir::Ty<'_>,
1068+
err: &mut DiagnosticBuilder<'_>,
1069+
) {
10661070
// Access to associates types should use `<T as Bound>::Assoc`, which does not need a
10671071
// bound. Let's see if this type does that.
10681072

10691073
// We use a HIR visitor to walk the type.
10701074
use rustc_hir::intravisit::{self, Visitor};
1071-
struct WalkAssocTypes<'a, 'db> {
1075+
struct WalkAssocTypes<'a, 'db, 'tcx> {
10721076
err: &'a mut DiagnosticBuilder<'db>,
1077+
tcx: TyCtxt<'tcx>,
10731078
}
1074-
impl<'a, 'db, 'v> Visitor<'v> for WalkAssocTypes<'a, 'db> {
1079+
impl<'a, 'db, 'tcx, 'v> Visitor<'v> for WalkAssocTypes<'a, 'db, 'tcx> {
10751080
type Map = intravisit::ErasedMap<'v>;
10761081

10771082
fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<Self::Map> {
10781083
intravisit::NestedVisitorMap::None
10791084
}
10801085

1081-
fn visit_qpath(&mut self, qpath: &'v hir::QPath<'v>, id: hir::HirId, span: Span) {
1086+
fn visit_qpath(&mut self, qpath: &'v hir::QPath<'v>, id: hir::HirId) {
10821087
if TypeAliasBounds::is_type_variable_assoc(qpath) {
1088+
let span = self.tcx.hir().span(id);
10831089
self.err.span_help(
10841090
span,
10851091
"use fully disambiguated paths (i.e., `<T as Trait>::Assoc`) to refer to \
10861092
associated types in type aliases",
10871093
);
10881094
}
1089-
intravisit::walk_qpath(self, qpath, id, span)
1095+
intravisit::walk_qpath(self, qpath, id)
10901096
}
10911097
}
10921098

10931099
// Let's go for a walk!
1094-
let mut visitor = WalkAssocTypes { err };
1100+
let mut visitor = WalkAssocTypes { err, tcx };
10951101
visitor.visit_ty(ty);
10961102
}
10971103
}
@@ -1127,7 +1133,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeAliasBounds {
11271133
Applicability::MachineApplicable,
11281134
);
11291135
if !suggested_changing_assoc_types {
1130-
TypeAliasBounds::suggest_changing_assoc_types(ty, &mut err);
1136+
TypeAliasBounds::suggest_changing_assoc_types(cx.tcx, ty, &mut err);
11311137
suggested_changing_assoc_types = true;
11321138
}
11331139
err.emit();
@@ -1152,7 +1158,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeAliasBounds {
11521158
and should be removed";
11531159
err.multipart_suggestion(&msg, suggestion, Applicability::MachineApplicable);
11541160
if !suggested_changing_assoc_types {
1155-
TypeAliasBounds::suggest_changing_assoc_types(ty, &mut err);
1161+
TypeAliasBounds::suggest_changing_assoc_types(cx.tcx, ty, &mut err);
11561162
suggested_changing_assoc_types = true;
11571163
}
11581164
err.emit();

0 commit comments

Comments
 (0)