-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Inconsistent warning for macros that contain unexpected_cfgs #132572
Copy link
Copy link
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.L-unexpected_cfgsLint: unexpected_cfgsLint: unexpected_cfgsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.L-unexpected_cfgsLint: unexpected_cfgsLint: unexpected_cfgsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Type
Fields
Give feedbackNo fields configured for issues without a type.
Problem
Hi, I recently encountered an inconsistent behavior of
cargo checkwhen I have a macro which expands to something withunexpected_cfgs.In short, I have a macro definition that expand to something with
#[cfg(feature = "my_feature")]. Whenmy_featureis not declared inCargo.tomlof my crate, I expectedunexpected_cfgsto be reported whenever I use this macro.However, whenever I use this macro in a downstream project (which also doesn't declare
my_feature), no warning reported.I originally thought this was a rust-analyzer problem, but after the discussion in rust-lang/rust-analyzer#18461, it seems this is more relevant to cargo.
I would like to understand if this is the expected behavior, because it feels like a bug to me.
Steps
mylib, andmylib/lib.rshascargo check --tests, I got the expected warning:mylibin other packages, say I have another crate,myapp, that depends onmylib.In
myapp/main.rs, I have:cargo checkonmyappreports nothing.Possible Solution(s)
No response
Notes
No response
Version
cargo 1.82.0 (8f40fc59f 2024-08-21)
release: 1.82.0
commit-hash: 8f40fc59fb0c8df91c97405785197f3c630304ea
commit-date: 2024-08-21
host: x86_64-apple-darwin
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.6.0 (sys:0.4.74+curl-8.9.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 1.1.1w 11 Sep 2023
os: Mac OS 14.5.0 [64-bit]