about summary refs log tree commit diff
path: root/src/librustc/metadata
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-03-26 17:35:13 -0700
committerAlex Crichton <alex@alexcrichton.com>2015-03-27 10:19:59 -0700
commitb24a3b82011c3b78573ace4ade3f99d7c4701a11 (patch)
tree9f9ac3cf9772ff71bfe85fba9ee6d870e67dab9c /src/librustc/metadata
parent36ef29abf7fa14dc9361d6b30ff7f8d18bfb4157 (diff)
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]
Diffstat (limited to 'src/librustc/metadata')
-rw-r--r--src/librustc/metadata/creader.rs20
1 files changed, 5 insertions, 15 deletions
diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs
index 7d8789c3cd1..b6a8525675e 100644
--- a/src/librustc/metadata/creader.rs
+++ b/src/librustc/metadata/creader.rs
@@ -73,24 +73,20 @@ struct CrateInfo {
 }
 
 pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
-    let say = |s: &str, warn: bool| {
+    let say = |s: &str| {
         match (sp, sess) {
             (_, None) => panic!("{}", s),
-            (Some(sp), Some(sess)) if warn => sess.span_warn(sp, s),
             (Some(sp), Some(sess)) => sess.span_err(sp, s),
-            (None, Some(sess)) if warn => sess.warn(s),
             (None, Some(sess)) => sess.err(s),
         }
     };
     if s.len() == 0 {
-        say("crate name must not be empty", false);
-    } else if s.contains("-") {
-        say(&format!("crate names soon cannot contain hyphens: {}", s), true);
+        say("crate name must not be empty");
     }
     for c in s.chars() {
         if c.is_alphanumeric() { continue }
-        if c == '_' || c == '-' { continue }
-        say(&format!("invalid character `{}` in crate name: `{}`", c, s), false);
+        if c == '_'  { continue }
+        say(&format!("invalid character `{}` in crate name: `{}`", c, s));
     }
     match sess {
         Some(sess) => sess.abort_if_errors(),
@@ -306,13 +302,7 @@ impl<'a> CrateReader<'a> {
                       -> Option<ast::CrateNum> {
         let mut ret = None;
         self.sess.cstore.iter_crate_data(|cnum, data| {
-            // For now we do a "fuzzy match" on crate names by considering
-            // hyphens equal to underscores. This is purely meant to be a
-            // transitionary feature while we deprecate the quote syntax of
-            // `extern crate` statements.
-            if data.name != name.replace("-", "_") {
-                return
-            }
+            if data.name != name { return }
 
             match hash {
                 Some(hash) if *hash == data.hash() => { ret = Some(cnum); return }