Skip to content

Macro-expanded unconfigured items are gated feature checked #32840

Closed

Description

@jseyfried

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() {}
}

Activity

  1. jseyfried commented on Apr 8, 2016

    @jseyfried
    ContributorAuthor

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

  2. LeoTestard commented on Apr 9, 2016

    @LeoTestard
    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.

  3. nrc commented on Apr 12, 2016

    @nrc
    Member

    cc @rust-lang/lang

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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