Skip to content

Missing warning when applying #[path = "..."] to a inline module #133907

@cyrgani

Description

@cyrgani

Code

#[path = "bar.rs"]
pub mod foo {}

Current output

no output

Desired output

warning: `#[path]` only has an effect on modules without bodies
 --> src/lib.rs:1:1
  |
1 | #[path = "bar.rs"]
  | ^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_attributes)]` on by default

Rationale and extra context

A similar warning exists for other misuses of the attribute, like

#[path = "bar.rs"]
pub struct Foo;

(IMO, this misuse should eventually become a hard error, but that's not the point of this issue.)

Other cases

Rust Version

rustc 1.85.0-nightly (d49be02cf 2024-12-02)
binary: rustc
commit-hash: d49be02cf6d2e2a01264fcdef1e20c826710c0f5
commit-date: 2024-12-02
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.4

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.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