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.

Changed all the tests to use the new extern crate syntax

Change pretty printer to use 'as' syntax
This commit is contained in:
wickerwaka 2014-08-22 21:02:00 -07:00
parent 6843d8ccd5
commit c0e003d5ad
70 changed files with 96 additions and 89 deletions

View file

@ -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.
@ -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

View file

@ -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,
@ -4836,6 +4837,8 @@ 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())
@ -4843,7 +4846,14 @@ impl<'a> Parser<'a> {
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();

View file

@ -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!(space(&mut self.s));
try!(word(&mut self.s, "="));
try!(space(&mut self.s));
try!(self.print_string(p.get(), style));
try!(space(&mut self.s));
try!(word(&mut self.s, "as"));
try!(space(&mut self.s));
}
try!(self.print_ident(id));
}
ast::ViewItemUse(ref vp) => {

View file

@ -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() }

View file

@ -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() }

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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 }

View file

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

View file

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

View file

@ -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);

View file

@ -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;

View file

@ -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 {

View file

@ -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(());

View file

@ -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,

View file

@ -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

View file

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

View file

@ -16,4 +16,4 @@
#![no_std]
extern crate core;
extern crate other = "weak-lang-items";
extern crate "weak-lang-items" as other;

View file

@ -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

View file

@ -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"###); } }

View file

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

View file

@ -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!();

View file

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

View file

@ -10,7 +10,7 @@
// aux-build:issue-10028.rs
extern crate issue10028 = "issue-10028";
extern crate "issue-10028" as issue10028;
use issue10028::ZeroLengthThingWithDestructor;

View file

@ -10,6 +10,6 @@
// aux-build:issue-11224.rs
extern crate unused = "issue-11224";
extern crate "issue-11224" as unused;
pub fn main() {}

View file

@ -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);

View file

@ -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);

View file

@ -10,7 +10,7 @@
// aux-build:issue-11508.rs
extern crate rand = "issue-11508";
extern crate "issue-11508" as rand;
use rand::{Closed01, random};

View file

@ -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;

View file

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

View file

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

View file

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

View file

@ -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;

View file

@ -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)();

View file

@ -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();

View file

@ -10,6 +10,6 @@
#![feature(phase)]
#[phase(plugin, link)] extern crate std2 = "std";
#[phase(plugin, link)] extern crate "std" as std2;
fn main() {}

View file

@ -10,7 +10,7 @@
// aux-build:issue-14421.rs
extern crate bug_lib = "issue-14421";
extern crate "issue-14421" as bug_lib;
use bug_lib::B;
use bug_lib::make;

View file

@ -10,7 +10,7 @@
// aux-build:issue-14422.rs
extern crate bug_lib = "issue-14422";
extern crate "issue-14422" as bug_lib;
use bug_lib::B;
use bug_lib::make;

View file

@ -10,5 +10,5 @@
// aux-build:issue-4545.rs
extern crate somelib = "issue-4545";
extern crate "issue-4545" as somelib;
pub fn main() { somelib::mk::<int>(); }

View file

@ -10,6 +10,6 @@
// aux-build:issue-5518.rs
extern crate other = "issue-5518";
extern crate "issue-5518" as other;
fn main() {}

View file

@ -11,7 +11,7 @@
// aux-build:issue-5521.rs
extern crate foo = "issue-5521";
extern crate "issue-5521" as foo;
fn bar(a: foo::map) {
if false {

View file

@ -10,7 +10,7 @@
// aux-build:issue-7178.rs
extern crate cross_crate_self = "issue-7178";
extern crate "issue-7178" as cross_crate_self;
pub fn main() {
let _ = cross_crate_self::Foo::new(&1i);

View file

@ -10,7 +10,7 @@
// aux-build:issue-7899.rs
extern crate testcrate = "issue-7899";
extern crate "issue-7899" as testcrate;
fn main() {
let f = testcrate::V2(1.0f32, 2.0f32);

View file

@ -10,7 +10,7 @@
// aux-build:issue-8044.rs
extern crate minimal = "issue-8044";
extern crate "issue-8044" as minimal;
use minimal::{BTree, leaf};
pub fn main() {

View file

@ -10,7 +10,7 @@
// aux-build:issue-8259.rs
extern crate other = "issue-8259";
extern crate "issue-8259" as other;
static a: other::Foo<'static> = other::A;
pub fn main() {}

View file

@ -10,7 +10,7 @@
// aux-build:issue-9906.rs
extern crate testmod = "issue-9906";
extern crate "issue-9906" as testmod;
pub fn main() {
testmod::foo();

View file

@ -10,7 +10,7 @@
// aux-build:issue-9968.rs
extern crate lib = "issue-9968";
extern crate "issue-9968" as lib;
use lib::{Trait, Struct};

View file

@ -14,7 +14,7 @@
#![no_std]
extern crate lang_lib = "lang-item-public";
extern crate "lang-item-public" as lang_lib;
#[cfg(target_os = "linux")]
#[link(name = "c")]

View file

@ -12,7 +12,7 @@
// ignore-android: FIXME(#10379)
// ignore-windows: std::dynamic_lib does not work on Windows well
extern crate foo = "linkage-visibility";
extern crate "linkage-visibility" as foo;
pub fn main() {
foo::test();

View file

@ -15,7 +15,7 @@
#![feature(linkage)]
extern crate other = "linkage1";
extern crate "linkage1" as other;
extern {
#[linkage = "extern_weak"]

View file

@ -10,7 +10,7 @@
// aux-build:priv-impl-prim-ty.rs
extern crate bar = "priv-impl-prim-ty";
extern crate "priv-impl-prim-ty" as bar;
pub fn main() {
bar::frob(1i);

View file

@ -10,7 +10,7 @@
// aux-build:reexport-should-still-link.rs
extern crate foo = "reexport-should-still-link";
extern crate "reexport-should-still-link" as foo;
pub fn main() {
foo::bar();

View file

@ -10,7 +10,7 @@
// aux-build:static_fn_inline_xc_aux.rs
extern crate mycore = "static_fn_inline_xc_aux";
extern crate "static_fn_inline_xc_aux" as mycore;
use mycore::num;

View file

@ -10,7 +10,7 @@
// aux-build:static_fn_trait_xc_aux.rs
extern crate mycore = "static_fn_trait_xc_aux";
extern crate "static_fn_trait_xc_aux" as mycore;
use mycore::num;

View file

@ -9,7 +9,7 @@
// except according to those terms.
// aux-build:static-function-pointer-aux.rs
extern crate aux = "static-function-pointer-aux";
extern crate "static-function-pointer-aux" as aux;
fn f(x: int) -> int { x }

View file

@ -12,8 +12,8 @@
// aux-build:trait_default_method_xc_aux_2.rs
extern crate aux = "trait_default_method_xc_aux";
extern crate aux2 = "trait_default_method_xc_aux_2";
extern crate "trait_default_method_xc_aux" as aux;
extern crate "trait_default_method_xc_aux_2" as aux2;
use aux::A;
use aux2::{a_struct, welp};

View file

@ -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, TestEquality, Something};
use aux::B;

View file

@ -10,7 +10,7 @@
// aux-build:trait_inheritance_auto_xc_2_aux.rs
extern crate aux = "trait_inheritance_auto_xc_2_aux";
extern crate "trait_inheritance_auto_xc_2_aux" as aux;
// aux defines impls of Foo, Bar and Baz for A
use aux::{Foo, Bar, Baz, A};

View file

@ -10,7 +10,7 @@
// aux-build:trait_inheritance_auto_xc_aux.rs
extern crate aux = "trait_inheritance_auto_xc_aux";
extern crate "trait_inheritance_auto_xc_aux" as aux;
use aux::{Foo, Bar, Baz, Quux};

View file

@ -10,7 +10,7 @@
// aux-build:trait_inheritance_cross_trait_call_xc_aux.rs
extern crate aux = "trait_inheritance_cross_trait_call_xc_aux";
extern crate "trait_inheritance_cross_trait_call_xc_aux" as aux;
use aux::Foo;

View file

@ -11,8 +11,8 @@
// aux-build:typeid-intrinsic.rs
// aux-build:typeid-intrinsic2.rs
extern crate other1 = "typeid-intrinsic";
extern crate other2 = "typeid-intrinsic2";
extern crate "typeid-intrinsic" as other1;
extern crate "typeid-intrinsic2" as other2;
use std::hash;
use std::intrinsics;

View file

@ -9,6 +9,6 @@
// except according to those terms.
// Issue #1706
extern crate stdlib = "std";
extern crate "std" as stdlib;
pub fn main() {}

View file

@ -14,7 +14,7 @@
#![no_std]
extern crate std;
extern crate zed = "std";
extern crate "std" as zed;
use std::str;

View file

@ -10,7 +10,7 @@
// aux-build:weak-lang-items.rs
extern crate other = "weak-lang-items";
extern crate "weak-lang-items" as other;
use std::task;

View file

@ -10,7 +10,7 @@
// aux-build:xcrate_address_insignificant.rs
extern crate foo = "xcrate_address_insignificant";
extern crate "xcrate_address_insignificant" as foo;
pub fn main() {
assert_eq!(foo::foo::<f64>(), foo::bar());

View file

@ -10,7 +10,7 @@
// aux-build:xcrate-trait-lifetime-param.rs
extern crate other = "xcrate-trait-lifetime-param";
extern crate "xcrate-trait-lifetime-param" as other;
struct Reader<'a> {
b : &'a [u8]