Skip to content

Commit 9c68679

Browse files
committed
auto merge of #17069 : eddyb/rust/visitor, r=pnkfelix
Few visitors used the context passing feature and it can be easily emulated. The added lifetime threading allows a visitor to keep safe references to AST nodes it visits, making a non-owning ast_map design possible, for #13316.
2 parents e9278c9 + 7ef6ff0 commit 9c68679

Some content is hidden

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

49 files changed

+1546
-1615
lines changed

src/librustc/front/feature_gate.rs

+26-27
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,15 @@ impl<'a> Context<'a> {
143143
}
144144
}
145145

146-
impl<'a> Visitor<()> for Context<'a> {
147-
fn visit_ident(&mut self, sp: Span, id: ast::Ident, _: ()) {
146+
impl<'a, 'v> Visitor<'v> for Context<'a> {
147+
fn visit_ident(&mut self, sp: Span, id: ast::Ident) {
148148
if !token::get_ident(id).get().is_ascii() {
149149
self.gate_feature("non_ascii_idents", sp,
150150
"non-ascii idents are not fully supported.");
151151
}
152152
}
153153

154-
fn visit_view_item(&mut self, i: &ast::ViewItem, _: ()) {
154+
fn visit_view_item(&mut self, i: &ast::ViewItem) {
155155
match i.node {
156156
ast::ViewItemUse(ref path) => {
157157
match path.node {
@@ -173,10 +173,10 @@ impl<'a> Visitor<()> for Context<'a> {
173173
}
174174
}
175175
}
176-
visit::walk_view_item(self, i, ())
176+
visit::walk_view_item(self, i)
177177
}
178178

179-
fn visit_item(&mut self, i: &ast::Item, _:()) {
179+
fn visit_item(&mut self, i: &ast::Item) {
180180
for attr in i.attrs.iter() {
181181
if attr.name().equiv(&("thread_local")) {
182182
self.gate_feature("thread_local", i.span,
@@ -252,10 +252,10 @@ impl<'a> Visitor<()> for Context<'a> {
252252
_ => {}
253253
}
254254

255-
visit::walk_item(self, i, ());
255+
visit::walk_item(self, i);
256256
}
257257

258-
fn visit_mac(&mut self, macro: &ast::Mac, _: ()) {
258+
fn visit_mac(&mut self, macro: &ast::Mac) {
259259
let ast::MacInvocTT(ref path, _, _) = macro.node;
260260
let id = path.segments.last().unwrap().identifier;
261261
let quotes = ["quote_tokens", "quote_expr", "quote_ty",
@@ -299,16 +299,16 @@ impl<'a> Visitor<()> for Context<'a> {
299299
}
300300
}
301301

302-
fn visit_foreign_item(&mut self, i: &ast::ForeignItem, _: ()) {
302+
fn visit_foreign_item(&mut self, i: &ast::ForeignItem) {
303303
if attr::contains_name(i.attrs.as_slice(), "linkage") {
304304
self.gate_feature("linkage", i.span,
305305
"the `linkage` attribute is experimental \
306306
and not portable across platforms")
307307
}
308-
visit::walk_foreign_item(self, i, ())
308+
visit::walk_foreign_item(self, i)
309309
}
310310

311-
fn visit_ty(&mut self, t: &ast::Ty, _: ()) {
311+
fn visit_ty(&mut self, t: &ast::Ty) {
312312
match t.node {
313313
ast::TyClosure(closure) if closure.onceness == ast::Once => {
314314
self.gate_feature("once_fns", t.span,
@@ -325,10 +325,10 @@ impl<'a> Visitor<()> for Context<'a> {
325325
_ => {}
326326
}
327327

328-
visit::walk_ty(self, t, ());
328+
visit::walk_ty(self, t);
329329
}
330330

331-
fn visit_expr(&mut self, e: &ast::Expr, _: ()) {
331+
fn visit_expr(&mut self, e: &ast::Expr) {
332332
match e.node {
333333
ast::ExprUnary(ast::UnBox, _) => {
334334
self.gate_box(e.span);
@@ -346,10 +346,10 @@ impl<'a> Visitor<()> for Context<'a> {
346346
}
347347
_ => {}
348348
}
349-
visit::walk_expr(self, e, ());
349+
visit::walk_expr(self, e);
350350
}
351351

352-
fn visit_generics(&mut self, generics: &ast::Generics, _: ()) {
352+
fn visit_generics(&mut self, generics: &ast::Generics) {
353353
for type_parameter in generics.ty_params.iter() {
354354
match type_parameter.default {
355355
Some(ty) => {
@@ -360,18 +360,18 @@ impl<'a> Visitor<()> for Context<'a> {
360360
None => {}
361361
}
362362
}
363-
visit::walk_generics(self, generics, ());
363+
visit::walk_generics(self, generics);
364364
}
365365

366-
fn visit_attribute(&mut self, attr: &ast::Attribute, _: ()) {
366+
fn visit_attribute(&mut self, attr: &ast::Attribute) {
367367
if attr::contains_name([*attr], "lang") {
368368
self.gate_feature("lang_items",
369369
attr.span,
370370
"language items are subject to change");
371371
}
372372
}
373373

374-
fn visit_pat(&mut self, pattern: &ast::Pat, (): ()) {
374+
fn visit_pat(&mut self, pattern: &ast::Pat) {
375375
match pattern.node {
376376
ast::PatVec(_, Some(_), ref last) if !last.is_empty() => {
377377
self.gate_feature("advanced_slice_patterns",
@@ -382,25 +382,24 @@ impl<'a> Visitor<()> for Context<'a> {
382382
}
383383
_ => {}
384384
}
385-
visit::walk_pat(self, pattern, ())
385+
visit::walk_pat(self, pattern)
386386
}
387387

388388
fn visit_fn(&mut self,
389-
fn_kind: &visit::FnKind,
390-
fn_decl: &ast::FnDecl,
391-
block: &ast::Block,
389+
fn_kind: visit::FnKind<'v>,
390+
fn_decl: &'v ast::FnDecl,
391+
block: &'v ast::Block,
392392
span: Span,
393-
_: NodeId,
394-
(): ()) {
395-
match *fn_kind {
396-
visit::FkItemFn(_, _, _, ref abi) if *abi == RustIntrinsic => {
393+
_: NodeId) {
394+
match fn_kind {
395+
visit::FkItemFn(_, _, _, abi) if abi == RustIntrinsic => {
397396
self.gate_feature("intrinsics",
398397
span,
399398
"intrinsics are subject to change")
400399
}
401400
_ => {}
402401
}
403-
visit::walk_fn(self, fn_kind, fn_decl, block, span, ());
402+
visit::walk_fn(self, fn_kind, fn_decl, block, span);
404403
}
405404
}
406405

@@ -453,7 +452,7 @@ pub fn check_crate(sess: &Session, krate: &ast::Crate) {
453452
}
454453
}
455454

456-
visit::walk_crate(&mut cx, krate, ());
455+
visit::walk_crate(&mut cx, krate);
457456

458457
sess.abort_if_errors();
459458

src/librustc/front/show_span.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ struct ShowSpanVisitor<'a> {
2323
sess: &'a Session
2424
}
2525

26-
impl<'a> Visitor<()> for ShowSpanVisitor<'a> {
27-
fn visit_expr(&mut self, e: &ast::Expr, _: ()) {
26+
impl<'a, 'v> Visitor<'v> for ShowSpanVisitor<'a> {
27+
fn visit_expr(&mut self, e: &ast::Expr) {
2828
self.sess.span_note(e.span, "expression");
29-
visit::walk_expr(self, e, ());
29+
visit::walk_expr(self, e);
3030
}
3131

32-
fn visit_mac(&mut self, macro: &ast::Mac, e: ()) {
33-
visit::walk_mac(self, macro, e);
32+
fn visit_mac(&mut self, macro: &ast::Mac) {
33+
visit::walk_mac(self, macro);
3434
}
3535
}
3636

3737
pub fn run(sess: &Session, krate: &ast::Crate) {
3838
let mut v = ShowSpanVisitor { sess: sess };
39-
visit::walk_crate(&mut v, krate, ());
39+
visit::walk_crate(&mut v, krate);
4040
}

src/librustc/lint/builtin.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,13 @@ impl<'a, 'tcx> CTypesVisitor<'a, 'tcx> {
366366
}
367367
}
368368

369-
impl<'a, 'tcx> Visitor<()> for CTypesVisitor<'a, 'tcx> {
370-
fn visit_ty(&mut self, ty: &ast::Ty, _: ()) {
369+
impl<'a, 'tcx, 'v> Visitor<'v> for CTypesVisitor<'a, 'tcx> {
370+
fn visit_ty(&mut self, ty: &ast::Ty) {
371371
match ty.node {
372372
ast::TyPath(_, _, id) => self.check_def(ty.span, ty.id, id),
373373
_ => (),
374374
}
375-
visit::walk_ty(self, ty, ());
375+
visit::walk_ty(self, ty);
376376
}
377377
}
378378

@@ -386,7 +386,7 @@ impl LintPass for CTypes {
386386
fn check_item(&mut self, cx: &Context, it: &ast::Item) {
387387
fn check_ty(cx: &Context, ty: &ast::Ty) {
388388
let mut vis = CTypesVisitor { cx: cx };
389-
vis.visit_ty(ty, ());
389+
vis.visit_ty(ty);
390390
}
391391

392392
fn check_foreign_fn(cx: &Context, decl: &ast::FnDecl) {
@@ -500,18 +500,18 @@ struct RawPtrDerivingVisitor<'a, 'tcx: 'a> {
500500
cx: &'a Context<'a, 'tcx>
501501
}
502502

503-
impl<'a, 'tcx> Visitor<()> for RawPtrDerivingVisitor<'a, 'tcx> {
504-
fn visit_ty(&mut self, ty: &ast::Ty, _: ()) {
503+
impl<'a, 'tcx, 'v> Visitor<'v> for RawPtrDerivingVisitor<'a, 'tcx> {
504+
fn visit_ty(&mut self, ty: &ast::Ty) {
505505
static MSG: &'static str = "use of `#[deriving]` with a raw pointer";
506506
match ty.node {
507507
ast::TyPtr(..) => self.cx.span_lint(RAW_POINTER_DERIVING, ty.span, MSG),
508508
_ => {}
509509
}
510-
visit::walk_ty(self, ty, ());
510+
visit::walk_ty(self, ty);
511511
}
512512
// explicit override to a no-op to reduce code bloat
513-
fn visit_expr(&mut self, _: &ast::Expr, _: ()) {}
514-
fn visit_block(&mut self, _: &ast::Block, _: ()) {}
513+
fn visit_expr(&mut self, _: &ast::Expr) {}
514+
fn visit_block(&mut self, _: &ast::Block) {}
515515
}
516516

517517
pub struct RawPointerDeriving {
@@ -554,7 +554,7 @@ impl LintPass for RawPointerDeriving {
554554
match item.node {
555555
ast::ItemStruct(..) | ast::ItemEnum(..) => {
556556
let mut visitor = RawPtrDerivingVisitor { cx: cx };
557-
visit::walk_item(&mut visitor, &*item, ());
557+
visit::walk_item(&mut visitor, &*item);
558558
}
559559
_ => {}
560560
}
@@ -908,9 +908,9 @@ impl LintPass for NonSnakeCase {
908908
}
909909

910910
fn check_fn(&mut self, cx: &Context,
911-
fk: &visit::FnKind, _: &ast::FnDecl,
911+
fk: visit::FnKind, _: &ast::FnDecl,
912912
_: &ast::Block, span: Span, _: ast::NodeId) {
913-
match *fk {
913+
match fk {
914914
visit::FkMethod(ident, _, m) => match method_context(cx, m) {
915915
PlainImpl
916916
=> self.check_snake_case(cx, "method", ident, span),
@@ -1218,7 +1218,7 @@ impl LintPass for UnusedMut {
12181218
}
12191219

12201220
fn check_fn(&mut self, cx: &Context,
1221-
_: &visit::FnKind, decl: &ast::FnDecl,
1221+
_: visit::FnKind, decl: &ast::FnDecl,
12221222
_: &ast::Block, _: Span, _: ast::NodeId) {
12231223
for a in decl.inputs.iter() {
12241224
self.check_unused_mut_pat(cx, &[a.pat]);
@@ -1387,9 +1387,9 @@ impl LintPass for MissingDoc {
13871387
}
13881388

13891389
fn check_fn(&mut self, cx: &Context,
1390-
fk: &visit::FnKind, _: &ast::FnDecl,
1390+
fk: visit::FnKind, _: &ast::FnDecl,
13911391
_: &ast::Block, _: Span, _: ast::NodeId) {
1392-
match *fk {
1392+
match fk {
13931393
visit::FkMethod(_, _, m) => {
13941394
// If the method is an impl for a trait, don't doc.
13951395
if method_context(cx, m) == TraitImpl { return; }

0 commit comments

Comments
 (0)