-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Inconsistent warning for macros that contain unexpected_cfgs
#132572
Comments
unexpected_cfgs
It doesn't need to have multiple Cargo packages. Simply a This also applies to some simpler lints like However, if you change the macro content to warning: unused bitwise operation that must be used
--> src/main.rs:3:5
|
3 | foo::my_macro!();
| ^^^^^^^^^^^^^^^^ the bitwise operation produces a value
|
= note: `#[warn(unused_must_use)]` on by default
= note: this warning originates in the macro `foo::my_macro` (in Nightly builds, run with -Z macro-backtrace for more info) Despite that, you won't get the error: this arithmetic operation will overflow
--> src/lib.rs:4:9
|
4 | 1_i32 << 32;
| ^^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow
...
11 | my_macro!();
| ----------- in this macro invocation
|
= note: `#[deny(arithmetic_overflow)]` on by default
= note: this error originates in the macro `my_macro` (in Nightly builds, run with -Z macro-backtrace for more info) I feel like this behavior pretty much depends on how the lint is implemented, though not a lint wizard so may need experts to answer this. cc @Urgau do you happen to know how |
I'm pretty sure this is because we (the compiler) don't (in general) show warnings coming from external macro, and the This is done to avoid awkward warnings where the users can't do anything about the warnings. In the case of the |
I'm transferring this issue to main Rust repo, as it's an issue with compiler.
|
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Enable transfer feature in triagebot This PR enables the `transfer` feature from triagebot, it permits issue transfers within the org. Documentation at: https://forge.rust-lang.org/triagebot/transfer.html It would have been useful in rust-lang/rust#132572 (comment) r? `@ehuss`
…o, r=petrochenkov Report the `unexpected_cfgs` lint in external macros This PR marks the `unexpected_cfgs` lint as being reportable in external macros, as it's probably not the intention of the macro author to leave ineffective cfgs in the users code. Fixes rust-lang#132572
… r=<try> Report the `unexpected_cfgs` lint in external macros This PR marks the `unexpected_cfgs` lint as being reportable in external macros, as it's probably not the intention of the macro author to leave ineffective cfgs in the users code. Fixes rust-lang#132572 try-job: aarch64-gnu-debug
… r=<try> Report the `unexpected_cfgs` lint in external macros This PR marks the `unexpected_cfgs` lint as being reportable in external macros, as it's probably not the intention of the macro author to leave ineffective cfgs in the users code. Fixes rust-lang#132572 try-job: aarch64-gnu-debug
…o, r=petrochenkov Report the `unexpected_cfgs` lint in external macros This PR marks the `unexpected_cfgs` lint as being reportable in external macros, as it's probably not the intention of the macro author to leave ineffective cfgs in the users code. Fixes rust-lang#132572 try-job: aarch64-gnu-debug
Rollup merge of rust-lang#132577 - Urgau:check-cfg-report-extern-macro, r=petrochenkov Report the `unexpected_cfgs` lint in external macros This PR marks the `unexpected_cfgs` lint as being reportable in external macros, as it's probably not the intention of the macro author to leave ineffective cfgs in the users code. Fixes rust-lang#132572 try-job: aarch64-gnu-debug
Problem
Hi, I recently encountered an inconsistent behavior of
cargo check
when 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_feature
is not declared inCargo.toml
of my crate, I expectedunexpected_cfgs
to 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.rs
hascargo check --tests
, I got the expected warning:mylib
in other packages, say I have another crate,myapp
, that depends onmylib
.In
myapp/main.rs
, I have:cargo check
onmyapp
reports 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]
The text was updated successfully, but these errors were encountered: