From b032d5db2db007ba927879371222ac00dd373ee2 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Sun, 15 Feb 2015 20:13:51 -0800 Subject: [PATCH 1/2] use_group_as RFC --- text/0000-use-group-as.md | 72 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 text/0000-use-group-as.md diff --git a/text/0000-use-group-as.md b/text/0000-use-group-as.md new file mode 100644 index 00000000000..de1231f1641 --- /dev/null +++ b/text/0000-use-group-as.md @@ -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" ; +``` + +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}`. + +# Drawbacks + +# Alternatives + +# Unresolved questions + +- **Should `self` also be aliasable?** So you could write `use foo::{self as xfoo, bar}`. + From d0e72a744fc40b2fd3f6fcf22fdc460fc457e3a1 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Wed, 22 Jul 2015 11:08:25 -0700 Subject: [PATCH 2/2] include renaming 'self' in a group import --- text/0000-use-group-as.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/text/0000-use-group-as.md b/text/0000-use-group-as.md index de1231f1641..1977175bbd8 100644 --- a/text/0000-use-group-as.md +++ b/text/0000-use-group-as.md @@ -56,17 +56,17 @@ This RFC proposes changing the grammar to something like: | '{' path_item [ ',' path_item ] * '}' ; path_item : ident [ "as" ident] ? - | "self" ; + | "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 - -- **Should `self` also be aliasable?** So you could write `use foo::{self as xfoo, bar}`. - +# Unresolved Questions