From 404a0f7106bed0b1ad2e9a0d1f8f167500bfae41 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sun, 5 May 2024 23:42:48 +0900 Subject: [PATCH] Ignore unexpected_cfgs lint for generated code ``` error: unexpected `cfg` condition name: `rustfmt` --> src/gen/ast_struct.rs:6:13 | 6 | #![cfg_attr(rustfmt, rustfmt::skip)] | ^^^^^^^ | = 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 for more information about checking conditional configuration error: unexpected `cfg` condition name: `rustfmt` --> src/gen/ast_enum.rs:6:13 | 6 | #![cfg_attr(rustfmt, rustfmt::skip)] | ^^^^^^^ | = 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 for more information about checking conditional configuration error: unexpected `cfg` condition name: `rustfmt` --> src/gen/convert.rs:6:13 | 6 | #![cfg_attr(rustfmt, rustfmt::skip)] | ^^^^^^^ | = 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 for more information about checking conditional configuration ``` 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 84141c0..d866b98 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -130,6 +130,7 @@ The data structures of syn-serde 0.3 is compatible with the data structures of )] // docs.rs only (cfg is enabled by docs.rs, not build script) #![cfg_attr(docsrs, feature(doc_cfg))] +#![allow(unexpected_cfgs)] // https://github.com/rust-lang/rust/issues/124735 #[macro_use] mod macros; diff --git a/tools/codegen/src/file.rs b/tools/codegen/src/file.rs index a468532..6639bef 100644 --- a/tools/codegen/src/file.rs +++ b/tools/codegen/src/file.rs @@ -31,7 +31,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}