Skip to content

register_late_mod_pass doesn't visit all attributes #115571

@Alexendoo

Description

@Alexendoo
Member

I was testing using per module passes (like #113734) in Clippy and saw test failures when trying clippy::allow_attributes, it seems only inner attributes of the root crate are visited by per module late lint passes

Reproducer without having to compile clippy:

diff --git i/compiler/rustc_lint/src/for_loops_over_fallibles.rs w/compiler/rustc_lint/src/for_loops_over_fallibles.rs
index c299e38842a..47595bcba77 100644
--- i/compiler/rustc_lint/src/for_loops_over_fallibles.rs
+++ w/compiler/rustc_lint/src/for_loops_over_fallibles.rs
@@ -80,6 +80,10 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
             ForLoopsOverFalliblesDiag { article, ty, sub, question_mark, suggestion },
         );
     }
+
+    fn check_attribute(&mut self, _: &LateContext<'_>, attr: &'_ rustc_ast::Attribute) {
+        dbg!(attr.span);
+    }
 }
 
 fn extract_for_loop<'tcx>(expr: &Expr<'tcx>) -> Option<(&'tcx Pat<'tcx>, &'tcx Expr<'tcx>)> {

Compile + run rustc on

#![warn(clippy::a)]

#[warn(clippy::b)]
pub struct B;

pub mod m {
    #![warn(clippy::c)]

    #[warn(clippy::d)]
    pub struct D;
}

fn main() {}

You'll see only one attribute in the output

[compiler/rustc_lint/src/for_loops_over_fallibles.rs:85] attr.span = foo.rs:1:1: 1:20 (#0)

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Sep 5, 2023
added a commit that references this issue on Sep 11, 2023
fd2809f
added a commit that references this issue on Sep 11, 2023
b829a5f
added a commit that references this issue on Sep 11, 2023
d24f575
added a commit that references this issue on Sep 11, 2023
3dcb681
removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @Alexendoo@apiraino@rustbot

      Issue actions

        `register_late_mod_pass` doesn't visit all attributes · Issue #115571 · rust-lang/rust