Skip to content

Commit 1c16acc

Browse files
committed
libsyntax: Accept use foo as bar; in lieu of use bar as foo;
The old syntax will be removed after a snapshot. RFC #47. Issue #16461.
1 parent 404978e commit 1c16acc

29 files changed

+51
-43
lines changed

src/doc/rust.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ extern crate foo = "some/where/rust-foo#foo:1.0"; // a full crate ID for externa
919919
##### Use declarations
920920

921921
~~~~ {.ebnf .gram}
922-
use_decl : "pub" ? "use" [ ident '=' path
922+
use_decl : "pub" ? "use" [ path "as" ident
923923
| path_glob ] ;
924924
925925
path_glob : ident [ "::" [ path_glob
@@ -939,7 +939,7 @@ module item. These declarations may appear at the top of [modules](#modules) and
939939
940940
Use declarations support a number of convenient shortcuts:
941941

942-
* Rebinding the target name as a new local name, using the syntax `use x = p::q::r;`.
942+
* Rebinding the target name as a new local name, using the syntax `use p::q::r as x;`.
943943
* Simultaneously binding a list of paths differing only in their final element,
944944
using the glob-like brace syntax `use a::b::{c,d,e,f};`
945945
* Binding all paths matching a given prefix, using the asterisk wildcard syntax `use a::b::*;`

src/libsyntax/ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,11 +1114,11 @@ pub type ViewPath = Spanned<ViewPath_>;
11141114
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
11151115
pub enum ViewPath_ {
11161116

1117-
/// `quux = foo::bar::baz`
1117+
/// `foo::bar::baz as quux`
11181118
///
11191119
/// or just
11201120
///
1121-
/// `foo::bar::baz ` (with 'baz =' implicitly on the left)
1121+
/// `foo::bar::baz` (with `as baz` implicitly on the right)
11221122
ViewPathSimple(Ident, Path, NodeId),
11231123

11241124
/// `foo::bar::*`

src/libsyntax/parse/parser.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5309,6 +5309,7 @@ impl<'a> Parser<'a> {
53095309
match self.token {
53105310
token::EQ => {
53115311
// x = foo::bar
5312+
// NOTE(stage0, #16461, pcwalton): Deprecate after snapshot.
53125313
self.bump();
53135314
let path_lo = self.span.lo;
53145315
path = vec!(self.parse_ident());
@@ -5391,7 +5392,7 @@ impl<'a> Parser<'a> {
53915392
}
53925393
_ => ()
53935394
}
5394-
let last = *path.get(path.len() - 1u);
5395+
let mut rename_to = *path.get(path.len() - 1u);
53955396
let path = ast::Path {
53965397
span: mk_sp(lo, self.span.hi),
53975398
global: false,
@@ -5403,9 +5404,12 @@ impl<'a> Parser<'a> {
54035404
}
54045405
}).collect()
54055406
};
5407+
if self.eat_keyword(keywords::As) {
5408+
rename_to = self.parse_ident()
5409+
}
54065410
return box(GC) spanned(lo,
54075411
self.last_span.hi,
5408-
ViewPathSimple(last, path, ast::DUMMY_NODE_ID));
5412+
ViewPathSimple(rename_to, path, ast::DUMMY_NODE_ID));
54095413
}
54105414

54115415
/// Parses a sequence of items. Stops when it finds program

src/libsyntax/print/pprust.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,13 +2262,17 @@ impl<'a> State<'a> {
22622262
pub fn print_view_path(&mut self, vp: &ast::ViewPath) -> IoResult<()> {
22632263
match vp.node {
22642264
ast::ViewPathSimple(ident, ref path, _) => {
2265+
try!(self.print_path(path, false));
2266+
22652267
// FIXME(#6993) can't compare identifiers directly here
2266-
if path.segments.last().unwrap().identifier.name != ident.name {
2267-
try!(self.print_ident(ident));
2268+
if path.segments.last().unwrap().identifier.name !=
2269+
ident.name {
22682270
try!(space(&mut self.s));
2269-
try!(self.word_space("="));
2271+
try!(self.word_space("as"));
2272+
try!(self.print_ident(ident));
22702273
}
2271-
self.print_path(path, false)
2274+
2275+
Ok(())
22722276
}
22732277

22742278
ast::ViewPathGlob(ref path, _) => {

src/test/auxiliary/privacy_reexport.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
pub use bar = foo;
11+
pub use foo as bar;
1212

1313
mod foo {
1414
pub fn frob() {}

src/test/auxiliary/reexported_static_methods.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
pub use sub_foo::Foo;
12-
pub use Baz = self::Bar;
12+
pub use self::Bar as Baz;
1313
pub use sub_foo::Boz;
1414
pub use sub_foo::Bort;
1515

src/test/auxiliary/static_priv_by_default.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ mod foo {
3939
}
4040

4141
pub mod bar {
42-
pub use e = foo::reexported_a;
43-
pub use f = foo::reexported_b;
44-
pub use g = foo::reexported_c;
45-
pub use h = foo::reexported_d;
42+
pub use foo::reexported_a as e;
43+
pub use foo::reexported_b as f;
44+
pub use foo::reexported_c as g;
45+
pub use foo::reexported_d as h;
4646
}
4747

4848
pub static a: int = 0;

src/test/compile-fail/borrowck-struct-update-with-dtor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// move, when the struct implements Drop.
1313

1414
// NoCopy
15-
use NP = std::kinds::marker::NoCopy;
15+
use std::kinds::marker::NoCopy as NP;
1616

1717

1818
struct S { a: int, np: NP }

src/test/compile-fail/glob-resolve1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use bar::*;
1616

1717
mod bar {
18-
use import = self::fpriv;
18+
use self::fpriv as import;
1919
fn fpriv() {}
2020
extern {
2121
fn epriv();

src/test/compile-fail/import-from-rename.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// error-pattern:expected
1212

13-
use baz = foo::{bar};
13+
use foo::{bar} as baz;
1414

1515
mod foo {
1616
pub fn bar() {}

0 commit comments

Comments
 (0)