Skip to content

#![allow(unexpected_cfgs)] does not work for modules #124735

Open
@taiki-e

Description

@taiki-e

I tried this code:

// lib.rs
mod a;
// a.rs
#![allow(unexpected_cfgs)] // for cfg(rustfmt)
#![cfg_attr(rustfmt, rustfmt::skip)]

I expected to see this happen: no warning

Instead, this happened: #![allow(unexpected_cfgs)] is ignored:

warning: unexpected `cfg` condition name: `rustfmt`
 --> src/a.rs:2:13
  |
2 | #![cfg_attr(rustfmt, rustfmt::skip)]
  |             ^^^^^^^
  |
  = help: expected names are: `clippy`, `debug_assertions`, `doc`, `docsrs`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `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`, `windows`
  = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(rustfmt)");` to the top of the `build.rs`
  = note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
  = note: `#[warn(unexpected_cfgs)]` on by default

Even if adding #[allow(unexpected_cfgs)] to mod a;, the result is the same.

cc @Urgau

Meta

rustc --version --verbose:

rustc 1.80.0-nightly (e82c861d7 2024-05-04)
binary: rustc
commit-hash: e82c861d7e5ecd766cb0dab0bf622445dec999dc
commit-date: 2024-05-04
host: aarch64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.F-check-cfg--check-cfgL-unexpected_cfgsLint: unexpected_cfgsS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-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