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

Macro-expanded unconfigured items are gated feature checked #32840

Closed
jseyfried opened this issue Apr 8, 2016 · 3 comments · Fixed by #32846
Closed

Macro-expanded unconfigured items are gated feature checked #32840

jseyfried opened this issue Apr 8, 2016 · 3 comments · Fixed by #32846

Comments

@jseyfried
Copy link
Contributor

Macro-expanded unconfigured items are gated feature checked, but ordinary unconfigured items are not. For example, the following should compile, ...

#![cfg_attr(attr, feature(rustc_attrs))]

macro_rules! mac {
    {} => {
        #[cfg(attr)]
        mod m {
            #[rustc_error] // ... but if not(attr), this complains about the lack of the rustc_attrs feature
            fn f() {}
        }
    }
}

mac! {}

If we manually expand mac! {}, it always compiles:

#![cfg_attr(attr, feature(rustc_attrs))]

#[cfg(attr)]
mod m {
    #[rustc_error]
    fn f() {}
}
@jseyfried
Copy link
Contributor Author

It looks like this was intentional (introduced in #22899), but I don't think it's a good idea.
cc @nrc
cc #22250

@LeoTestard
Copy link
Contributor

There are arguments on #32648 about why this is not a good idea: #[cfg] is typically used by crates that need to build against both stable and nightly and use nightly-specific features when available (the most important example that I have in mind is syntax extensions using plugins on nightly and syntex on stable). Checking for use of gated features inside this #[cfg]-guarded code will break those crates, and it's not a good thing, this use case is actually useful. This check pass should be removed.

@nrc
Copy link
Member

nrc commented Apr 12, 2016

cc @rust-lang/lang

bors added a commit that referenced this issue Apr 30, 2016
…ems, r=nrc

Avoid gated feature checking unconfigured expanded items

Avoid gated feature checking unconfigured macro-expanded items (fixes #32840).
Unconfigured items that are not macro-expanded are already not gated feature checked.
r? @nrc
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

Successfully merging a pull request may close this issue.

3 participants