Skip to content

Commit

Permalink
Ignore unexpected_cfgs lint for generated code
Browse files Browse the repository at this point in the history
```
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 <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> 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 <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> 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 <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
```

Due to rust-lang/rust#124735, we cannot
disable this lint at module-level.
  • Loading branch information
taiki-e committed May 5, 2024
1 parent 851f165 commit 404a0f7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion tools/codegen/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 404a0f7

Please sign in to comment.