Skip to content

Functions/modules using unstable *syntax* (e.g., impl Trait) can't be CFGed out on stable #36478

@Stebalien

Description

@Stebalien

This fails on stable because rust still parses the unstable module:

#[cfg(feature = "unstable")]
mod unstable {
    fn foo() -> impl Foo {}
}

It's possible to work around this by conditionally defining a macro and then having the macro define the module but that's a bit messy:

#[cfg(feature = "unstable")]
macro_rules! decl_unstable {
    () =>  {
        mod unstable {
            fn foo() -> impl Foo {}
        }
    }
}

#[cfg(not(feature = "unstable"))]
macro_rules! decl_unstable {
    () =>  {}
}

decl_unstable!();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions