Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
cyrgani opened this issue Dec 5, 2024 · 1 comment
Closed

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

cyrgani opened this issue Dec 5, 2024 · 1 comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cyrgani
Copy link
Contributor

cyrgani commented Dec 5, 2024

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

@cyrgani cyrgani added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 5, 2024
@fmease fmease added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. and removed A-diagnostics Area: Messages for errors, warnings, and lints labels Dec 5, 2024
@jieyouxu jieyouxu self-assigned this Dec 6, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Dec 6, 2024

Actually, AFAICT, this is intentional as per the Reference on path attribute.

In particular,

An example of combining the above rules of path attributes on inline modules and nested modules within (applies to both mod-rs and non-mod-rs files):

#[path = "thread_files"]
mod thread {
   // Load the `local_data` module from `thread_files/tls.rs` relative to
    // this source file's directory.
    #[path = "tls.rs"]
    mod local_data;
}

This is a duplicate of #13156. I only found out when I tried to make this warn and some tests failed (good).

@jieyouxu jieyouxu closed this as completed Dec 6, 2024
@jieyouxu jieyouxu removed their assignment Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants