-
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
use_group_as RFC #1219
Merged
Merged
use_group_as RFC #1219
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
- Feature Name: use_group_as | ||
- Start Date: 2015-02-15 | ||
- RFC PR: (leave this empty) | ||
- Rust Issue: (leave this empty) | ||
|
||
# Summary | ||
|
||
Allow renaming imports when importing a group of symbols from a module. | ||
|
||
```rust | ||
use std::io::{ | ||
Error as IoError, | ||
Result as IoResult, | ||
Read, | ||
Write | ||
} | ||
``` | ||
|
||
# Motivation | ||
|
||
THe current design requires the above example to be written like this: | ||
|
||
```rust | ||
use std::io::Error as IoError; | ||
use std::io::Result as IoResult; | ||
use std::io::{Read, Write}; | ||
``` | ||
|
||
It's unfortunate to duplicate `use std::io::` on the 3 lines, and the proposed | ||
example feels logical, and something you reach for in this instance, without | ||
knowing for sure if it worked. | ||
|
||
# Detailed design | ||
|
||
The current grammar for use statements is something like: | ||
|
||
``` | ||
use_decl : "pub" ? "use" [ path "as" ident | ||
| path_glob ] ; | ||
|
||
path_glob : ident [ "::" [ path_glob | ||
| '*' ] ] ? | ||
| '{' path_item [ ',' path_item ] * '}' ; | ||
|
||
path_item : ident | "self" ; | ||
``` | ||
|
||
This RFC proposes changing the grammar to something like: | ||
|
||
``` | ||
use_decl : "pub" ? "use" [ path [ "as" ident ] ? | ||
| path_glob ] ; | ||
|
||
path_glob : ident [ "::" [ path_glob | ||
| '*' ] ] ? | ||
| '{' path_item [ ',' path_item ] * '}' ; | ||
|
||
path_item : ident [ "as" ident] ? | ||
| "self" [ "as" ident]; | ||
``` | ||
|
||
The `"as" ident` part is optional in each location, and if omitted, it is expanded | ||
to alias to the same name, e.g. `use foo::{bar}` expands to `use foo::{bar as bar}`. | ||
|
||
This includes being able to rename `self`, such as `use std::io::{self | ||
as stdio, Result as IoResult};`. | ||
|
||
# Drawbacks | ||
|
||
# Alternatives | ||
|
||
# Unresolved Questions |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
s/THe/The/
(unless it's intentional for some strange reason which I'm guessing it isn't)