-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: Nested groups in imports #2128
Conversation
Thanks, @petrochenkov, for hopping on this! Somehow it hadn't been targeted as part of the ergonomics initiative previously. I'm very much in favor; I've wanted this syntax many, many times. There's not really a lot to critique here, so I'm going to go ahead and propose FCP, which will ping the other members of the lang team to review. @rfcbot fcp merge |
Team member @aturon has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
I had no idea |
@Ixrec yeah my thoughts exactly. Note though that the lang team still has to sign off to go into FCP, which is part of why I wanted to get the ball rolling right away. With luck, we'll be merging this in two weeks time... |
Would the following be legal under this RFC? (Without asking about if it would be desirable to use it this way although I think I like this 😅)
And, if that was legal, would it also legal without the leading Overall, I'm a big 👍 ! |
@lukaramu |
Minor thing: It looks like the grammar allows use std::mem::{*, copy}; At the grammar level that's reasonable, but should there be a lint about it? |
@scottmcm Do we currently lint on |
@scottmcm https://play.rust-lang.org/?gist=eaeded63b68e2b63d84f173fce79c832&version=nightly // use std::mem::{*, swap};
use std::mem::*; // WARN unused import: `std::mem::*;`
use std::mem::swap;
fn main() {
let mut x = 0;
let mut y = 0;
swap(&mut x, &mut y);
} https://play.rust-lang.org/?gist=5d9069fe10d07f8a3046d5a9bc82ecce&version=nightly // use std::mem::{*, *};
use std::mem::*;
use std::mem::*; // WARN unused import: `std::mem::*;`
fn main() {
let mut x = 0;
let mut y = 0;
swap(&mut x, &mut y);
} |
IIRC how name resolution works, that's not even a useless thing to do, because if you have multiple glob imports, the explicit import of |
Yep, that's a valid use case too. In general, the "don't think, desugar" seems like a reasonable approach because If some imports look suspicious in "merged" form, then they should be reported in "unmerged" form as well. |
I second @petrochenkov that simple desugarings help users form the intuition that "it's just a shorthand", and for refactoring the transformation is simpler for both humans and tools. |
I'm pretty strongly against importing from multiple crates with a single use statements and I'd like us to consider it unidiomatic. But it makes sense for it to be allowed technically. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
1 similar comment
🔔 This is now entering its final comment period, as per the review above. 🔔 |
text/0000-use-nested-groups.md
Outdated
use syntax::ast::*; | ||
|
||
use rustc::mir::*; | ||
use rustc::transform::{MirPass, MirSource}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small correction: here the path should be rustc::mir::transform::{MirPass, MirSource}
.
The RFC is jolly good as it stands, but I am tempted to ask: are there obvious reasons not allow this in re-exports? As in pub use module::this_here_fn;
pub use module::yonder::{Struct, Trait};
pub use module::yonder::window::*; becoming pub use module::{
this_here_fn,
yonder::{Struct, Trait, window::*},
}; Such "re-export lists" would work nicely with the façade pattern. Moreover, once nested imports land on stable, it would feel rather inconsistent to have |
@tapeinosyne I don't see anything in this RFC that explicitly restricts this from working with visibility modifiers, so I don't see why your example wouldn't work when this RFC is eventually implemented. Might be worth clarifying in the RFC that this feature can be combined with visibility modifiers just fine. |
@retep998 Explicitly restricts, no. Carefully avoids mentioning, yes. Imports and imports only are explicitly mentioned in the title, the examples, and the syntax section of the Reference-level explanation. (As I understand, Besides, re-export lists look a bit like a little zombie hand sticking out of the grave of export lists long gone, which may unduly faze some… |
@tapeinosyne It may be worth calling out explicitly, but I guarantee given the author that this was assumed to cover |
The grammar explicitly contains visibilities, but I should make it more prominent, yes. |
Oh, you are right. Apologies, I must have missed that. |
👍 from me. It's not something that's used often, but there are some common patterns that it makes prettier / less painful to write, and (probably) doesn't add too much complexity to the import system. One example that always annoys me is use std::io;
use std::io::prelude::*; which can now be simply use std::io::{self, prelude::*}; |
The final comment period is now complete. |
This RFC has been merged! Tracking issue. Thanks @petrochenkov! |
Add nested groups in imports This PR adds support for nested groups in imports (rust-lang/rfcs#2128, tracking issue #44494). r? @petrochenkov
This is an incremental improvement to syntax of imports.
With this RFC groups inside of braces
{}
in imports can be nestedand globs
*
can be placed into groups as wellCloses #1400
Closes #1290
Rendered