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

typos inside cfg macros go undetected #5051

Open
JOE1994 opened this issue Jan 16, 2020 · 6 comments
Open

typos inside cfg macros go undetected #5051

JOE1994 opened this issue Jan 16, 2020 · 6 comments
Labels
A-lint Area: New lints T-macros Type: Issues with macros and macro expansion

Comments

@JOE1994
Copy link

JOE1994 commented Jan 16, 2020

The below program has typos inside the cfg macro call.
(feeture instead of feature)

The below program compiles without any errors, and clippy also does not print any warnings.

pub fn main() {
    if cfg!(feeture="EXT1") {
        println!("EXTRA FEATURE1 ADDED");
    }
    #[cfg(feeture="EXT2")] {
        println!("EXTRA FEATURE2 ADDED");
    }
}

cfg macro seems to be a compiler built-in macro (source code not available?).
I found this issue while debugging my Rust code.

@mati865
Copy link
Contributor

mati865 commented Jan 16, 2020

Only the "enabled" code is being checked by rustc. You should get what you expect by pressing --all-features argument to Cargo.

@JOE1994
Copy link
Author

JOE1994 commented Jan 16, 2020

I apologize for not phrasing the issue well.. I am aware that only the enabled code is checked by rustc.
The issue I wanted to talk about was that feeture is an invalid configuration option, but neither rustc nor clippy complains about it. I think either clippy or rustc could print a warning that the given configuration option feeture is not a valid one.

@flip1995
Copy link
Member

A lint with a whitelist of possible configurations would be possible. The problem is, that you can pass anything as a config through --cfg, so with rustc --cfg 'feeture="EXT1"' main.rs the code would be totally valid.

@JOE1994
Copy link
Author

JOE1994 commented Jan 16, 2020

@flip1995 I see.. Can we keep this issue open for a bit to get others' feedback also? I'm curious how others would think of this issue 😃

@vallentin
Copy link
Contributor

I'd say, have Clippy produce a warning if there's a high similarity. So if feeture is used, then Clippy should say "Are you sure you didn't mean 'feature'?", since they're highly similar.

Same with say target_familly (double L) or target_pointer_with (missing d).

@flip1995
Copy link
Member

We already do something similar with unknown_clippy_lints, so this should be quite easy to implement. We'd need a list of config options though.

@flip1995 flip1995 added A-lint Area: New lints T-macros Type: Issues with macros and macro expansion labels Jan 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints T-macros Type: Issues with macros and macro expansion
Projects
None yet
Development

No branches or pull requests

4 participants