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
clarfon opened this Issue May 5, 2017 · 7 comments

Comments

Projects
None yet
6 participants
@clarfon
Copy link
Contributor

clarfon commented May 5, 2017

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

This comment has been minimized.

Copy link
Contributor

SimonSapin commented May 5, 2017

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 label May 14, 2017

@scottmcm

This comment has been minimized.

Copy link
Member

scottmcm commented Jun 29, 2017

@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};
}
@clarfon

This comment has been minimized.

Copy link
Contributor Author

clarfon commented Jun 29, 2017

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.

@ubsan

This comment has been minimized.

Copy link
Contributor

ubsan commented Jun 29, 2017

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

@clarfon

This comment has been minimized.

Copy link
Contributor Author

clarfon commented Jun 29, 2017

@ubsan wait, is that actually allowed? huh.

@ubsan

This comment has been minimized.

Copy link
Contributor

ubsan commented Jun 30, 2017

@Centril

This comment has been minimized.

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 Apr 26, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.