Skip to content

Lint suggestion: undeclared_feature #5660

Closed
@pscott

Description

@pscott

Hi,

This issue suggests a new lint: undeclared_feature. I tried following the guidelines, but feel free to change the name obviously.

Take a fresh Cargo.toml file and add time as an optional dependency. Now write this code:

#[cfg(feature=time)]
fn main() {
  println!("foo");
}

#[cfg(not(feature=time))]
fn main() {
  println!("bar");
}

You can then run:

$ cargo run
bar

and

$ cargo run --features time
foo

I believe this is bad practice because this code effectively has a "hidden" feature, which should probably be documented and exposed via the Cargo.toml file. What do you think? Is this good / bad practice, and would a clippy lint be appropriate?

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