From b81f9c350fc00d8dbdc9e23c8167c29bf82be243 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sun, 5 May 2024 22:52:21 +0900 Subject: [PATCH] Ignore unexpected_cfgs lint for generated code ``` error: unexpected `cfg` condition name: `rustfmt` --> src/gen/assert_impl.rs:6:13 | 6 | #![cfg_attr(rustfmt, rustfmt::skip)] | ^^^^^^^ ``` Due to https://github.com/rust-lang/rust/issues/124735, we cannot disable this lint at module-level. --- src/lib.rs | 1 + tools/codegen/src/file.rs | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 90413c7..37b3b90 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -82,6 +82,7 @@ fn foo(secs: u64, nanos: u32, instant: Instant) -> Option { )] // docs.rs only (cfg is enabled by docs.rs, not build script) #![cfg_attr(docsrs, feature(doc_cfg))] +#![cfg_attr(test, allow(unexpected_cfgs))] // https://github.com/rust-lang/rust/issues/124735 #[cfg(doc)] extern crate self as easytime; diff --git a/tools/codegen/src/file.rs b/tools/codegen/src/file.rs index 0b9e182..42cd769 100644 --- a/tools/codegen/src/file.rs +++ b/tools/codegen/src/file.rs @@ -33,7 +33,9 @@ pub(crate) fn workspace_root() -> PathBuf { #[track_caller] pub(crate) fn header(function_name: &str) -> String { // rust-analyzer does not respect outer attribute (#[rustfmt::skip]) on - // a module without a body. So use inner attribute under cfg(rustfmt). + // a module without a body and unstable ignore option in .rustfmt.toml. + // https://github.com/rust-lang/rust-analyzer/issues/10826 + // So use inner attribute under cfg(rustfmt). format!( "// SPDX-License-Identifier: Apache-2.0 OR MIT // This file is @generated by {bin_name}