Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

features_check/error.rs interferes with static analysis #1123

Closed
mleonhard opened this issue Apr 15, 2024 · 0 comments · Fixed by #1124
Closed

features_check/error.rs interferes with static analysis #1123

mleonhard opened this issue Apr 15, 2024 · 0 comments · Fixed by #1124

Comments

@mleonhard
Copy link
Contributor

mleonhard commented Apr 15, 2024

The file exists to trigger a compiler error when the user uses an invalid combination of features:

"serde_json requires that either `std` (default) or `alloc` feature is enabled"

#[cfg(not(any(feature = "std", feature = "alloc")))]
hide_from_rustfmt! {
mod error;
}

The invalid code interferes with static analysis tools like cargo-geiger:

$ cargo-geiger --version
cargo-geiger 0.11.7
$ cargo geiger
...
Failed to parse file: /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde_json-1.0.115/src/features_check/error.rs, Syn(Error("expected one of: `fn`, `extern`, `use`, `static`, `const`, `unsafe`, `mod`, `type`, `struct`, `enum`, `union`, `trait`, `auto`, `impl`, `default`, `macro`, identifier, `self`, `super`, `crate`, `::`"), "/Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde_json-1.0.115/src/features_check/error.rs") 
...

Let replace the invalid code with a call to the std::compile_error! macro:

#[cfg(not(any(feature = "std", feature = "alloc")))] 
compile_error!("serde_json requires that either `std` (default) or `alloc` feature is enabled");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant