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

#[cfg(unknown_option = "...") should produce a warning #39370

Closed
Wilfred opened this issue Jan 28, 2017 · 4 comments
Closed

#[cfg(unknown_option = "...") should produce a warning #39370

Wilfred opened this issue Jan 28, 2017 · 4 comments

Comments

@Wilfred
Copy link
Contributor

Wilfred commented Jan 28, 2017

The rust reference https://doc.rust-lang.org/reference.html#conditional-compilation states:

contains a string that can be checked against (#[cfg(bar = "baz")]). Currently, only compiler-defined configuration options can have the latter form.

Given that there's a fixed list of options, could rustc warn on invalid options? The following code compiles with no warnings:

#[cfg(i_dont_exist = "foo")]
extern crate bar;

fn main() {
}

This caught me out today when I wrote target = "macos" rather than target_os = "macos".

@durka
Copy link
Contributor

durka commented Jan 28, 2017

Hmm, that line in the reference is a total lie.

$ rustc xx.rs --cfg 'i_dont_exist="foo"'
error[E0463]: can't find crate for `bar`
 --> xx.rs:2:1
  |
2 | extern crate bar;
  | ^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to previous error

@Wilfred
Copy link
Contributor Author

Wilfred commented Jan 28, 2017

Ah, sounds like I'm doomed and there's no way to warn on invalid option names. I will close this issue if there's nothing we can do to improve this.

@retep998
Copy link
Member

There is something we can do. We can update the documentation so it no longer states "Currently, only compiler-defined configuration options can have the latter form."

@durka
Copy link
Contributor

durka commented Jan 28, 2017

The reference should be fixed or we should add a warning, one or the other.

frewsxcv added a commit to frewsxcv/rust that referenced this issue Feb 8, 2017
reference: clarify #[cfg] section

Closes rust-lang#39370, but maybe we (or clippy) should add a warning too.
frewsxcv added a commit to frewsxcv/rust that referenced this issue Feb 8, 2017
reference: clarify #[cfg] section

Closes rust-lang#39370, but maybe we (or clippy) should add a warning too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants