Skip to content

features_check/error.rs interferes with static analysis #1123

Closed
@mleonhard

Description

@mleonhard

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");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions