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(...)] ignores namespace #53489

Closed
kennytm opened this issue Aug 19, 2018 · 6 comments
Closed

#[cfg(...)] ignores namespace #53489

kennytm opened this issue Aug 19, 2018 · 6 comments

Comments

@kennytm
Copy link
Member

kennytm commented Aug 19, 2018

Repro:

fn main() {
    println!("           cfg(a) = {}", cfg!(a));
    println!("cfg(something::a) = {}", cfg!(something::a));
}
$ rustc --cfg 'a' 1.rs && ./1
           cfg(a) = true
cfg(something::a) = true

$ rustc --cfg 'something::a' 1.rs && ./1
           cfg(a) = true
cfg(something::a) = true

$ rustc --cfg 'what::a' 1.rs && ./1
           cfg(a) = true
cfg(something::a) = true

while I expected these should print true/false, false/true and false/false instead.

(Note: this also affects --print cfg which something::a is collapsed to a)

cc @petrochenkov @eddyb


$ rustc -vV
rustc 1.30.0-nightly (33b923fd4 2018-08-18)
binary: rustc
commit-hash: 33b923fd44c5c5925e635815fce68bdf1f98740f
commit-date: 2018-08-18
host: x86_64-apple-darwin
release: 1.30.0-nightly
LLVM version: 7.0
@eddyb
Copy link
Member

eddyb commented Aug 19, 2018

What happens if you also have cfg(a), does that interact with cfg(something::a)?

@kennytm kennytm changed the title --print=cfg ignores namespace cfg(...) ignores namespace Aug 19, 2018
@kennytm kennytm changed the title cfg(...) ignores namespace #[cfg(...)] ignores namespace Aug 19, 2018
@kennytm
Copy link
Member Author

kennytm commented Aug 19, 2018

@eddyb Oh no, cfg(something::a) is the same as cfg(a). Edited the issue.

@kennytm
Copy link
Member Author

kennytm commented Aug 19, 2018

This behavior exists since 1.27. On 1.26 or before, #[cfg(module::path)] is simply a syntax error.

@petrochenkov
Copy link
Contributor

This looks like an unintended side-effect of #50030 that allowed arbitrary paths in meta-items (including nested ones), but fn name() for meta-items still returns the last segment ignoring everything else.
cc @flip1995 @topecongiro

Most of attributes, including cfg want nested meta-item paths to be single-segment.
So, looks like fn name should return Option<Name> and all its callers need to be taught to deal with None somehow - report an error, or pass it further, etc.

@eddyb
Copy link
Member

eddyb commented Aug 19, 2018

I'd suggest having a flag on "meta-item parsing" to say whether it should allow paths at all - most of the builtin attributes don't need paths.

@petrochenkov
Copy link
Contributor

The cfg issue specifically was fixed in #53893.

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