Skip to content

libsyntax visitor does not visit the paths in macros #54110

Closed
@nikomatsakis

Description

@nikomatsakis

It's a minor point, but the macro struct includes a path:

rust/src/libsyntax/ast.rs

Lines 1223 to 1228 in 551244f

#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Mac_ {
pub path: Path,
pub delim: MacDelimiter,
pub tts: ThinTokenStream,
}

However, the walk_mac helper just ignores this completely:

rust/src/libsyntax/visit.rs

Lines 650 to 652 in 551244f

pub fn walk_mac<'a, V: Visitor<'a>>(_: &mut V, _: &Mac) {
// Empty!
}

As a result — well, a partial result — the early lint checker just ignores this path altogether (in particular, visit_path is never invoked, and hence check_path and friends are not invoked):

fn visit_mac(&mut self, mac: &'a ast::Mac) {
run_lints!(self, check_mac, mac);
}

This was a contributing factor to #53686.

I say that this is a "partial result" because the early lint checker never calls walk_mac -- but, really, it ought to. And, if it did, and walk_mac did what it was supposed to do and walked all the subparts, then everything would be fine.

Adding a hacky fix for now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-cleanupCategory: PRs that clean code up or issues documenting cleanup.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions