Skip to content

Commit 59eb444

Browse files
committed
Auto merge of #28715 - petrochenkov:visit, r=nrc
Some minor parts of AST and HIR were not visited by the `visit::walk_xxx` methods - some identifiers, lifetimes, loop labels, attributes of exported macros - but nothing as serious as in, for example, #28364. \+ Added a convenience macro for visiting lists (including Options) \+ Removed some pre-Deref-coersions `&**` noise from visitors r? @nrc
2 parents 19fe7b6 + 4764d98 commit 59eb444

File tree

19 files changed

+552
-713
lines changed

19 files changed

+552
-713
lines changed

src/librustc/front/map/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -912,12 +912,12 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
912912
self.parent_node = parent_node;
913913
}
914914

915-
fn visit_lifetime_ref(&mut self, lifetime: &'ast Lifetime) {
915+
fn visit_lifetime(&mut self, lifetime: &'ast Lifetime) {
916916
self.insert(lifetime.id, NodeLifetime(lifetime));
917917
}
918918

919919
fn visit_lifetime_def(&mut self, def: &'ast LifetimeDef) {
920-
self.visit_lifetime_ref(&def.lifetime);
920+
self.visit_lifetime(&def.lifetime);
921921
}
922922
}
923923

src/librustc/lint/context.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -745,12 +745,8 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {
745745
});
746746
}
747747

748-
fn visit_opt_lifetime_ref(&mut self, sp: Span, lt: &Option<hir::Lifetime>) {
749-
run_lints!(self, check_opt_lifetime_ref, late_passes, sp, lt);
750-
}
751-
752-
fn visit_lifetime_ref(&mut self, lt: &hir::Lifetime) {
753-
run_lints!(self, check_lifetime_ref, late_passes, lt);
748+
fn visit_lifetime(&mut self, lt: &hir::Lifetime) {
749+
run_lints!(self, check_lifetime, late_passes, lt);
754750
}
755751

756752
fn visit_lifetime_def(&mut self, lt: &hir::LifetimeDef) {
@@ -898,12 +894,8 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> {
898894
});
899895
}
900896

901-
fn visit_opt_lifetime_ref(&mut self, sp: Span, lt: &Option<ast::Lifetime>) {
902-
run_lints!(self, check_opt_lifetime_ref, early_passes, sp, lt);
903-
}
904-
905-
fn visit_lifetime_ref(&mut self, lt: &ast::Lifetime) {
906-
run_lints!(self, check_lifetime_ref, early_passes, lt);
897+
fn visit_lifetime(&mut self, lt: &ast::Lifetime) {
898+
run_lints!(self, check_lifetime, early_passes, lt);
907899
}
908900

909901
fn visit_lifetime_def(&mut self, lt: &ast::LifetimeDef) {

src/librustc/lint/mod.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ pub trait LateLintPass: LintPass {
156156
fn check_struct_field(&mut self, _: &LateContext, _: &hir::StructField) { }
157157
fn check_variant(&mut self, _: &LateContext, _: &hir::Variant, _: &hir::Generics) { }
158158
fn check_variant_post(&mut self, _: &LateContext, _: &hir::Variant, _: &hir::Generics) { }
159-
fn check_opt_lifetime_ref(&mut self, _: &LateContext, _: Span, _: &Option<hir::Lifetime>) { }
160-
fn check_lifetime_ref(&mut self, _: &LateContext, _: &hir::Lifetime) { }
159+
fn check_lifetime(&mut self, _: &LateContext, _: &hir::Lifetime) { }
161160
fn check_lifetime_def(&mut self, _: &LateContext, _: &hir::LifetimeDef) { }
162161
fn check_explicit_self(&mut self, _: &LateContext, _: &hir::ExplicitSelf) { }
163162
fn check_path(&mut self, _: &LateContext, _: &hir::Path, _: ast::NodeId) { }
@@ -199,11 +198,7 @@ pub trait EarlyLintPass: LintPass {
199198
fn check_struct_field(&mut self, _: &EarlyContext, _: &ast::StructField) { }
200199
fn check_variant(&mut self, _: &EarlyContext, _: &ast::Variant, _: &ast::Generics) { }
201200
fn check_variant_post(&mut self, _: &EarlyContext, _: &ast::Variant, _: &ast::Generics) { }
202-
fn check_opt_lifetime_ref(&mut self,
203-
_: &EarlyContext,
204-
_: Span,
205-
_: &Option<ast::Lifetime>) { }
206-
fn check_lifetime_ref(&mut self, _: &EarlyContext, _: &ast::Lifetime) { }
201+
fn check_lifetime(&mut self, _: &EarlyContext, _: &ast::Lifetime) { }
207202
fn check_lifetime_def(&mut self, _: &EarlyContext, _: &ast::LifetimeDef) { }
208203
fn check_explicit_self(&mut self, _: &EarlyContext, _: &ast::ExplicitSelf) { }
209204
fn check_path(&mut self, _: &EarlyContext, _: &ast::Path, _: ast::NodeId) { }

src/librustc/metadata/creader.rs

+6
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,12 @@ impl<'a> CrateReader<'a> {
481481
};
482482
let span = mk_sp(lo, p.last_span.hi);
483483
p.abort_if_errors();
484+
485+
// Mark the attrs as used
486+
for attr in &attrs {
487+
attr::mark_used(attr);
488+
}
489+
484490
macros.push(ast::MacroDef {
485491
ident: ast::Ident::with_empty_ctxt(name),
486492
attrs: attrs,

src/librustc/middle/region.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ fn resolve_block(visitor: &mut RegionResolutionVisitor, blk: &hir::Block) {
705705
}
706706
visitor.visit_stmt(&**statement)
707707
}
708-
visit::walk_expr_opt(visitor, &blk.expr)
708+
walk_list!(visitor, visit_expr, &blk.expr);
709709
}
710710

711711
visitor.cx = prev_cx;

src/librustc/middle/resolve_lifetime.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
195195
fn visit_ty(&mut self, ty: &hir::Ty) {
196196
match ty.node {
197197
hir::TyBareFn(ref c) => {
198-
visit::walk_lifetime_decls_helper(self, &c.lifetimes);
199198
self.with(LateScope(&c.lifetimes, self.scope), |old_scope, this| {
200199
// a bare fn has no bounds, so everything
201200
// contained within is scoped within its binder.
@@ -245,7 +244,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
245244
|_, this| visit::walk_block(this, b));
246245
}
247246

248-
fn visit_lifetime_ref(&mut self, lifetime_ref: &hir::Lifetime) {
247+
fn visit_lifetime(&mut self, lifetime_ref: &hir::Lifetime) {
249248
if lifetime_ref.name == special_idents::static_lifetime.name {
250249
self.insert_lifetime(lifetime_ref, DefStaticRegion);
251250
return;
@@ -255,7 +254,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
255254

256255
fn visit_generics(&mut self, generics: &hir::Generics) {
257256
for ty_param in generics.ty_params.iter() {
258-
visit::walk_ty_param_bounds_helper(self, &ty_param.bounds);
257+
walk_list!(self, visit_ty_param_bound, &ty_param.bounds);
259258
match ty_param.default {
260259
Some(ref ty) => self.visit_ty(&**ty),
261260
None => {}
@@ -273,22 +272,22 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
273272
|old_scope, this| {
274273
this.check_lifetime_defs(old_scope, bound_lifetimes);
275274
this.visit_ty(&**bounded_ty);
276-
visit::walk_ty_param_bounds_helper(this, bounds);
275+
walk_list!(this, visit_ty_param_bound, bounds);
277276
});
278277
self.trait_ref_hack = false;
279278
result
280279
} else {
281280
self.visit_ty(&**bounded_ty);
282-
visit::walk_ty_param_bounds_helper(self, bounds);
281+
walk_list!(self, visit_ty_param_bound, bounds);
283282
}
284283
}
285284
&hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate{ref lifetime,
286285
ref bounds,
287286
.. }) => {
288287

289-
self.visit_lifetime_ref(lifetime);
288+
self.visit_lifetime(lifetime);
290289
for bound in bounds {
291-
self.visit_lifetime_ref(bound);
290+
self.visit_lifetime(bound);
292291
}
293292
}
294293
&hir::WherePredicate::EqPredicate(hir::WhereEqPredicate{ id,
@@ -799,23 +798,23 @@ fn early_bound_lifetime_names(generics: &hir::Generics) -> Vec<ast::Name> {
799798
FreeLifetimeCollector { early_bound: &mut early_bound,
800799
late_bound: &mut late_bound };
801800
for ty_param in generics.ty_params.iter() {
802-
visit::walk_ty_param_bounds_helper(&mut collector, &ty_param.bounds);
801+
walk_list!(&mut collector, visit_ty_param_bound, &ty_param.bounds);
803802
}
804803
for predicate in &generics.where_clause.predicates {
805804
match predicate {
806805
&hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate{ref bounds,
807806
ref bounded_ty,
808807
..}) => {
809808
collector.visit_ty(&**bounded_ty);
810-
visit::walk_ty_param_bounds_helper(&mut collector, bounds);
809+
walk_list!(&mut collector, visit_ty_param_bound, bounds);
811810
}
812811
&hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate{ref lifetime,
813812
ref bounds,
814813
..}) => {
815-
collector.visit_lifetime_ref(lifetime);
814+
collector.visit_lifetime(lifetime);
816815

817816
for bound in bounds {
818-
collector.visit_lifetime_ref(bound);
817+
collector.visit_lifetime(bound);
819818
}
820819
}
821820
&hir::WherePredicate::EqPredicate(_) => unimplemented!()
@@ -843,7 +842,7 @@ fn early_bound_lifetime_names(generics: &hir::Generics) -> Vec<ast::Name> {
843842
}
844843

845844
impl<'a, 'v> Visitor<'v> for FreeLifetimeCollector<'a> {
846-
fn visit_lifetime_ref(&mut self, lifetime_ref: &hir::Lifetime) {
845+
fn visit_lifetime(&mut self, lifetime_ref: &hir::Lifetime) {
847846
shuffle(self.early_bound, self.late_bound,
848847
lifetime_ref.name);
849848
}

src/librustc_back/svh.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ mod svh_visitor {
177177
SawIdent(token::InternedString),
178178
SawStructDef(token::InternedString),
179179

180-
SawLifetimeRef(token::InternedString),
180+
SawLifetime(token::InternedString),
181181
SawLifetimeDef(token::InternedString),
182182

183183
SawMod,
@@ -193,7 +193,6 @@ mod svh_visitor {
193193
SawVariant,
194194
SawExplicitSelf,
195195
SawPath,
196-
SawOptLifetimeRef,
197196
SawBlock,
198197
SawPat,
199198
SawLocal,
@@ -316,17 +315,6 @@ mod svh_visitor {
316315
visit::walk_variant(self, v, g)
317316
}
318317

319-
fn visit_opt_lifetime_ref(&mut self, _: Span, l: &Option<Lifetime>) {
320-
SawOptLifetimeRef.hash(self.st);
321-
// (This is a strange method in the visitor trait, in that
322-
// it does not expose a walk function to do the subroutine
323-
// calls.)
324-
match *l {
325-
Some(ref l) => self.visit_lifetime_ref(l),
326-
None => ()
327-
}
328-
}
329-
330318
// All of the remaining methods just record (in the hash
331319
// SipHasher) that the visitor saw that particular variant
332320
// (with its payload), and continue walking as the default
@@ -345,8 +333,8 @@ mod svh_visitor {
345333
SawIdent(name.as_str()).hash(self.st);
346334
}
347335

348-
fn visit_lifetime_ref(&mut self, l: &Lifetime) {
349-
SawLifetimeRef(l.name.as_str()).hash(self.st);
336+
fn visit_lifetime(&mut self, l: &Lifetime) {
337+
SawLifetime(l.name.as_str()).hash(self.st);
350338
}
351339

352340
fn visit_lifetime_def(&mut self, l: &LifetimeDef) {

src/librustc_front/hir.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,13 @@ impl PathListItem_ {
10541054
}
10551055
}
10561056

1057+
pub fn name(&self) -> Option<Name> {
1058+
match *self {
1059+
PathListIdent { name, .. } => Some(name),
1060+
PathListMod { .. } => None,
1061+
}
1062+
}
1063+
10571064
pub fn rename(&self) -> Option<Name> {
10581065
match *self {
10591066
PathListIdent { rename, .. } | PathListMod { rename, .. } => rename

src/librustc_front/util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,12 @@ impl<'a, 'v, O: ast_util::IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O>
303303
visit::walk_impl_item(self, ii);
304304
}
305305

306-
fn visit_lifetime_ref(&mut self, lifetime: &Lifetime) {
306+
fn visit_lifetime(&mut self, lifetime: &Lifetime) {
307307
self.operation.visit_id(lifetime.id);
308308
}
309309

310310
fn visit_lifetime_def(&mut self, def: &LifetimeDef) {
311-
self.visit_lifetime_ref(&def.lifetime);
311+
self.visit_lifetime(&def.lifetime);
312312
}
313313

314314
fn visit_trait_ref(&mut self, trait_ref: &TraitRef) {

0 commit comments

Comments
 (0)