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

+2-5
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

+2-7
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

+2-2
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

-4
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

-4
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

-8
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

-5
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

-2
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

-4
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

-3
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`.

compiler/rustc_expand/src/placeholders.rs

-4
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,4 @@ impl<'a, 'b> MutVisitor for PlaceholderExpander<'a, 'b> {
386386
|item| !matches!(item.kind, ast::ItemKind::MacCall(_) if !self.cx.ecfg.keep_macs),
387387
);
388388
}
389-
390-
fn visit_mac(&mut self, _mac: &mut ast::MacCall) {
391-
// Do nothing.
392-
}
393389
}

compiler/rustc_interface/src/util.rs

-6
Original file line numberDiff line numberDiff line change
@@ -881,12 +881,6 @@ impl<'a> MutVisitor for ReplaceBodyWithLoop<'a, '_> {
881881
})
882882
}
883883
}
884-
885-
// in general the pretty printer processes unexpanded code, so
886-
// we override the default `visit_mac` method which panics.
887-
fn visit_mac(&mut self, mac: &mut ast::MacCall) {
888-
noop_visit_mac(mac, self)
889-
}
890884
}
891885

892886
/// Returns a version string such as "rustc 1.46.0 (04488afe3 2020-08-24)"

compiler/rustc_lint/src/early.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,8 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
271271
}
272272

273273
fn visit_mac(&mut self, mac: &'a ast::MacCall) {
274-
// FIXME(#54110): So, this setup isn't really right. I think
275-
// that (a) the librustc_ast visitor ought to be doing this as
276-
// part of `walk_mac`, and (b) we should be calling
277-
// `visit_path`, *but* that would require a `NodeId`, and I
278-
// want to get #53686 fixed quickly. -nmatsakis
279-
ast_visit::walk_path(self, &mac.path);
280-
281274
run_early_pass!(self, check_mac, mac);
275+
ast_visit::walk_mac(self, mac);
282276
}
283277
}
284278

compiler/rustc_parse/src/parser/pat.rs

-4
Original file line numberDiff line numberDiff line change
@@ -570,10 +570,6 @@ impl<'a> Parser<'a> {
570570
fn make_all_value_bindings_mutable(pat: &mut P<Pat>) -> bool {
571571
struct AddMut(bool);
572572
impl MutVisitor for AddMut {
573-
fn visit_mac(&mut self, mac: &mut MacCall) {
574-
noop_visit_mac(mac, self);
575-
}
576-
577573
fn visit_pat(&mut self, pat: &mut P<Pat>) {
578574
if let PatKind::Ident(BindingMode::ByValue(m @ Mutability::Not), ..) = &mut pat.kind
579575
{

compiler/rustc_passes/src/hir_stats.rs

+1
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
338338

339339
fn visit_mac(&mut self, mac: &'v ast::MacCall) {
340340
self.record("MacCall", Id::None, mac);
341+
ast_visit::walk_mac(self, mac)
341342
}
342343

343344
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v ast::PathSegment) {

src/tools/clippy/clippy_lints/src/non_expressive_names.rs

-6
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ impl<'a, 'tcx, 'b> Visitor<'tcx> for SimilarNamesNameVisitor<'a, 'tcx, 'b> {
149149
_ => walk_pat(self, pat),
150150
}
151151
}
152-
fn visit_mac(&mut self, _mac: &MacCall) {
153-
// do not check macs
154-
}
155152
}
156153

157154
#[must_use]
@@ -356,9 +353,6 @@ impl<'a, 'tcx> Visitor<'tcx> for SimilarNamesLocalVisitor<'a, 'tcx> {
356353
fn visit_item(&mut self, _: &Item) {
357354
// do not recurse into inner items
358355
}
359-
fn visit_mac(&mut self, _mac: &MacCall) {
360-
// do not check macs
361-
}
362356
}
363357

364358
impl EarlyLintPass for NonExpressiveNames {

0 commit comments

Comments
 (0)