Skip to content

Commit

Permalink
extern crate foobar as foo;
Browse files Browse the repository at this point in the history
Implements remaining part of RFC rust-lang#47.
Addresses issue rust-lang#16461.

Removed link_attrs from rust.md, they don't appear to be supported by
the parser.

Changed all the tests to use the new extern crate syntax

Change pretty printer to use 'as' syntax
  • Loading branch information
wickerwaka committed Aug 23, 2014
1 parent 6843d8c commit c0e003d
Show file tree
Hide file tree
Showing 70 changed files with 95 additions and 88 deletions.
11 changes: 4 additions & 7 deletions src/doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -891,9 +891,8 @@ There are several kinds of view item:
##### Extern crate declarations
~~~~ {.ebnf .gram}
extern_crate_decl : "extern" "crate" ident [ '(' link_attrs ')' ] ? [ '=' string_lit ] ? ;
link_attrs : link_attr [ ',' link_attrs ] + ;
link_attr : ident '=' literal ;
extern_crate_decl : "extern" "crate" crate_name
crate_name: ident | ( string_lit as ident )
~~~~
An _`extern crate` declaration_ specifies a dependency on an external crate.
Expand All @@ -913,11 +912,9 @@ Four examples of `extern crate` declarations:
~~~~ {.ignore}
extern crate pcre;

extern crate std; // equivalent to: extern crate std = "std";
extern crate std; // equivalent to: extern crate std as std;

extern crate ruststd = "std"; // linking to 'std' under another name

extern crate foo = "some/where/rust-foo#foo:1.0"; // a full crate ID for external tools
extern crate "std" as ruststd; // linking to 'std' under another name
~~~~

##### Use declarations
Expand Down
14 changes: 12 additions & 2 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4825,7 +4825,8 @@ impl<'a> Parser<'a> {
/// # Example
///
/// extern crate url;
/// extern crate foo = "bar";
/// extern crate foo = "bar"; //deprecated
/// extern crate "bar" as foo;
fn parse_item_extern_crate(&mut self,
lo: BytePos,
visibility: Visibility,
Expand All @@ -4836,14 +4837,23 @@ impl<'a> Parser<'a> {
token::IDENT(..) => {
let the_ident = self.parse_ident();
self.expect_one_of(&[], &[token::EQ, token::SEMI]);
// NOTE - #16689 change this to a warning once
// the 'as' support is in stage0
let path = if self.token == token::EQ {
self.bump();
Some(self.parse_str())
} else {None};

self.expect(&token::SEMI);
(path, the_ident)
}
},
token::LIT_STR(..) | token::LIT_STR_RAW(..) => {
let path = self.parse_str();
self.expect_keyword(keywords::As);
let the_ident = self.parse_ident();
self.expect(&token::SEMI);
(Some(path), the_ident)
},
_ => {
let span = self.span;
let token_str = self.this_token_to_string();
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2375,13 +2375,13 @@ impl<'a> State<'a> {
match item.node {
ast::ViewItemExternCrate(id, ref optional_path, _) => {
try!(self.head("extern crate"));
try!(self.print_ident(id));
for &(ref p, style) in optional_path.iter() {
try!(self.print_string(p.get(), style));
try!(space(&mut self.s));
try!(word(&mut self.s, "="));
try!(word(&mut self.s, "as"));
try!(space(&mut self.s));
try!(self.print_string(p.get(), style));
}
try!(self.print_ident(id));
}

ast::ViewItemUse(ref vp) => {
Expand Down
2 changes: 1 addition & 1 deletion src/test/auxiliary/crateresolve4b-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
#![crate_id="crateresolve4b#0.1"]
#![crate_type = "lib"]

extern crate crateresolve4a = "crateresolve4a#0.2";
extern crate "crateresolve4a#0.2" as crateresolve4a;

pub fn f() -> int { crateresolve4a::g() }
2 changes: 1 addition & 1 deletion src/test/auxiliary/crateresolve4b-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
#![crate_id="crateresolve4b#0.2"]
#![crate_type = "lib"]

extern crate crateresolve4a = "crateresolve4a#0.1";
extern crate "crateresolve4a#0.1" as crateresolve4a;

pub fn g() -> int { crateresolve4a::f() }
4 changes: 2 additions & 2 deletions src/test/auxiliary/issue-12133-dylib2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@

#![crate_type = "dylib"]

extern crate a = "issue-12133-rlib";
extern crate b = "issue-12133-dylib";
extern crate "issue-12133-rlib" as a;
extern crate "issue-12133-dylib" as b;

4 changes: 2 additions & 2 deletions src/test/auxiliary/issue-13560-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
#![crate_type = "rlib"]
#![feature(phase)]

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

2 changes: 1 addition & 1 deletion src/test/auxiliary/issue-13620-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern crate crate1 = "issue-13620-1";
extern crate "issue-13620-1" as crate1;

pub static FOO2: crate1::Foo = crate1::FOO;
2 changes: 1 addition & 1 deletion src/test/auxiliary/issue-13872-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern crate foo = "issue-13872-1";
extern crate "issue-13872-1" as foo;

pub use foo::B;
2 changes: 1 addition & 1 deletion src/test/auxiliary/issue-13872-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern crate bar = "issue-13872-2";
extern crate "issue-13872-2" as bar;

use bar::B;

Expand Down
2 changes: 1 addition & 1 deletion src/test/auxiliary/syntax-extension-with-dll-deps-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#![crate_type = "dylib"]
#![feature(plugin_registrar, quote, globs)]

extern crate other = "syntax-extension-with-dll-deps-1";
extern crate "syntax-extension-with-dll-deps-1" as other;
extern crate syntax;
extern crate rustc;

Expand Down
2 changes: 1 addition & 1 deletion src/test/auxiliary/trait_default_method_xc_aux_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// aux-build:trait_default_method_xc_aux.rs

extern crate aux = "trait_default_method_xc_aux";
extern crate "trait_default_method_xc_aux" as aux;
use aux::A;

pub struct a_struct { pub x: int }
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/bad-crate-id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

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

fn main() {}
2 changes: 1 addition & 1 deletion src/test/compile-fail/bad-crate-id2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern crate bar = "#a"; //~ ERROR: invalid character `#` in crate name: `#a`
extern crate "#a" as bar; //~ ERROR: invalid character `#` in crate name: `#a`

fn main() {}

2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-11680.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// aux-build:issue-11680.rs

extern crate other = "issue-11680";
extern crate "issue-11680" as other;

fn main() {
let _b = other::Bar(1);
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-12612.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

extern crate foo = "issue-12612-1";
extern crate "issue-12612-1" as foo;

use foo::bar;

Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/privacy-struct-variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#![feature(struct_variant)]

extern crate other = "privacy-struct-variant";
extern crate "privacy-struct-variant" as other;

mod a {
pub enum Foo {
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/privacy5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// aux-build:privacy-tuple-struct.rs
// ignore-fast

extern crate other = "privacy-tuple-struct";
extern crate "privacy-tuple-struct" as other;

mod a {
pub struct A(());
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/struct-field-privacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

extern crate xc = "struct-field-privacy";
extern crate "struct-field-privacy" as xc;

struct A {
a: int,
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/unreachable-variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// aux-build:unreachable-variant.rs

extern crate other = "unreachable-variant";
extern crate "unreachable-variant" as other;

fn main() {
let _x = other::super_sekrit::baz; //~ ERROR is private
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/use-meta-mismatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

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

extern crate extra = "fake-crate";
extern crate "fake-crate" as extra;

fn main() { }
2 changes: 1 addition & 1 deletion src/test/compile-fail/weak-lang-item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
#![no_std]

extern crate core;
extern crate other = "weak-lang-items";
extern crate "weak-lang-items" as other;
4 changes: 2 additions & 2 deletions src/test/pretty/issue-4264.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#![no_std]
#![feature(globs)]
#[phase(plugin, link)]
extern crate std = "std";
extern crate rt = "native";
extern crate "std" as std;
extern crate "native" as rt;
#[prelude_import]
use std::prelude::*;
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
Expand Down
2 changes: 1 addition & 1 deletion src/test/pretty/raw-str-nonexpr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
#![feature(asm)]

#[cfg = r#"just parse this"#]
extern crate blah = r##"blah"##;
extern crate r##"blah"## as blah;

fn main() { unsafe { asm!(r###"blah"###); } }
4 changes: 2 additions & 2 deletions src/test/run-pass-fulldeps/issue-13560.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// Regression test for issue #13560, the test itself is all in the dependent
// libraries. The fail which previously failed to compile is the one numbered 3.

extern crate t2 = "issue-13560-2";
extern crate t3 = "issue-13560-3";
extern crate "issue-13560-2" as t2;
extern crate "issue-13560-3" as t3;

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#![feature(phase)]

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

fn main() {
foo!();
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/extern-foreign-crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern crate mystd = "std";
extern crate "std" as mystd;

pub fn main() {}
2 changes: 1 addition & 1 deletion src/test/run-pass/issue-10028.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// aux-build:issue-10028.rs

extern crate issue10028 = "issue-10028";
extern crate "issue-10028" as issue10028;

use issue10028::ZeroLengthThingWithDestructor;

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/issue-11224.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

// aux-build:issue-11224.rs

extern crate unused = "issue-11224";
extern crate "issue-11224" as unused;

pub fn main() {}
2 changes: 1 addition & 1 deletion src/test/run-pass/issue-11225-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

extern crate foo = "issue-11225-1";
extern crate "issue-11225-1" as foo;

pub fn main() {
foo::foo(1i);
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/issue-11225-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

extern crate foo = "issue-11225-2";
extern crate "issue-11225-2" as foo;

pub fn main() {
foo::foo(1i);
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/issue-11508.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// aux-build:issue-11508.rs

extern crate rand = "issue-11508";
extern crate "issue-11508" as rand;

use rand::{Closed01, random};

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/issue-11529.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// aux-build:issue-11529.rs

extern crate a = "issue-11529";
extern crate "issue-11529" as a;

fn main() {
let one = 1;
Expand Down
4 changes: 2 additions & 2 deletions src/test/run-pass/issue-12133-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// aux-build:issue-12133-rlib.rs
// aux-build:issue-12133-dylib.rs

extern crate a = "issue-12133-rlib";
extern crate b = "issue-12133-dylib";
extern crate "issue-12133-rlib" as a;
extern crate "issue-12133-dylib" as b;

fn main() {}
4 changes: 2 additions & 2 deletions src/test/run-pass/issue-12133-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// aux-build:issue-12133-dylib.rs
// no-prefer-dynamic

extern crate a = "issue-12133-rlib";
extern crate b = "issue-12133-dylib";
extern crate "issue-12133-rlib" as a;
extern crate "issue-12133-dylib" as b;

fn main() {}
2 changes: 1 addition & 1 deletion src/test/run-pass/issue-12133-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
// aux-build:issue-12133-dylib.rs
// aux-build:issue-12133-dylib2.rs

extern crate other = "issue-12133-dylib2";
extern crate "issue-12133-dylib2" as other;

fn main() {}
4 changes: 2 additions & 2 deletions src/test/run-pass/issue-12612.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// aux-build:issue-12612-1.rs
// aux-build:issue-12612-2.rs

extern crate foo = "issue-12612-1";
extern crate bar = "issue-12612-2";
extern crate "issue-12612-1" as foo;
extern crate "issue-12612-2" as bar;

mod test {
use bar::baz;
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/issue-13620.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// aux-build:issue-13620-1.rs
// aux-build:issue-13620-2.rs

extern crate crate2 = "issue-13620-2";
extern crate "issue-13620-2" as crate2;

fn main() {
(crate2::FOO2.foo)();
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/issue-13872.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// aux-build:issue-13872-2.rs
// aux-build:issue-13872-3.rs

extern crate other = "issue-13872-3";
extern crate "issue-13872-3" as other;

fn main() {
other::foo();
Expand Down
Loading

3 comments on commit c0e003d

@pcwalton
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

@alexcrichton
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors: retry

@alexcrichton
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors: retry

Please sign in to comment.