Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upRFC: Nested groups in imports #2128
Conversation
petrochenkov
added
Ergonomics Initiative
T-lang
labels
Aug 25, 2017
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Aug 25, 2017
•
|
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. |
rfcbot
added
the
proposed-final-comment-period
label
Aug 25, 2017
This comment has been minimized.
This comment has been minimized.
|
I had no idea |
This comment has been minimized.
This comment has been minimized.
|
@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... |
aturon
self-assigned this
Aug 25, 2017
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
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? |
This comment has been minimized.
This comment has been minimized.
|
@scottmcm Do we currently lint on |
This comment has been minimized.
This comment has been minimized.
|
@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);
} |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
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. |
cramertj
referenced this pull request
Aug 29, 2017
Merged
RFC: Clarify and streamline paths and visibility #2126
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Aug 30, 2017
|
|
1 similar comment
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Aug 30, 2017
|
|
rfcbot
added
final-comment-period
and removed
proposed-final-comment-period
labels
Aug 30, 2017
tapeinosyne
reviewed
Sep 2, 2017
| use syntax::ast::*; | ||
| use rustc::mir::*; | ||
| use rustc::transform::{MirPass, MirSource}; |
This comment has been minimized.
This comment has been minimized.
tapeinosyne
Sep 2, 2017
•
Small correction: here the path should be rustc::mir::transform::{MirPass, MirSource}.
This comment has been minimized.
This comment has been minimized.
tapeinosyne
commented
Sep 2, 2017
•
|
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 |
This comment has been minimized.
This comment has been minimized.
|
@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. |
This comment has been minimized.
This comment has been minimized.
tapeinosyne
commented
Sep 2, 2017
•
|
@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… |
This comment has been minimized.
This comment has been minimized.
|
@tapeinosyne It may be worth calling out explicitly, but I guarantee given the author that this was assumed to cover |
This comment has been minimized.
This comment has been minimized.
The grammar explicitly contains visibilities, but I should make it more prominent, yes. |
This comment has been minimized.
This comment has been minimized.
tapeinosyne
commented
Sep 2, 2017
Oh, you are right. Apologies, I must have missed that. |
This comment has been minimized.
This comment has been minimized.
crumblingstatue
commented
Sep 6, 2017
|
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::*}; |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Sep 9, 2017
|
The final comment period is now complete. |
aturon
referenced this pull request
Sep 11, 2017
Closed
Tracking issue for RFC 2128: Nested groups in imports #44494
This comment has been minimized.
This comment has been minimized.
|
This RFC has been merged! Tracking issue. Thanks @petrochenkov! |
petrochenkov commentedAug 25, 2017
•
edited
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