Skip to content

Commit 5550ede

Browse files
committed
auto merge of #16689 : wickerwaka/rust/crate-as, r=pcwalton
For review. Not sure about the link_attrs stuff. Will work on converting all the tests. extern crate "foobar" as foo; extern crate foobar as foo; Implements remaining part of RFC #47. Addresses issue #16461. Removed link_attrs from rust.md, they don't appear to be supported by the parser.
2 parents 566b470 + c0e003d commit 5550ede

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+95
-88
lines changed

src/doc/rust.md

+4-7
Original file line numberDiff line numberDiff line change
@@ -891,9 +891,8 @@ There are several kinds of view item:
891891
##### Extern crate declarations
892892

893893
~~~~ {.ebnf .gram}
894-
extern_crate_decl : "extern" "crate" ident [ '(' link_attrs ')' ] ? [ '=' string_lit ] ? ;
895-
link_attrs : link_attr [ ',' link_attrs ] + ;
896-
link_attr : ident '=' literal ;
894+
extern_crate_decl : "extern" "crate" crate_name
895+
crate_name: ident | ( string_lit as ident )
897896
~~~~
898897

899898
An _`extern crate` declaration_ specifies a dependency on an external crate.
@@ -913,11 +912,9 @@ Four examples of `extern crate` declarations:
913912
~~~~ {.ignore}
914913
extern crate pcre;
915914
916-
extern crate std; // equivalent to: extern crate std = "std";
915+
extern crate std; // equivalent to: extern crate std as std;
917916
918-
extern crate ruststd = "std"; // linking to 'std' under another name
919-
920-
extern crate foo = "some/where/rust-foo#foo:1.0"; // a full crate ID for external tools
917+
extern crate "std" as ruststd; // linking to 'std' under another name
921918
~~~~
922919

923920
##### Use declarations

src/libsyntax/parse/parser.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -4807,7 +4807,8 @@ impl<'a> Parser<'a> {
48074807
/// # Example
48084808
///
48094809
/// extern crate url;
4810-
/// extern crate foo = "bar";
4810+
/// extern crate foo = "bar"; //deprecated
4811+
/// extern crate "bar" as foo;
48114812
fn parse_item_extern_crate(&mut self,
48124813
lo: BytePos,
48134814
visibility: Visibility,
@@ -4818,14 +4819,23 @@ impl<'a> Parser<'a> {
48184819
token::IDENT(..) => {
48194820
let the_ident = self.parse_ident();
48204821
self.expect_one_of(&[], &[token::EQ, token::SEMI]);
4822+
// NOTE - #16689 change this to a warning once
4823+
// the 'as' support is in stage0
48214824
let path = if self.token == token::EQ {
48224825
self.bump();
48234826
Some(self.parse_str())
48244827
} else {None};
48254828

48264829
self.expect(&token::SEMI);
48274830
(path, the_ident)
4828-
}
4831+
},
4832+
token::LIT_STR(..) | token::LIT_STR_RAW(..) => {
4833+
let path = self.parse_str();
4834+
self.expect_keyword(keywords::As);
4835+
let the_ident = self.parse_ident();
4836+
self.expect(&token::SEMI);
4837+
(Some(path), the_ident)
4838+
},
48294839
_ => {
48304840
let span = self.span;
48314841
let token_str = self.this_token_to_string();

src/libsyntax/print/pprust.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2363,13 +2363,13 @@ impl<'a> State<'a> {
23632363
match item.node {
23642364
ast::ViewItemExternCrate(id, ref optional_path, _) => {
23652365
try!(self.head("extern crate"));
2366-
try!(self.print_ident(id));
23672366
for &(ref p, style) in optional_path.iter() {
2367+
try!(self.print_string(p.get(), style));
23682368
try!(space(&mut self.s));
2369-
try!(word(&mut self.s, "="));
2369+
try!(word(&mut self.s, "as"));
23702370
try!(space(&mut self.s));
2371-
try!(self.print_string(p.get(), style));
23722371
}
2372+
try!(self.print_ident(id));
23732373
}
23742374

23752375
ast::ViewItemUse(ref vp) => {

src/test/auxiliary/crateresolve4b-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
#![crate_id="crateresolve4b#0.1"]
1414
#![crate_type = "lib"]
1515

16-
extern crate crateresolve4a = "crateresolve4a#0.2";
16+
extern crate "crateresolve4a#0.2" as crateresolve4a;
1717

1818
pub fn f() -> int { crateresolve4a::g() }

src/test/auxiliary/crateresolve4b-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
#![crate_id="crateresolve4b#0.2"]
1414
#![crate_type = "lib"]
1515

16-
extern crate crateresolve4a = "crateresolve4a#0.1";
16+
extern crate "crateresolve4a#0.1" as crateresolve4a;
1717

1818
pub fn g() -> int { crateresolve4a::f() }

src/test/auxiliary/issue-12133-dylib2.rs

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

1313
#![crate_type = "dylib"]
1414

15-
extern crate a = "issue-12133-rlib";
16-
extern crate b = "issue-12133-dylib";
15+
extern crate "issue-12133-rlib" as a;
16+
extern crate "issue-12133-dylib" as b;
1717

src/test/auxiliary/issue-13560-3.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
#![crate_type = "rlib"]
1414
#![feature(phase)]
1515

16-
#[phase(plugin)] extern crate t1 = "issue-13560-1";
17-
#[phase(plugin, link)] extern crate t2 = "issue-13560-2";
16+
#[phase(plugin)] extern crate "issue-13560-1" as t1;
17+
#[phase(plugin, link)] extern crate "issue-13560-2" as t2;
1818

src/test/auxiliary/issue-13620-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
extern crate crate1 = "issue-13620-1";
11+
extern crate "issue-13620-1" as crate1;
1212

1313
pub static FOO2: crate1::Foo = crate1::FOO;

src/test/auxiliary/issue-13872-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
extern crate foo = "issue-13872-1";
11+
extern crate "issue-13872-1" as foo;
1212

1313
pub use foo::B;

src/test/auxiliary/issue-13872-3.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-
extern crate bar = "issue-13872-2";
11+
extern crate "issue-13872-2" as bar;
1212

1313
use bar::B;
1414

src/test/auxiliary/syntax-extension-with-dll-deps-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#![crate_type = "dylib"]
1515
#![feature(plugin_registrar, quote, globs)]
1616

17-
extern crate other = "syntax-extension-with-dll-deps-1";
17+
extern crate "syntax-extension-with-dll-deps-1" as other;
1818
extern crate syntax;
1919
extern crate rustc;
2020

src/test/auxiliary/trait_default_method_xc_aux_2.rs

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

1111
// aux-build:trait_default_method_xc_aux.rs
1212

13-
extern crate aux = "trait_default_method_xc_aux";
13+
extern crate "trait_default_method_xc_aux" as aux;
1414
use aux::A;
1515

1616
pub struct a_struct { pub x: int }

src/test/compile-fail/bad-crate-id.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
extern crate foo = ""; //~ ERROR: crate name must not be empty
11+
extern crate "" as foo; //~ ERROR: crate name must not be empty
1212

1313
fn main() {}

src/test/compile-fail/bad-crate-id2.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-
extern crate bar = "#a"; //~ ERROR: invalid character `#` in crate name: `#a`
11+
extern crate "#a" as bar; //~ ERROR: invalid character `#` in crate name: `#a`
1212

1313
fn main() {}
1414

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

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

1111
// aux-build:issue-11680.rs
1212

13-
extern crate other = "issue-11680";
13+
extern crate "issue-11680" as other;
1414

1515
fn main() {
1616
let _b = other::Bar(1);

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

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

1111
// aux-build:issue-12612-1.rs
1212

13-
extern crate foo = "issue-12612-1";
13+
extern crate "issue-12612-1" as foo;
1414

1515
use foo::bar;
1616

src/test/compile-fail/privacy-struct-variant.rs

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

1313
#![feature(struct_variant)]
1414

15-
extern crate other = "privacy-struct-variant";
15+
extern crate "privacy-struct-variant" as other;
1616

1717
mod a {
1818
pub enum Foo {

src/test/compile-fail/privacy5.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// aux-build:privacy-tuple-struct.rs
1212
// ignore-fast
1313

14-
extern crate other = "privacy-tuple-struct";
14+
extern crate "privacy-tuple-struct" as other;
1515

1616
mod a {
1717
pub struct A(());

src/test/compile-fail/struct-field-privacy.rs

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

1111
// aux-build:struct-field-privacy.rs
1212

13-
extern crate xc = "struct-field-privacy";
13+
extern crate "struct-field-privacy" as xc;
1414

1515
struct A {
1616
a: int,

src/test/compile-fail/unreachable-variant.rs

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

1111
// aux-build:unreachable-variant.rs
1212

13-
extern crate other = "unreachable-variant";
13+
extern crate "unreachable-variant" as other;
1414

1515
fn main() {
1616
let _x = other::super_sekrit::baz; //~ ERROR is private

src/test/compile-fail/use-meta-mismatch.rs

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

1111
// error-pattern:can't find crate for `extra`
1212

13-
extern crate extra = "fake-crate";
13+
extern crate "fake-crate" as extra;
1414

1515
fn main() { }

src/test/compile-fail/weak-lang-item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
#![no_std]
1717

1818
extern crate core;
19-
extern crate other = "weak-lang-items";
19+
extern crate "weak-lang-items" as other;

src/test/pretty/issue-4264.pp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#![no_std]
33
#![feature(globs)]
44
#[phase(plugin, link)]
5-
extern crate std = "std";
6-
extern crate rt = "native";
5+
extern crate "std" as std;
6+
extern crate "native" as rt;
77
#[prelude_import]
88
use std::prelude::*;
99
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT

src/test/pretty/raw-str-nonexpr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
#![feature(asm)]
1414

1515
#[cfg = r#"just parse this"#]
16-
extern crate blah = r##"blah"##;
16+
extern crate r##"blah"## as blah;
1717

1818
fn main() { unsafe { asm!(r###"blah"###); } }

src/test/run-pass-fulldeps/issue-13560.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// Regression test for issue #13560, the test itself is all in the dependent
1717
// libraries. The fail which previously failed to compile is the one numbered 3.
1818

19-
extern crate t2 = "issue-13560-2";
20-
extern crate t3 = "issue-13560-3";
19+
extern crate "issue-13560-2" as t2;
20+
extern crate "issue-13560-3" as t3;
2121

2222
fn main() {}

src/test/run-pass-fulldeps/syntax-extension-with-dll-deps.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#![feature(phase)]
1616

1717
#[phase(plugin)]
18-
extern crate extension = "syntax-extension-with-dll-deps-2";
18+
extern crate "syntax-extension-with-dll-deps-2" as extension;
1919

2020
fn main() {
2121
foo!();

src/test/run-pass/extern-foreign-crate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
extern crate mystd = "std";
11+
extern crate "std" as mystd;
1212

1313
pub fn main() {}

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

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

1111
// aux-build:issue-10028.rs
1212

13-
extern crate issue10028 = "issue-10028";
13+
extern crate "issue-10028" as issue10028;
1414

1515
use issue10028::ZeroLengthThingWithDestructor;
1616

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

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

1111
// aux-build:issue-11224.rs
1212

13-
extern crate unused = "issue-11224";
13+
extern crate "issue-11224" as unused;
1414

1515
pub fn main() {}

src/test/run-pass/issue-11225-1.rs

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

1111
// aux-build:issue-11225-1.rs
1212

13-
extern crate foo = "issue-11225-1";
13+
extern crate "issue-11225-1" as foo;
1414

1515
pub fn main() {
1616
foo::foo(1i);

src/test/run-pass/issue-11225-2.rs

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

1111
// aux-build:issue-11225-2.rs
1212

13-
extern crate foo = "issue-11225-2";
13+
extern crate "issue-11225-2" as foo;
1414

1515
pub fn main() {
1616
foo::foo(1i);

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

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

1111
// aux-build:issue-11508.rs
1212

13-
extern crate rand = "issue-11508";
13+
extern crate "issue-11508" as rand;
1414

1515
use rand::{Closed01, random};
1616

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

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

1111
// aux-build:issue-11529.rs
1212

13-
extern crate a = "issue-11529";
13+
extern crate "issue-11529" as a;
1414

1515
fn main() {
1616
let one = 1;

src/test/run-pass/issue-12133-1.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// aux-build:issue-12133-rlib.rs
1212
// aux-build:issue-12133-dylib.rs
1313

14-
extern crate a = "issue-12133-rlib";
15-
extern crate b = "issue-12133-dylib";
14+
extern crate "issue-12133-rlib" as a;
15+
extern crate "issue-12133-dylib" as b;
1616

1717
fn main() {}

src/test/run-pass/issue-12133-2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// aux-build:issue-12133-dylib.rs
1313
// no-prefer-dynamic
1414

15-
extern crate a = "issue-12133-rlib";
16-
extern crate b = "issue-12133-dylib";
15+
extern crate "issue-12133-rlib" as a;
16+
extern crate "issue-12133-dylib" as b;
1717

1818
fn main() {}

src/test/run-pass/issue-12133-3.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
// aux-build:issue-12133-dylib.rs
1313
// aux-build:issue-12133-dylib2.rs
1414

15-
extern crate other = "issue-12133-dylib2";
15+
extern crate "issue-12133-dylib2" as other;
1616

1717
fn main() {}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
// aux-build:issue-12612-1.rs
1212
// aux-build:issue-12612-2.rs
1313

14-
extern crate foo = "issue-12612-1";
15-
extern crate bar = "issue-12612-2";
14+
extern crate "issue-12612-1" as foo;
15+
extern crate "issue-12612-2" as bar;
1616

1717
mod test {
1818
use bar::baz;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// aux-build:issue-13620-1.rs
1212
// aux-build:issue-13620-2.rs
1313

14-
extern crate crate2 = "issue-13620-2";
14+
extern crate "issue-13620-2" as crate2;
1515

1616
fn main() {
1717
(crate2::FOO2.foo)();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// aux-build:issue-13872-2.rs
1313
// aux-build:issue-13872-3.rs
1414

15-
extern crate other = "issue-13872-3";
15+
extern crate "issue-13872-3" as other;
1616

1717
fn main() {
1818
other::foo();

0 commit comments

Comments
 (0)