From b24a3b82011c3b78573ace4ade3f99d7c4701a11 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 26 Mar 2015 17:35:13 -0700 Subject: rustc: Remove support for hyphens in crate names This commit removes parser support for `extern crate "foo" as bar` as the renamed crate is now required to be an identifier. Additionally this commit enables hard errors on crate names that contain hyphens in them, they must now solely contain alphanumeric characters or underscores. If the crate name is inferred from the file name, however, the file name `foo-bar.rs` will have the crate name inferred as `foo_bar`. If a binary is being emitted it will have the name `foo-bar` and a library will have the name `libfoo_bar.rlib`. This commit is a breaking change for a number of reasons: * Old syntax is being removed. This was previously only issuing warnings. * The output for the compiler when input is received on stdin is now `rust_out` instead of `rust-out`. * The crate name for a crate in the file `foo-bar.rs` is now `foo_bar` which can affect infrastructure such as logging. [breaking-change] --- src/libsyntax/parse/parser.rs | 47 +++++++++---------------------------------- 1 file changed, 10 insertions(+), 37 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 220ea30256e..92795bb2002 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4977,46 +4977,19 @@ impl<'a> Parser<'a> { /// /// # Examples /// - /// extern crate url; - /// extern crate foo = "bar"; //deprecated - /// extern crate "bar" as foo; + /// extern crate foo; + /// extern crate bar as foo; fn parse_item_extern_crate(&mut self, - lo: BytePos, - visibility: Visibility, - attrs: Vec) + lo: BytePos, + visibility: Visibility, + attrs: Vec) -> P { - let (maybe_path, ident) = match self.token { - token::Ident(..) => { - let crate_name = self.parse_ident(); - if self.eat_keyword(keywords::As) { - (Some(crate_name.name), self.parse_ident()) - } else { - (None, crate_name) - } - }, - token::Literal(token::Str_(..), suf) | - token::Literal(token::StrRaw(..), suf) => { - let sp = self.span; - self.expect_no_suffix(sp, "extern crate name", suf); - // forgo the internal suffix check of `parse_str` to - // avoid repeats (this unwrap will always succeed due - // to the restriction of the `match`) - let (s, _, _) = self.parse_optional_str().unwrap(); - self.expect_keyword(keywords::As); - let the_ident = self.parse_ident(); - self.obsolete(sp, ObsoleteSyntax::ExternCrateString); - let s = token::intern(&s); - (Some(s), the_ident) - }, - _ => { - let span = self.span; - let token_str = self.this_token_to_string(); - self.span_fatal(span, - &format!("expected extern crate name but \ - found `{}`", - token_str)); - } + let crate_name = self.parse_ident(); + let (maybe_path, ident) = if self.eat_keyword(keywords::As) { + (Some(crate_name.name), self.parse_ident()) + } else { + (None, crate_name) }; self.expect(&token::Semi); -- cgit 1.4.1-3-g733a5 From 13e4270bf9468e9213b6cc16ca217062791599a0 Mon Sep 17 00:00:00 2001 From: Richo Healey Date: Fri, 27 Mar 2015 10:58:12 -0700 Subject: Unquote all crate names without underscores --- src/doc/reference.md | 2 +- src/driver/driver.rs | 4 ++-- src/liblibc/lib.rs | 2 +- src/librustc/lib.rs | 2 +- src/librustc_borrowck/lib.rs | 2 +- src/librustc_driver/lib.rs | 2 +- src/librustc_trans/lib.rs | 2 +- src/librustdoc/lib.rs | 4 ++-- src/libstd/lib.rs | 6 +++--- src/libstd/old_io/mem.rs | 2 +- src/libsyntax/lib.rs | 2 +- src/libsyntax/parse/parser.rs | 2 +- src/libsyntax/std_inject.rs | 2 +- src/libtest/lib.rs | 2 +- src/test/auxiliary/syntax_extension_with_dll_deps_2.rs | 2 +- src/test/auxiliary/trait_default_method_xc_aux_2.rs | 2 +- src/test/run-make/save-analysis/foo.rs | 2 +- src/test/run-pass/derive-no-std.rs | 2 +- src/test/run-pass/extern-foreign-crate.rs | 2 +- src/test/run-pass/for-loop-no-std.rs | 2 +- src/test/run-pass/format-no-std.rs | 2 +- src/test/run-pass/issue-14330.rs | 2 +- src/test/run-pass/linkage1.rs | 2 +- src/test/run-pass/macro-crate-nonterminal-renamed.rs | 2 +- src/test/run-pass/static-fn-inline-xc.rs | 2 +- src/test/run-pass/static-fn-trait-xc.rs | 2 +- src/test/run-pass/trait-default-method-xc-2.rs | 4 ++-- src/test/run-pass/trait-default-method-xc.rs | 2 +- src/test/run-pass/trait-inheritance-auto-xc-2.rs | 2 +- src/test/run-pass/trait-inheritance-auto-xc.rs | 2 +- src/test/run-pass/trait-inheritance-cross-trait-call-xc.rs | 2 +- src/test/run-pass/use-crate-name-alias.rs | 2 +- src/test/run-pass/use.rs | 2 +- src/test/run-pass/vec-macro-no-std.rs | 2 +- src/test/run-pass/xcrate-address-insignificant.rs | 2 +- 35 files changed, 40 insertions(+), 40 deletions(-) (limited to 'src/libsyntax') diff --git a/src/doc/reference.md b/src/doc/reference.md index 32088b2ab67..b39a4f7b516 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -980,7 +980,7 @@ extern crate pcre; extern crate std; // equivalent to: extern crate std as std; -extern crate "std" as ruststd; // linking to 'std' under another name +extern crate std as ruststd; // linking to 'std' under another name ``` ##### Use declarations diff --git a/src/driver/driver.rs b/src/driver/driver.rs index 6b56c2b6303..c5c58bb49ac 100644 --- a/src/driver/driver.rs +++ b/src/driver/driver.rs @@ -12,9 +12,9 @@ #![cfg_attr(rustdoc, feature(rustdoc))] #[cfg(rustdoc)] -extern crate "rustdoc" as this; +extern crate rustdoc as this; #[cfg(rustc)] -extern crate "rustc_driver" as this; +extern crate rustc_driver as this; fn main() { this::main() } diff --git a/src/liblibc/lib.rs b/src/liblibc/lib.rs index 89843979cd0..7174b2d2c29 100644 --- a/src/liblibc/lib.rs +++ b/src/liblibc/lib.rs @@ -76,7 +76,7 @@ #![allow(bad_style, raw_pointer_derive)] #![cfg_attr(target_os = "nacl", allow(unused_imports))] -#[cfg(feature = "cargo-build")] extern crate "std" as core; +#[cfg(feature = "cargo-build")] extern crate std as core; #[cfg(not(feature = "cargo-build"))] extern crate core; #[cfg(test)] extern crate std; diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index e8af07e4381..90d9324b909 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -65,7 +65,7 @@ extern crate collections; #[macro_use] extern crate syntax; #[macro_use] #[no_link] extern crate rustc_bitflags; -extern crate "serialize" as rustc_serialize; // used by deriving +extern crate serialize as rustc_serialize; // used by deriving #[cfg(test)] extern crate test; diff --git a/src/librustc_borrowck/lib.rs b/src/librustc_borrowck/lib.rs index e927ea5b86c..99f19ad7110 100644 --- a/src/librustc_borrowck/lib.rs +++ b/src/librustc_borrowck/lib.rs @@ -35,7 +35,7 @@ // for "clarity", rename the graphviz crate to dot; graphviz within `borrowck` // refers to the borrowck-specific graphviz adapter traits. -extern crate "graphviz" as dot; +extern crate graphviz as dot; extern crate rustc; pub use borrowck::check_crate; diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 5e6f2fb835b..c433aed4ae9 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -55,7 +55,7 @@ extern crate rustc_resolve; extern crate rustc_trans; extern crate rustc_typeck; extern crate serialize; -extern crate "rustc_llvm" as llvm; +extern crate rustc_llvm as llvm; #[macro_use] extern crate log; #[macro_use] extern crate syntax; diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index 99a64156d66..83525dffaae 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -54,7 +54,7 @@ extern crate libc; extern crate rustc; extern crate rustc_back; extern crate serialize; -extern crate "rustc_llvm" as llvm; +extern crate rustc_llvm as llvm; #[macro_use] extern crate log; #[macro_use] extern crate syntax; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 9f1d876432c..62c9199a0fa 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -51,11 +51,11 @@ extern crate rustc_lint; extern crate rustc_back; extern crate serialize; extern crate syntax; -extern crate "test" as testing; +extern crate test as testing; extern crate unicode; #[macro_use] extern crate log; -extern crate "serialize" as rustc_serialize; // used by deriving +extern crate serialize as rustc_serialize; // used by deriving use std::cell::RefCell; use std::collections::HashMap; diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index cca6bb747d4..7eb575a3a68 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -149,9 +149,9 @@ extern crate core; #[macro_use] #[macro_reexport(vec, format)] -extern crate "collections" as core_collections; +extern crate collections as core_collections; -#[allow(deprecated)] extern crate "rand" as core_rand; +#[allow(deprecated)] extern crate rand as core_rand; extern crate alloc; extern crate unicode; extern crate libc; @@ -159,7 +159,7 @@ extern crate libc; #[macro_use] #[no_link] extern crate rustc_bitflags; // Make std testable by not duplicating lang items. See #2912 -#[cfg(test)] extern crate "std" as realstd; +#[cfg(test)] extern crate std as realstd; #[cfg(test)] pub use realstd::marker; #[cfg(test)] pub use realstd::ops; #[cfg(test)] pub use realstd::cmp; diff --git a/src/libstd/old_io/mem.rs b/src/libstd/old_io/mem.rs index d877a60b079..298085806bd 100644 --- a/src/libstd/old_io/mem.rs +++ b/src/libstd/old_io/mem.rs @@ -397,7 +397,7 @@ impl<'a> Buffer for BufReader<'a> { #[cfg(test)] mod test { - extern crate "test" as test_crate; + extern crate test as test_crate; use old_io::{SeekSet, SeekCur, SeekEnd, Reader, Writer, Seek, Buffer}; use prelude::v1::{Ok, Err, Vec, AsSlice}; use prelude::v1::IteratorExt; diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 9af7b9ab633..79132b2e543 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -50,7 +50,7 @@ extern crate libc; #[macro_use] extern crate log; #[macro_use] #[no_link] extern crate rustc_bitflags; -extern crate "serialize" as rustc_serialize; // used by deriving +extern crate serialize as rustc_serialize; // used by deriving pub mod util { pub mod interner; diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 220ea30256e..7c95f16bee9 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4979,7 +4979,7 @@ impl<'a> Parser<'a> { /// /// extern crate url; /// extern crate foo = "bar"; //deprecated - /// extern crate "bar" as foo; + /// extern crate bar as foo; fn parse_item_extern_crate(&mut self, lo: BytePos, visibility: Visibility, diff --git a/src/libsyntax/std_inject.rs b/src/libsyntax/std_inject.rs index 0fa7e4f902c..021ec4738ed 100644 --- a/src/libsyntax/std_inject.rs +++ b/src/libsyntax/std_inject.rs @@ -52,7 +52,7 @@ struct StandardLibraryInjector { impl fold::Folder for StandardLibraryInjector { fn fold_crate(&mut self, mut krate: ast::Crate) -> ast::Crate { - // The name to use in `extern crate "name" as std;` + // The name to use in `extern crate name as std;` let actual_crate_name = match self.alt_std_name { Some(ref s) => token::intern(&s), None => token::intern("std"), diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index c48c7e413d0..3e26a68d590 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -50,7 +50,7 @@ extern crate getopts; extern crate serialize; -extern crate "serialize" as rustc_serialize; +extern crate serialize as rustc_serialize; extern crate term; extern crate libc; diff --git a/src/test/auxiliary/syntax_extension_with_dll_deps_2.rs b/src/test/auxiliary/syntax_extension_with_dll_deps_2.rs index 54da1a1e451..4980eb8b913 100644 --- a/src/test/auxiliary/syntax_extension_with_dll_deps_2.rs +++ b/src/test/auxiliary/syntax_extension_with_dll_deps_2.rs @@ -13,7 +13,7 @@ #![crate_type = "dylib"] #![feature(plugin_registrar, quote, rustc_private)] -extern crate "syntax_extension_with_dll_deps_1" as other; +extern crate syntax_extension_with_dll_deps_1 as other; extern crate syntax; extern crate rustc; diff --git a/src/test/auxiliary/trait_default_method_xc_aux_2.rs b/src/test/auxiliary/trait_default_method_xc_aux_2.rs index 4239865d577..4e99cc26bce 100644 --- a/src/test/auxiliary/trait_default_method_xc_aux_2.rs +++ b/src/test/auxiliary/trait_default_method_xc_aux_2.rs @@ -10,7 +10,7 @@ // aux-build:trait_default_method_xc_aux.rs -extern crate "trait_default_method_xc_aux" as aux; +extern crate trait_default_method_xc_aux as aux; use aux::A; pub struct a_struct { pub x: int } diff --git a/src/test/run-make/save-analysis/foo.rs b/src/test/run-make/save-analysis/foo.rs index 74251c3c63e..a613aa84d71 100644 --- a/src/test/run-make/save-analysis/foo.rs +++ b/src/test/run-make/save-analysis/foo.rs @@ -15,7 +15,7 @@ extern crate graphviz; // A simple rust project -extern crate "flate" as myflate; +extern crate flate as myflate; use std::collections::{HashMap,HashSet}; use std::cell::RefCell; diff --git a/src/test/run-pass/derive-no-std.rs b/src/test/run-pass/derive-no-std.rs index 4f48549d499..fbc6c28fd4a 100644 --- a/src/test/run-pass/derive-no-std.rs +++ b/src/test/run-pass/derive-no-std.rs @@ -13,7 +13,7 @@ extern crate core; extern crate rand; -extern crate "serialize" as rustc_serialize; +extern crate serialize as rustc_serialize; extern crate collections; // Issue #16803 diff --git a/src/test/run-pass/extern-foreign-crate.rs b/src/test/run-pass/extern-foreign-crate.rs index 50c070483f6..1757ff51fed 100644 --- a/src/test/run-pass/extern-foreign-crate.rs +++ b/src/test/run-pass/extern-foreign-crate.rs @@ -10,6 +10,6 @@ // pretty-expanded FIXME #23616 -extern crate "std" as mystd; +extern crate std as mystd; pub fn main() {} diff --git a/src/test/run-pass/for-loop-no-std.rs b/src/test/run-pass/for-loop-no-std.rs index 769d9116f5a..72d4dd73667 100644 --- a/src/test/run-pass/for-loop-no-std.rs +++ b/src/test/run-pass/for-loop-no-std.rs @@ -13,7 +13,7 @@ #![feature(lang_items, start, no_std, core, collections)] #![no_std] -extern crate "std" as other; +extern crate std as other; #[macro_use] extern crate core; #[macro_use] extern crate collections; diff --git a/src/test/run-pass/format-no-std.rs b/src/test/run-pass/format-no-std.rs index 71934b42c33..8ee4becbb81 100644 --- a/src/test/run-pass/format-no-std.rs +++ b/src/test/run-pass/format-no-std.rs @@ -13,7 +13,7 @@ #![feature(lang_items, start, no_std, core, collections)] #![no_std] -extern crate "std" as other; +extern crate std as other; #[macro_use] extern crate core; #[macro_use] extern crate collections; diff --git a/src/test/run-pass/issue-14330.rs b/src/test/run-pass/issue-14330.rs index 48c4aed50f4..dd5b7e722fe 100644 --- a/src/test/run-pass/issue-14330.rs +++ b/src/test/run-pass/issue-14330.rs @@ -10,6 +10,6 @@ // pretty-expanded FIXME #23616 -#[macro_use] extern crate "std" as std2; +#[macro_use] extern crate std as std2; fn main() {} diff --git a/src/test/run-pass/linkage1.rs b/src/test/run-pass/linkage1.rs index 5cd741350d5..9cada12685f 100644 --- a/src/test/run-pass/linkage1.rs +++ b/src/test/run-pass/linkage1.rs @@ -14,7 +14,7 @@ #![feature(linkage)] -extern crate "linkage1" as other; +extern crate linkage1 as other; extern { #[linkage = "extern_weak"] diff --git a/src/test/run-pass/macro-crate-nonterminal-renamed.rs b/src/test/run-pass/macro-crate-nonterminal-renamed.rs index cb919297b04..ed7b1cbacad 100644 --- a/src/test/run-pass/macro-crate-nonterminal-renamed.rs +++ b/src/test/run-pass/macro-crate-nonterminal-renamed.rs @@ -12,7 +12,7 @@ // ignore-stage1 #[macro_use] -extern crate "macro_crate_nonterminal" as new_name; +extern crate macro_crate_nonterminal as new_name; pub fn main() { new_name::check_local(); diff --git a/src/test/run-pass/static-fn-inline-xc.rs b/src/test/run-pass/static-fn-inline-xc.rs index b2fbff67ac7..80de65c0e9f 100644 --- a/src/test/run-pass/static-fn-inline-xc.rs +++ b/src/test/run-pass/static-fn-inline-xc.rs @@ -12,7 +12,7 @@ // pretty-expanded FIXME #23616 -extern crate "static_fn_inline_xc_aux" as mycore; +extern crate static_fn_inline_xc_aux as mycore; use mycore::num; diff --git a/src/test/run-pass/static-fn-trait-xc.rs b/src/test/run-pass/static-fn-trait-xc.rs index 7c9049ffacf..550e03c8b12 100644 --- a/src/test/run-pass/static-fn-trait-xc.rs +++ b/src/test/run-pass/static-fn-trait-xc.rs @@ -12,7 +12,7 @@ // pretty-expanded FIXME #23616 -extern crate "static_fn_trait_xc_aux" as mycore; +extern crate static_fn_trait_xc_aux as mycore; use mycore::num; diff --git a/src/test/run-pass/trait-default-method-xc-2.rs b/src/test/run-pass/trait-default-method-xc-2.rs index b3e83f747a3..d4ed7270400 100644 --- a/src/test/run-pass/trait-default-method-xc-2.rs +++ b/src/test/run-pass/trait-default-method-xc-2.rs @@ -14,8 +14,8 @@ // pretty-expanded FIXME #23616 -extern crate "trait_default_method_xc_aux" as aux; -extern crate "trait_default_method_xc_aux_2" as aux2; +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}; diff --git a/src/test/run-pass/trait-default-method-xc.rs b/src/test/run-pass/trait-default-method-xc.rs index eb2a75f62fb..59b44a7a6dc 100644 --- a/src/test/run-pass/trait-default-method-xc.rs +++ b/src/test/run-pass/trait-default-method-xc.rs @@ -12,7 +12,7 @@ // pretty-expanded FIXME #23616 -extern crate "trait_default_method_xc_aux" as aux; +extern crate trait_default_method_xc_aux as aux; use aux::{A, TestEquality, Something}; use aux::B; diff --git a/src/test/run-pass/trait-inheritance-auto-xc-2.rs b/src/test/run-pass/trait-inheritance-auto-xc-2.rs index 9db1af230d5..128be2993ec 100644 --- a/src/test/run-pass/trait-inheritance-auto-xc-2.rs +++ b/src/test/run-pass/trait-inheritance-auto-xc-2.rs @@ -12,7 +12,7 @@ // pretty-expanded FIXME #23616 -extern crate "trait_inheritance_auto_xc_2_aux" as 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}; diff --git a/src/test/run-pass/trait-inheritance-auto-xc.rs b/src/test/run-pass/trait-inheritance-auto-xc.rs index b58839931b0..cfef5c2b503 100644 --- a/src/test/run-pass/trait-inheritance-auto-xc.rs +++ b/src/test/run-pass/trait-inheritance-auto-xc.rs @@ -12,7 +12,7 @@ // pretty-expanded FIXME #23616 -extern crate "trait_inheritance_auto_xc_aux" as aux; +extern crate trait_inheritance_auto_xc_aux as aux; use aux::{Foo, Bar, Baz, Quux}; diff --git a/src/test/run-pass/trait-inheritance-cross-trait-call-xc.rs b/src/test/run-pass/trait-inheritance-cross-trait-call-xc.rs index 8de867eff90..23d612baa1c 100644 --- a/src/test/run-pass/trait-inheritance-cross-trait-call-xc.rs +++ b/src/test/run-pass/trait-inheritance-cross-trait-call-xc.rs @@ -12,7 +12,7 @@ // pretty-expanded FIXME #23616 -extern crate "trait_inheritance_cross_trait_call_xc_aux" as aux; +extern crate trait_inheritance_cross_trait_call_xc_aux as aux; use aux::Foo; diff --git a/src/test/run-pass/use-crate-name-alias.rs b/src/test/run-pass/use-crate-name-alias.rs index 2821de6f1e7..98594183a00 100644 --- a/src/test/run-pass/use-crate-name-alias.rs +++ b/src/test/run-pass/use-crate-name-alias.rs @@ -11,6 +11,6 @@ // Issue #1706 // pretty-expanded FIXME #23616 -extern crate "std" as stdlib; +extern crate std as stdlib; pub fn main() {} diff --git a/src/test/run-pass/use.rs b/src/test/run-pass/use.rs index 446bb4a148e..e4b13b60176 100644 --- a/src/test/run-pass/use.rs +++ b/src/test/run-pass/use.rs @@ -15,7 +15,7 @@ #![no_std] extern crate std; -extern crate "std" as zed; +extern crate std as zed; use std::str; use zed::str as x; diff --git a/src/test/run-pass/vec-macro-no-std.rs b/src/test/run-pass/vec-macro-no-std.rs index 360cecb9e6a..f81509025a8 100644 --- a/src/test/run-pass/vec-macro-no-std.rs +++ b/src/test/run-pass/vec-macro-no-std.rs @@ -13,7 +13,7 @@ #![feature(lang_items, start, no_std, core, libc, collections)] #![no_std] -extern crate "std" as other; +extern crate std as other; #[macro_use] extern crate core; diff --git a/src/test/run-pass/xcrate-address-insignificant.rs b/src/test/run-pass/xcrate-address-insignificant.rs index f133396a725..ac8b15d7bf5 100644 --- a/src/test/run-pass/xcrate-address-insignificant.rs +++ b/src/test/run-pass/xcrate-address-insignificant.rs @@ -12,7 +12,7 @@ // pretty-expanded FIXME #23616 -extern crate "xcrate_address_insignificant" as foo; +extern crate xcrate_address_insignificant as foo; pub fn main() { assert_eq!(foo::foo::(), foo::bar()); -- cgit 1.4.1-3-g733a5