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

Lines changed: 4 additions & 7 deletions
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

Lines changed: 12 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

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-
extern crate bar = "issue-13872-2";
11+
extern crate "issue-13872-2" as bar;
1212

1313
use bar::B;
1414

0 commit comments

Comments
 (0)