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

Blocks for items #1991

Closed
clarfonthey opened this issue May 5, 2017 · 7 comments
Closed

Blocks for items #1991

clarfonthey opened this issue May 5, 2017 · 7 comments
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.

Comments

@clarfonthey
Copy link

It'd be really nice if we could do something like:

#[cfg(feature = "abc")]
{
    extern crate x;
    extern crate y;
    mod z;
    use z::{a, b, c};
}

Right now, we have to attach the attribute to every item, which is a bit redundant. We can put things in a module and then re-export them, but it'd be nice if we could do something like this instead.

@SimonSapin
Copy link
Contributor

With https://github.com/alexcrichton/cfg-if you can make it look like:

#[macro_use] extern crate cfg_if;

cfg_if! {
    if #[cfg(feature = "abc")] {
        extern crate x;
        extern crate y;
        mod z;
        use z::{a, b, c};
    }
}

@withoutboats withoutboats added the T-lang Relevant to the language team, which will review and decide on the RFC. label May 14, 2017
@scottmcm
Copy link
Member

@withoutboats Would anonymous modules do this? As something like

#[cfg(feature = "abc")]
mod {
    extern crate x;
    extern crate y;
    mod z;
    use z::{a, b, c};
}

@clarfonthey
Copy link
Author

I considered anonymous modules, but the main issue is that things like extern crate, etc. wouldn't semantically fit in a module. It could work, though.

@strega-nil
Copy link

@clarcharr it's actually a pattern, albeit an uncommon one, to put extern crates in submodules.

@clarfonthey
Copy link
Author

@ubsan wait, is that actually allowed? huh.

@strega-nil
Copy link

@Centril
Copy link
Contributor

Centril commented Apr 26, 2018

I think this is #2377 so I'm closing in favor of that.

@Centril Centril closed this as completed Apr 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

6 participants