Skip to content

Commit 3237b38

Browse files
committed
rustc_ast: Do not panic by default when visiting macro calls
1 parent 0cd1516 commit 3237b38

File tree

16 files changed

+8
-71
lines changed

16 files changed

+8
-71
lines changed

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,8 @@ pub trait MutVisitor: Sized {
210210
noop_visit_local(l, self);
211211
}
212212

213-
fn visit_mac(&mut self, _mac: &mut MacCall) {
214-
panic!("visit_mac disabled by default");
215-
// N.B., see note about macros above. If you really want a visitor that
216-
// works on macros, use this definition in your trait impl:
217-
// mut_visit::noop_visit_mac(_mac, self);
213+
fn visit_mac(&mut self, mac: &mut MacCall) {
214+
noop_visit_mac(mac, self);
218215
}
219216

220217
fn visit_macro_def(&mut self, def: &mut MacroDef) {

compiler/rustc_ast/src/visit.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,8 @@ pub trait Visitor<'ast>: Sized {
176176
fn visit_lifetime(&mut self, lifetime: &'ast Lifetime) {
177177
walk_lifetime(self, lifetime)
178178
}
179-
fn visit_mac(&mut self, _mac: &'ast MacCall) {
180-
panic!("visit_mac disabled by default");
181-
// N.B., see note about macros above.
182-
// if you really want a visitor that
183-
// works on macros, use this
184-
// definition in your trait impl:
185-
// visit::walk_mac(self, _mac)
179+
fn visit_mac(&mut self, mac: &'ast MacCall) {
180+
walk_mac(self, mac)
186181
}
187182
fn visit_mac_def(&mut self, _mac: &'ast MacroDef, _id: NodeId) {
188183
// Nothing to do

compiler/rustc_ast_passes/src/node_count.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ impl<'ast> Visitor<'ast> for NodeCounter {
114114
self.count += 1;
115115
walk_lifetime(self, lifetime)
116116
}
117-
fn visit_mac(&mut self, _mac: &MacCall) {
117+
fn visit_mac(&mut self, mac: &MacCall) {
118118
self.count += 1;
119-
walk_mac(self, _mac)
119+
walk_mac(self, mac)
120120
}
121121
fn visit_path(&mut self, path: &Path, _id: NodeId) {
122122
self.count += 1;

compiler/rustc_ast_passes/src/show_span.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ impl<'a> Visitor<'a> for ShowSpanVisitor<'a> {
5454
}
5555
visit::walk_ty(self, t);
5656
}
57-
58-
fn visit_mac(&mut self, mac: &'a ast::MacCall) {
59-
visit::walk_mac(self, mac);
60-
}
6157
}
6258

6359
pub fn run(span_diagnostic: &rustc_errors::Handler, mode: &str, krate: &ast::Crate) {

compiler/rustc_builtin_macros/src/proc_macro_harness.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,6 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
344344
visit::walk_item(self, item);
345345
self.in_root = prev_in_root;
346346
}
347-
348-
fn visit_mac(&mut self, mac: &'a ast::MacCall) {
349-
visit::walk_mac(self, mac)
350-
}
351347
}
352348

353349
// Creates a new module which looks like:

compiler/rustc_builtin_macros/src/test_harness.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,6 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> {
130130
}
131131
smallvec![P(item)]
132132
}
133-
134-
fn visit_mac(&mut self, _mac: &mut ast::MacCall) {
135-
// Do nothing.
136-
}
137133
}
138134

139135
// Beware, this is duplicated in librustc_passes/entry.rs (with
@@ -201,10 +197,6 @@ impl<'a> MutVisitor for EntryPointCleaner<'a> {
201197

202198
smallvec![item]
203199
}
204-
205-
fn visit_mac(&mut self, _mac: &mut ast::MacCall) {
206-
// Do nothing.
207-
}
208200
}
209201

210202
/// Crawl over the crate, inserting test reexports and the test main function

compiler/rustc_expand/src/config.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -547,11 +547,6 @@ impl<'a> MutVisitor for StripUnconfigured<'a> {
547547
noop_flat_map_assoc_item(configure!(self, item), self)
548548
}
549549

550-
fn visit_mac(&mut self, _mac: &mut ast::MacCall) {
551-
// Don't configure interpolated AST (cf. issue #34171).
552-
// Interpolated AST will get configured once the surrounding tokens are parsed.
553-
}
554-
555550
fn visit_pat(&mut self, pat: &mut P<ast::Pat>) {
556551
self.configure_pat(pat);
557552
noop_visit_pat(pat, self)

compiler/rustc_expand/src/expand.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,8 +850,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
850850

851851
visit::walk_item(self, item);
852852
}
853-
854-
fn visit_mac(&mut self, _: &'ast ast::MacCall) {}
855853
}
856854

857855
if !self.cx.ecfg.proc_macro_hygiene() {

compiler/rustc_expand/src/mbe/transcribe.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ impl MutVisitor for Marker {
2727
fn visit_span(&mut self, span: &mut Span) {
2828
*span = span.apply_mark(self.0, self.1)
2929
}
30-
31-
fn visit_mac(&mut self, mac: &mut MacCall) {
32-
mut_visit::noop_visit_mac(mac, self)
33-
}
3430
}
3531

3632
/// An iterator over the token trees in a delimited token tree (`{ ... }`) or a sequence (`$(...)`).

compiler/rustc_expand/src/mut_visit/tests.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ impl MutVisitor for ToZzIdentMutVisitor {
2121
fn visit_ident(&mut self, ident: &mut Ident) {
2222
*ident = Ident::from_str("zz");
2323
}
24-
fn visit_mac(&mut self, mac: &mut ast::MacCall) {
25-
mut_visit::noop_visit_mac(mac, self)
26-
}
2724
}
2825

2926
// Maybe add to `expand.rs`.

0 commit comments

Comments
 (0)