Skip to content

Commit f8e0ede

Browse files
committed
auto merge of #16468 : pcwalton/rust/as-renaming-import, r=alexcrichton
The old syntax will be removed after a snapshot. RFC #47. Issue #16461. r? @brson
2 parents a8c8e3f + 1c16acc commit f8e0ede

29 files changed

+51
-43
lines changed

src/doc/rust.md

+2-2
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1119,11 +1119,11 @@ pub type ViewPath = Spanned<ViewPath_>;
11191119
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
11201120
pub enum ViewPath_ {
11211121

1122-
/// `quux = foo::bar::baz`
1122+
/// `foo::bar::baz as quux`
11231123
///
11241124
/// or just
11251125
///
1126-
/// `foo::bar::baz ` (with 'baz =' implicitly on the left)
1126+
/// `foo::bar::baz` (with `as baz` implicitly on the right)
11271127
ViewPathSimple(Ident, Path, NodeId),
11281128

11291129
/// `foo::bar::*`

src/libsyntax/parse/parser.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -5317,6 +5317,7 @@ impl<'a> Parser<'a> {
53175317
match self.token {
53185318
token::EQ => {
53195319
// x = foo::bar
5320+
// NOTE(stage0, #16461, pcwalton): Deprecate after snapshot.
53205321
self.bump();
53215322
let path_lo = self.span.lo;
53225323
path = vec!(self.parse_ident());
@@ -5399,7 +5400,7 @@ impl<'a> Parser<'a> {
53995400
}
54005401
_ => ()
54015402
}
5402-
let last = *path.get(path.len() - 1u);
5403+
let mut rename_to = *path.get(path.len() - 1u);
54035404
let path = ast::Path {
54045405
span: mk_sp(lo, self.span.hi),
54055406
global: false,
@@ -5411,9 +5412,12 @@ impl<'a> Parser<'a> {
54115412
}
54125413
}).collect()
54135414
};
5415+
if self.eat_keyword(keywords::As) {
5416+
rename_to = self.parse_ident()
5417+
}
54145418
return box(GC) spanned(lo,
54155419
self.last_span.hi,
5416-
ViewPathSimple(last, path, ast::DUMMY_NODE_ID));
5420+
ViewPathSimple(rename_to, path, ast::DUMMY_NODE_ID));
54175421
}
54185422

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

src/libsyntax/print/pprust.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -2275,13 +2275,17 @@ impl<'a> State<'a> {
22752275
pub fn print_view_path(&mut self, vp: &ast::ViewPath) -> IoResult<()> {
22762276
match vp.node {
22772277
ast::ViewPathSimple(ident, ref path, _) => {
2278+
try!(self.print_path(path, false));
2279+
22782280
// FIXME(#6993) can't compare identifiers directly here
2279-
if path.segments.last().unwrap().identifier.name != ident.name {
2280-
try!(self.print_ident(ident));
2281+
if path.segments.last().unwrap().identifier.name !=
2282+
ident.name {
22812283
try!(space(&mut self.s));
2282-
try!(self.word_space("="));
2284+
try!(self.word_space("as"));
2285+
try!(self.print_ident(ident));
22832286
}
2284-
self.print_path(path, false)
2287+
2288+
Ok(())
22852289
}
22862290

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

src/test/auxiliary/privacy_reexport.rs

+1-1
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

+1-1
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

+4-4
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

+1-1
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

+1-1
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

+1-1
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() {}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// error-pattern:expected
1212

13-
use baz = foo::*;
13+
use foo::* as baz;
1414

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

src/test/compile-fail/inaccessible-test-modules.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
// the `--test` harness creates modules with these textual names, but
1414
// they should be inaccessible from normal code.
15-
use x = __test; //~ ERROR unresolved import `__test`
16-
use y = __test_reexports; //~ ERROR unresolved import `__test_reexports`
15+
use __test as x; //~ ERROR unresolved import `__test`
16+
use __test_reexports as y; //~ ERROR unresolved import `__test_reexports`
1717

1818
#[test]
1919
fn baz() {}

src/test/compile-fail/issue-2937.rs

+1-1
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-
use x = m::f; //~ ERROR unresolved import `m::f`. There is no `f` in `m`
11+
use m::f as x; //~ ERROR unresolved import `m::f`. There is no `f` in `m`
1212

1313
mod m {}
1414

src/test/compile-fail/lint-dead-code-3.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
extern crate libc;
1818

19-
pub use x = extern_foo;
19+
pub use extern_foo as x;
2020
extern {
2121
fn extern_foo();
2222
}

src/test/compile-fail/lint-missing-doc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ mod internal_impl {
148148
}
149149
/// dox
150150
pub mod public_interface {
151-
pub use foo = internal_impl::documented;
152-
pub use bar = internal_impl::undocumented1;
151+
pub use internal_impl::documented as foo;
152+
pub use internal_impl::undocumented1 as bar;
153153
pub use internal_impl::{documented, undocumented2};
154154
pub use internal_impl::globbed::*;
155155
}

src/test/compile-fail/lint-unused-imports.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#![deny(unused_imports)]
1313
#![allow(dead_code)]
1414

15-
use cal = bar::c::cc;
15+
use bar::c::cc as cal;
1616

1717
use std::mem::*; // shouldn't get errors for not using
1818
// everything imported

src/test/compile-fail/match-static-const-lc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ mod n {
4343
}
4444

4545
fn h() {
46-
use not_okay = self::n::OKAY;
46+
use self::n::OKAY as not_okay;
4747
let r = match (0,0) {
4848
(0, not_okay) => 0,
4949
//~^ ERROR static constant in pattern `not_okay` should have an uppercase name such as `NOT_OKAY`

src/test/compile-fail/privacy1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ pub mod mytest {
176176
//~^ NOTE: module `i` is private
177177

178178
pub mod foo {
179-
pub use foo = self::i::A;
179+
pub use self::i::A as foo;
180180

181181
mod i {
182182
pub struct A;

src/test/compile-fail/unresolved-import.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use foo::bar; //~ ERROR unresolved import `foo::bar`. Maybe a missing `extern crate foo`?
1212

13-
use x = bar::baz; //~ ERROR unresolved import `bar::baz`. There is no `baz` in `bar`
13+
use bar::baz as x; //~ ERROR unresolved import `bar::baz`. There is no `baz` in `bar`
1414

1515
mod bar {
1616
struct bar;

src/test/run-pass/auto-encode.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ extern crate time;
1919

2020
use std::hashmap::{HashMap, HashSet};
2121

22-
use EBReader = rbml::reader;
23-
use EBWriter = rbml::writer;
22+
use rbml::reader as EBReader;
23+
use rbml::writer as EBWriter;
2424
use std::cmp::Eq;
2525
use std::cmp;
2626
use std::io;

src/test/run-pass/exponential-notation.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
#![feature(macro_rules)]
1212

13-
use s = std::num::strconv;
14-
use to_string = std::num::strconv::float_to_str_common;
13+
use std::num::strconv as s;
14+
use std::num::strconv::float_to_str_common as to_string;
1515

1616
macro_rules! t(($a:expr, $b:expr) => { { let (r, _) = $a; assert_eq!(r, $b.to_string()) } })
1717

src/test/run-pass/filter-block-view-items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
pub fn main() {
1212
// Make sure that this view item is filtered out because otherwise it would
1313
// trigger a compilation error
14-
#[cfg(not_present)] use foo = bar;
14+
#[cfg(not_present)] use bar as foo;
1515
}

src/test/run-pass/fsu-moves-and-copies.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// Issue 4691: Ensure that functional-struct-updates operates
1212
// correctly and moves rather than copy when appropriate.
1313

14-
use NP = std::kinds::marker::NoCopy;
14+
use std::kinds::marker::NoCopy as NP;
1515

1616
struct ncint { np: NP, v: int }
1717
fn ncint(v: int) -> ncint { ncint { np: NP, v: v } }

src/test/run-pass/import.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ mod foo {
1616

1717
mod bar {
1818
use foo::x;
19-
use z = foo::x;
19+
use foo::x as z;
2020
pub fn thing() { x(10); z(10); }
2121
}
2222

src/test/run-pass/import8.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
use foo::x;
14-
use z = foo::x;
14+
use foo::x as z;
1515

1616
mod foo {
1717
pub fn x(y: int) { println!("{}", y); }

src/test/run-pass/issue-5950.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111

12-
pub use local_alias = local;
12+
pub use local as local_alias;
1313

1414
mod local { }
1515

src/test/run-pass/match-static-const-rename.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ mod m {
3838
}
3939

4040
fn g() {
41-
use AHA = self::m::aha;
41+
use self::m::aha as AHA;
4242
let r = match (0,0) {
4343
(0, AHA) => 0,
4444
(x, y) => 1 + x + y,

src/test/run-pass/use.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ extern crate zed = "std";
1818

1919

2020
use std::str;
21-
use x = zed::str;
21+
use zed::str as x;
2222
mod baz {
23-
pub use x = std::str;
23+
pub use std::str as x;
2424
}
2525

2626
#[start]

src/test/run-pass/xcrate-static-addresses.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
extern crate xcrate_static_addresses;
1414

15-
use other = xcrate_static_addresses;
15+
use xcrate_static_addresses as other;
1616

1717
pub fn main() {
1818
other::verify_same(&other::global);

0 commit comments

Comments
 (0)