rustc: Add support for extern crate foo as bar

The compiler will now issue a warning for crates that have syntax of the form
`extern crate "foo" as bar`, but it will still continue to accept this syntax.
Additionally, the string `foo-bar` will match the crate name `foo_bar` to assist
in the transition period as well.

This patch will land hopefully in tandem with a Cargo patch that will start
translating all crate names to have underscores instead of hyphens.

cc #23533
This commit is contained in:
Alex Crichton 2015-03-19 15:39:03 -07:00
parent ed81038504
commit eb2f1d925f
67 changed files with 144 additions and 145 deletions

View file

@ -9,5 +9,6 @@
// except according to those terms.
extern crate "" as foo; //~ ERROR: crate name must not be empty
//~^ WARNING: obsolete syntax
fn main() {}

View file

@ -9,5 +9,6 @@
// except according to those terms.
extern crate "#a" as bar; //~ ERROR: invalid character `#` in crate name: `#a`
//~^ WARNING: obsolete syntax
fn main() {}

View file

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:coherence-lib.rs
// aux-build:coherence_lib.rs
extern crate "coherence-lib" as lib;
extern crate coherence_lib as lib;
use lib::Remote1;
impl<T> Remote1<T> for isize { }

View file

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:coherence-lib.rs
// aux-build:coherence_lib.rs
extern crate "coherence-lib" as lib;
extern crate coherence_lib as lib;
use lib::Remote1;
pub struct BigInt;

View file

@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:coherence-lib.rs
// aux-build:coherence_lib.rs
// Test that it's not ok for U to appear uncovered
extern crate "coherence-lib" as lib;
extern crate coherence_lib as lib;
use lib::{Remote,Pair};
pub struct Cover<T>(T);

View file

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:coherence-lib.rs
// aux-build:coherence_lib.rs
extern crate "coherence-lib" as lib;
extern crate coherence_lib as lib;
use lib::Remote;
impl<T> Remote for T { }

View file

@ -9,11 +9,11 @@
// except according to those terms.
// ignore-tidy-linelength
// aux-build:coherence-orphan-lib.rs
// aux-build:coherence_orphan_lib.rs
#![feature(optin_builtin_traits)]
extern crate "coherence-orphan-lib" as lib;
extern crate coherence_orphan_lib as lib;
use lib::TheTrait;

View file

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:coherence-lib.rs
// aux-build:coherence_lib.rs
extern crate "coherence-lib" as lib;
extern crate coherence_lib as lib;
use lib::Remote;
struct Foo;

View file

@ -11,9 +11,9 @@
// Test that the same coverage rules apply even if the local type appears in the
// list of type parameters, not the self type.
// aux-build:coherence-lib.rs
// aux-build:coherence_lib.rs
extern crate "coherence-lib" as lib;
extern crate coherence_lib as lib;
use lib::{Remote1, Pair};
pub struct Local<T>(T);

View file

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:coherence-lib.rs
// aux-build:coherence_lib.rs
extern crate "coherence-lib" as lib;
extern crate coherence_lib as lib;
use lib::{Remote, Pair};
struct Local<T>(T);

View file

@ -13,7 +13,7 @@
extern crate core;
extern crate rand;
extern crate "serialize" as rustc_serialize;
extern crate serialize as rustc_serialize;
#[derive(Rand)] //~ ERROR this trait cannot be derived
//~^ WARNING `#[derive(Rand)]` is deprecated

View file

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:issue-11680.rs
// aux-build:issue_11680.rs
extern crate "issue-11680" as other;
extern crate issue_11680 as other;
fn main() {
let _b = other::Foo::Bar(1);

View file

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:issue-12612-1.rs
// aux-build:issue_12612_1.rs
extern crate "issue-12612-1" as foo;
extern crate issue_12612_1 as foo;
use foo::bar;

View file

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:issue-16725.rs
// aux-build:issue_16725.rs
extern crate "issue-16725" as foo;
extern crate issue_16725 as foo;
fn main() {
unsafe { foo::bar(); }

View file

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:issue-17718-const-privacy.rs
// aux-build:issue_17718_const_privacy.rs
extern crate "issue-17718-const-privacy" as other;
extern crate issue_17718_const_privacy as other;
use a::B; //~ ERROR: const `B` is private
use other::{

View file

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:issue-21202.rs
// aux-build:issue_21202.rs
extern crate "issue-21202" as crate1;
extern crate issue_21202 as crate1;
use crate1::A;

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:lint-unused-extern-crate.rs
// aux-build:lint_unused_extern_crate.rs
#![deny(unused_extern_crates)]
#![allow(unused_variables)]
@ -19,12 +19,12 @@
extern crate libc; //~ ERROR: unused extern crate
extern crate "collections" as collecs; // no error, it is used
extern crate collections as collecs; // no error, it is used
extern crate rand; // no error, the use marks it as used
// even if imported objects aren't used
extern crate "lint-unused-extern-crate" as other; // no error, the use * marks it as used
extern crate lint_unused_extern_crate as other; // no error, the use * marks it as used
#[allow(unused_imports)]
use rand::isaac::IsaacRng;

View file

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:privacy-tuple-struct.rs
// aux-build:privacy_tuple_struct.rs
extern crate "privacy-tuple-struct" as other;
extern crate privacy_tuple_struct as other;
mod a {
pub struct A(());
@ -101,30 +101,30 @@ fn xcrate() {
let c = other::C(2, 3); //~ ERROR: cannot invoke tuple struct constructor
let d = other::D(4);
let other::A(()) = a; //~ ERROR: field #1 of struct `privacy-tuple-struct::A` is private
let other::A(()) = a; //~ ERROR: field #1 of struct `privacy_tuple_struct::A` is private
let other::A(_) = a;
match a { other::A(()) => {} }
//~^ ERROR: field #1 of struct `privacy-tuple-struct::A` is private
//~^ ERROR: field #1 of struct `privacy_tuple_struct::A` is private
match a { other::A(_) => {} }
let other::B(_) = b;
let other::B(_b) = b; //~ ERROR: field #1 of struct `privacy-tuple-struct::B` is private
let other::B(_b) = b; //~ ERROR: field #1 of struct `privacy_tuple_struct::B` is private
match b { other::B(_) => {} }
match b { other::B(_b) => {} }
//~^ ERROR: field #1 of struct `privacy-tuple-struct::B` is private
//~^ ERROR: field #1 of struct `privacy_tuple_struct::B` is private
match b { other::B(1) => {} other::B(_) => {} }
//~^ ERROR: field #1 of struct `privacy-tuple-struct::B` is private
//~^ ERROR: field #1 of struct `privacy_tuple_struct::B` is private
let other::C(_, _) = c;
let other::C(_a, _) = c;
let other::C(_, _b) = c; //~ ERROR: field #2 of struct `privacy-tuple-struct::C` is private
let other::C(_a, _b) = c; //~ ERROR: field #2 of struct `privacy-tuple-struct::C` is private
let other::C(_, _b) = c; //~ ERROR: field #2 of struct `privacy_tuple_struct::C` is private
let other::C(_a, _b) = c; //~ ERROR: field #2 of struct `privacy_tuple_struct::C` is private
match c { other::C(_, _) => {} }
match c { other::C(_a, _) => {} }
match c { other::C(_, _b) => {} }
//~^ ERROR: field #2 of struct `privacy-tuple-struct::C` is private
//~^ ERROR: field #2 of struct `privacy_tuple_struct::C` is private
match c { other::C(_a, _b) => {} }
//~^ ERROR: field #2 of struct `privacy-tuple-struct::C` is private
//~^ ERROR: field #2 of struct `privacy_tuple_struct::C` is private
let other::D(_) = d;
let other::D(_d) = d;

View file

@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:regions-bounded-method-type-parameters-cross-crate-lib.rs
// aux-build:regions_bounded_method_type_parameters_cross_crate_lib.rs
// Check explicit region bounds on methods in the cross crate case.
extern crate "regions-bounded-method-type-parameters-cross-crate-lib" as lib;
extern crate regions_bounded_method_type_parameters_cross_crate_lib as lib;
use lib::Inv;
use lib::MaybeOwned;

View file

@ -10,7 +10,7 @@
// aux-build:pub_static_array.rs
extern crate "pub_static_array" as array;
extern crate pub_static_array as array;
use array::ARRAY;

View file

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:struct-field-privacy.rs
// aux-build:struct_field_privacy.rs
extern crate "struct-field-privacy" as xc;
extern crate struct_field_privacy as xc;
struct A {
a: isize,
@ -37,11 +37,11 @@ fn test(a: A, b: inner::A, c: inner::B, d: xc::A, e: xc::B) {
c.a;
c.b; //~ ERROR: field `b` of struct `inner::B` is private
d.a; //~ ERROR: field `a` of struct `struct-field-privacy::A` is private
d.a; //~ ERROR: field `a` of struct `struct_field_privacy::A` is private
d.b;
e.a;
e.b; //~ ERROR: field `b` of struct `struct-field-privacy::B` is private
e.b; //~ ERROR: field `b` of struct `struct_field_privacy::B` is private
}
fn main() {}

View file

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:struct-field-privacy.rs
// aux-build:struct_field_privacy.rs
extern crate "struct-field-privacy" as xc;
extern crate struct_field_privacy as xc;
use xc::B;
@ -22,9 +22,9 @@ struct A {
fn main () {
// external crate struct
let k = B {
aa: 20, //~ ERROR structure `struct-field-privacy::B` has no field named `aa`
aa: 20, //~ ERROR structure `struct_field_privacy::B` has no field named `aa`
//~^ HELP did you mean `a`?
bb: 20, //~ ERROR structure `struct-field-privacy::B` has no field named `bb`
bb: 20, //~ ERROR structure `struct_field_privacy::B` has no field named `bb`
};
// local crate struct
let l = A {

View file

@ -8,12 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:trait-safety-lib.rs
// aux-build:trait_safety_lib.rs
// Check that unsafe traits require unsafe impls and that inherent
// impls cannot be unsafe.
extern crate "trait-safety-lib" as lib;
extern crate trait_safety_lib as lib;
struct Bar;
impl lib::Foo for Bar { //~ ERROR requires an `unsafe impl` declaration

View file

@ -8,14 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:typeck-default-trait-impl-cross-crate-coherence-lib.rs
// aux-build:typeck_default_trait_impl_cross_crate_coherence_lib.rs
// Test that we do not consider associated types to be sendable without
// some applicable trait bound (and we don't ICE).
#![feature(optin_builtin_traits)]
extern crate "typeck-default-trait-impl-cross-crate-coherence-lib" as lib;
extern crate typeck_default_trait_impl_cross_crate_coherence_lib as lib;
use lib::DefaultedTrait;

View file

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:unreachable-variant.rs
// aux-build:unreachable_variant.rs
extern crate "unreachable-variant" as other;
extern crate unreachable_variant as other;
fn main() {
let _x = other::super_sekrit::sooper_sekrit::baz; //~ ERROR is private

View file

@ -11,6 +11,7 @@
extern crate
"foo"suffix //~ ERROR extern crate name with a suffix is illegal
//~^ WARNING: obsolete syntax
as foo;
extern

View file

@ -1,15 +0,0 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Tests that the proper help is displayed in the error message
extern crate foo as bar;
//~^ ERROR expected `;`, found `as`
//~^^ HELP perhaps you meant to enclose the crate name `foo` in a string?

View file

@ -11,4 +11,4 @@
// Verifies that the expected token errors for `extern crate` are
// raised
extern crate foo {} //~ERROR expected `;`, found `{`
extern crate foo {} //~ERROR expected one of `;` or `as`, found `{`

View file

@ -3,7 +3,7 @@
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate "std" as std;
extern crate std as std;
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.

View file

@ -13,6 +13,6 @@
#![feature(asm)]
#[cfg(foo = r#"just parse this"#)]
extern crate r##"blah"## as blah;
extern crate blah as blah;
fn main() { unsafe { asm!(r###"blah"###); } }

View file

@ -12,4 +12,4 @@ all:
| grep "invalid character.*in crate name:"
cp foo.rs $(TMPDIR)/-foo.rs
$(RUSTC) $(TMPDIR)/-foo.rs 2>&1 \
| grep "crate name cannot start with a hyphen:"
| grep "soon cannot contain hyphens:"

View file

@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:coherence-lib.rs
// aux-build:coherence_lib.rs
// pretty-expanded FIXME #23616
extern crate "coherence-lib" as lib;
extern crate coherence_lib as lib;
use lib::Remote1;
pub struct BigInt;

View file

@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:coherence-lib.rs
// aux-build:coherence_lib.rs
// pretty-expanded FIXME #23616
extern crate "coherence-lib" as lib;
extern crate coherence_lib as lib;
use lib::Remote1;
pub struct BigInt;

View file

@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:coherence-lib.rs
// aux-build:coherence_lib.rs
// pretty-expanded FIXME #23616
extern crate "coherence-lib" as lib;
extern crate coherence_lib as lib;
use lib::Remote1;
pub trait Local {

View file

@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:coherence-lib.rs
// aux-build:coherence_lib.rs
// pretty-expanded FIXME #23616
extern crate "coherence-lib" as lib;
extern crate coherence_lib as lib;
use lib::Remote;
struct Foo<T>(T);

View file

@ -8,14 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:coherence-lib.rs
// aux-build:coherence_lib.rs
// Test that it's ok for T to appear first in the self-type, as long
// as it's covered somewhere.
// pretty-expanded FIXME #23616
extern crate "coherence-lib" as lib;
extern crate coherence_lib as lib;
use lib::{Remote,Pair};
pub struct Cover<T>(T);

View file

@ -8,14 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:coherence-lib.rs
// aux-build:coherence_lib.rs
// Test that it's ok for T to appear second in the self-type, as long
// as it's covered somewhere.
// pretty-expanded FIXME #23616
extern crate "coherence-lib" as lib;
extern crate coherence_lib as lib;
use lib::{Remote,Pair};
pub struct Cover<T>(T);

View file

@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:coherence-lib.rs
// aux-build:coherence_lib.rs
// pretty-expanded FIXME #23616
extern crate "coherence-lib" as lib;
extern crate coherence_lib as lib;
use lib::Remote1;
struct Foo<T>(T);

View file

@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:coherence-lib.rs
// aux-build:coherence_lib.rs
// pretty-expanded FIXME #23616
extern crate "coherence-lib" as lib;
extern crate coherence_lib as lib;
use lib::Remote1;
struct Foo<T>(T);

View file

@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:coherence-lib.rs
// aux-build:coherence_lib.rs
// pretty-expanded FIXME #23616
extern crate "coherence-lib" as lib;
extern crate coherence_lib as lib;
use lib::Remote;
struct Local;

View file

@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:coherence-lib.rs
// aux-build:coherence_lib.rs
// pretty-expanded FIXME #23616
extern crate "coherence-lib" as lib;
extern crate coherence_lib as lib;
use lib::Remote;
struct Local<T>(T);

View file

@ -8,13 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:issue-12612-1.rs
// aux-build:issue-12612-2.rs
// aux-build:issue_12612_1.rs
// aux-build:issue_12612_2.rs
// pretty-expanded FIXME #23616
extern crate "issue-12612-1" as foo;
extern crate "issue-12612-2" as bar;
extern crate issue_12612_1 as foo;
extern crate issue_12612_2 as bar;
mod test {
use bar::baz;

View file

@ -8,13 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:trait-safety-lib.rs
// aux-build:trait_safety_lib.rs
// Simple smoke test that unsafe traits can be compiled across crates.
// pretty-expanded FIXME #23616
extern crate "trait-safety-lib" as lib;
extern crate trait_safety_lib as lib;
use lib::Foo;