Skip to content

Commit 6606d0e

Browse files
committed
Auto merge of rust-lang#132577 - Urgau:check-cfg-report-extern-macro, 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
2 parents 303fc05 + 37e67ac commit 6606d0e

File tree

6 files changed

+46
-8
lines changed

6 files changed

+46
-8
lines changed

Diff for: Cargo.lock

+7-7
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ dependencies = [
112112

113113
[[package]]
114114
name = "anstream"
115-
version = "0.6.15"
115+
version = "0.6.18"
116116
source = "registry+https://github.com/rust-lang/crates.io-index"
117-
checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526"
117+
checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b"
118118
dependencies = [
119119
"anstyle",
120120
"anstyle-parse",
@@ -173,12 +173,12 @@ dependencies = [
173173

174174
[[package]]
175175
name = "anstyle-wincon"
176-
version = "3.0.4"
176+
version = "3.0.6"
177177
source = "registry+https://github.com/rust-lang/crates.io-index"
178-
checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8"
178+
checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125"
179179
dependencies = [
180180
"anstyle",
181-
"windows-sys 0.52.0",
181+
"windows-sys 0.59.0",
182182
]
183183

184184
[[package]]
@@ -1991,7 +1991,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
19911991
checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4"
19921992
dependencies = [
19931993
"cfg-if",
1994-
"windows-targets 0.52.6",
1994+
"windows-targets 0.48.5",
19951995
]
19961996

19971997
[[package]]
@@ -5928,7 +5928,7 @@ version = "0.1.9"
59285928
source = "registry+https://github.com/rust-lang/crates.io-index"
59295929
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
59305930
dependencies = [
5931-
"windows-sys 0.59.0",
5931+
"windows-sys 0.48.0",
59325932
]
59335933

59345934
[[package]]

Diff for: compiler/rustc_lint_defs/src/builtin.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3184,6 +3184,7 @@ declare_lint! {
31843184
pub UNEXPECTED_CFGS,
31853185
Warn,
31863186
"detects unexpected names and values in `#[cfg]` conditions",
3187+
report_in_external_macro
31873188
}
31883189

31893190
declare_lint! {

Diff for: tests/ui/check-cfg/auxiliary/cfg_macro.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Inspired by https://github.com/rust-lang/cargo/issues/14775
2+
3+
pub fn my_lib_func() {}
4+
5+
#[macro_export]
6+
macro_rules! my_lib_macro {
7+
() => {
8+
#[cfg(my_lib_cfg)]
9+
$crate::my_lib_func()
10+
};
11+
}

Diff for: tests/ui/check-cfg/report-in-external-macros.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// This test checks that we emit the `unexpected_cfgs` lint even in code
2+
// coming from an external macro.
3+
4+
//@ check-pass
5+
//@ no-auto-check-cfg
6+
//@ aux-crate: cfg_macro=cfg_macro.rs
7+
//@ compile-flags: --check-cfg=cfg()
8+
9+
fn main() {
10+
cfg_macro::my_lib_macro!();
11+
//~^ WARNING unexpected `cfg` condition name
12+
}

Diff for: tests/ui/check-cfg/report-in-external-macros.stderr

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
warning: unexpected `cfg` condition name: `my_lib_cfg`
2+
--> $DIR/report-in-external-macros.rs:10:5
3+
|
4+
LL | cfg_macro::my_lib_macro!();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: expected names are: `clippy`, `debug_assertions`, `doc`, `doctest`, `fmt_debug`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `ub_checks`, `unix`, and `windows`
8+
= help: to expect this configuration use `--check-cfg=cfg(my_lib_cfg)`
9+
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
10+
= note: `#[warn(unexpected_cfgs)]` on by default
11+
= note: this warning originates in the macro `cfg_macro::my_lib_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
12+
13+
warning: 1 warning emitted
14+

0 commit comments

Comments
 (0)