about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMark Rousskov <mark.simulacrum@gmail.com>2018-07-31 12:07:37 -0600
committerMark Rousskov <mark.simulacrum@gmail.com>2018-08-03 11:09:02 -0600
commitd4beecaed36f6c8ba8f73f06d89fd20267887749 (patch)
treeea5786dc8d53fea0a48b71d52f56fb2280dfffa0
parent88e0ff14a81a2122222e32cf7c285f585c516cfd (diff)
downloadrust-d4beecaed36f6c8ba8f73f06d89fd20267887749.tar.gz
rust-d4beecaed36f6c8ba8f73f06d89fd20267887749.zip
Move validate_crate_name to rustc_metadata
-rw-r--r--src/Cargo.lock10
-rw-r--r--src/librustc/middle/cstore.rs27
-rw-r--r--src/librustc_codegen_utils/Cargo.toml1
-rw-r--r--src/librustc_codegen_utils/lib.rs1
-rw-r--r--src/librustc_codegen_utils/link.rs5
-rw-r--r--src/librustc_metadata/Cargo.toml1
-rw-r--r--src/librustc_metadata/creader.rs4
-rw-r--r--src/librustc_metadata/lib.rs1
-rw-r--r--src/librustc_metadata_utils/Cargo.toml13
-rw-r--r--src/librustc_metadata_utils/lib.rs42
10 files changed, 75 insertions, 30 deletions
diff --git a/src/Cargo.lock b/src/Cargo.lock
index 8a94faf2c52..1455ea506e6 100644
--- a/src/Cargo.lock
+++ b/src/Cargo.lock
@@ -2219,6 +2219,7 @@ dependencies = [
  "rustc 0.0.0",
  "rustc_data_structures 0.0.0",
  "rustc_incremental 0.0.0",
+ "rustc_metadata_utils 0.0.0",
  "rustc_mir 0.0.0",
  "rustc_target 0.0.0",
  "syntax 0.0.0",
@@ -2352,6 +2353,7 @@ dependencies = [
  "rustc 0.0.0",
  "rustc_data_structures 0.0.0",
  "rustc_errors 0.0.0",
+ "rustc_metadata_utils 0.0.0",
  "rustc_target 0.0.0",
  "serialize 0.0.0",
  "syntax 0.0.0",
@@ -2360,6 +2362,14 @@ dependencies = [
 ]
 
 [[package]]
+name = "rustc_metadata_utils"
+version = "0.0.0"
+dependencies = [
+ "rustc 0.0.0",
+ "syntax_pos 0.0.0",
+]
+
+[[package]]
 name = "rustc_mir"
 version = "0.0.0"
 dependencies = [
diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs
index 54169acac46..6132d8f2bf6 100644
--- a/src/librustc/middle/cstore.rs
+++ b/src/librustc/middle/cstore.rs
@@ -260,33 +260,6 @@ pub trait CrateStore {
 
 pub type CrateStoreDyn = dyn CrateStore + sync::Sync;
 
-// FIXME: find a better place for this?
-pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
-    let mut err_count = 0;
-    {
-        let mut say = |s: &str| {
-            match (sp, sess) {
-                (_, None) => bug!("{}", s),
-                (Some(sp), Some(sess)) => sess.span_err(sp, s),
-                (None, Some(sess)) => sess.err(s),
-            }
-            err_count += 1;
-        };
-        if s.is_empty() {
-            say("crate name must not be empty");
-        }
-        for c in s.chars() {
-            if c.is_alphanumeric() { continue }
-            if c == '_'  { continue }
-            say(&format!("invalid character `{}` in crate name: `{}`", c, s));
-        }
-    }
-
-    if err_count > 0 {
-        sess.unwrap().abort_if_errors();
-    }
-}
-
 /// A dummy crate store that does not support any non-local crates,
 /// for test purposes.
 pub struct DummyCrateStore;
diff --git a/src/librustc_codegen_utils/Cargo.toml b/src/librustc_codegen_utils/Cargo.toml
index 30f533285dd..a1f4a323f84 100644
--- a/src/librustc_codegen_utils/Cargo.toml
+++ b/src/librustc_codegen_utils/Cargo.toml
@@ -20,3 +20,4 @@ rustc_target = { path = "../librustc_target" }
 rustc_data_structures = { path = "../librustc_data_structures" }
 rustc_mir = { path = "../librustc_mir" }
 rustc_incremental = { path = "../librustc_incremental" }
+rustc_metadata_utils = { path = "../librustc_metadata_utils" }
diff --git a/src/librustc_codegen_utils/lib.rs b/src/librustc_codegen_utils/lib.rs
index f59cf5832fc..3ff2388beea 100644
--- a/src/librustc_codegen_utils/lib.rs
+++ b/src/librustc_codegen_utils/lib.rs
@@ -37,6 +37,7 @@ extern crate rustc_incremental;
 extern crate syntax;
 extern crate syntax_pos;
 #[macro_use] extern crate rustc_data_structures;
+extern crate rustc_metadata_utils;
 
 use rustc::ty::TyCtxt;
 
diff --git a/src/librustc_codegen_utils/link.rs b/src/librustc_codegen_utils/link.rs
index aabe931d79c..b33482eb868 100644
--- a/src/librustc_codegen_utils/link.rs
+++ b/src/librustc_codegen_utils/link.rs
@@ -10,11 +10,12 @@
 
 use rustc::session::config::{self, OutputFilenames, Input, OutputType};
 use rustc::session::Session;
-use rustc::middle::cstore::{self, LinkMeta};
+use rustc::middle::cstore::LinkMeta;
 use rustc::hir::svh::Svh;
 use std::path::{Path, PathBuf};
 use syntax::{ast, attr};
 use syntax_pos::Span;
+use rustc_metadata_utils::validate_crate_name;
 
 pub fn out_filename(sess: &Session,
                 crate_type: config::CrateType,
@@ -61,7 +62,7 @@ pub fn find_crate_name(sess: Option<&Session>,
                        attrs: &[ast::Attribute],
                        input: &Input) -> String {
     let validate = |s: String, span: Option<Span>| {
-        cstore::validate_crate_name(sess, &s, span);
+        validate_crate_name(sess, &s, span);
         s
     };
 
diff --git a/src/librustc_metadata/Cargo.toml b/src/librustc_metadata/Cargo.toml
index 338824d5efe..6142fe78149 100644
--- a/src/librustc_metadata/Cargo.toml
+++ b/src/librustc_metadata/Cargo.toml
@@ -20,3 +20,4 @@ serialize = { path = "../libserialize" }
 syntax = { path = "../libsyntax" }
 syntax_ext = { path = "../libsyntax_ext" }
 syntax_pos = { path = "../libsyntax_pos" }
+rustc_metadata_utils = { path = "../librustc_metadata_utils" }
diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs
index 4f808dee61f..1910540f00b 100644
--- a/src/librustc_metadata/creader.rs
+++ b/src/librustc_metadata/creader.rs
@@ -25,11 +25,13 @@ use rustc::session::config::{Sanitizer, self};
 use rustc_target::spec::{PanicStrategy, TargetTriple};
 use rustc::session::search_paths::PathKind;
 use rustc::middle;
-use rustc::middle::cstore::{validate_crate_name, ExternCrate, ExternCrateSource};
+use rustc::middle::cstore::{ExternCrate, ExternCrateSource};
 use rustc::util::common::record_time;
 use rustc::util::nodemap::FxHashSet;
 use rustc::hir::map::Definitions;
 
+use rustc_metadata_utils::validate_crate_name;
+
 use std::ops::Deref;
 use std::path::PathBuf;
 use std::{cmp, fs};
diff --git a/src/librustc_metadata/lib.rs b/src/librustc_metadata/lib.rs
index 5cba0387d17..798b631989b 100644
--- a/src/librustc_metadata/lib.rs
+++ b/src/librustc_metadata/lib.rs
@@ -37,6 +37,7 @@ extern crate serialize as rustc_serialize; // used by deriving
 extern crate rustc_errors as errors;
 extern crate syntax_ext;
 extern crate proc_macro;
+extern crate rustc_metadata_utils;
 
 #[macro_use]
 extern crate rustc;
diff --git a/src/librustc_metadata_utils/Cargo.toml b/src/librustc_metadata_utils/Cargo.toml
new file mode 100644
index 00000000000..ef2e73f8e3f
--- /dev/null
+++ b/src/librustc_metadata_utils/Cargo.toml
@@ -0,0 +1,13 @@
+[package]
+authors = ["The Rust Project Developers"]
+name = "rustc_metadata_utils"
+version = "0.0.0"
+
+[lib]
+name = "rustc_metadata_utils"
+path = "lib.rs"
+crate-type = ["dylib"]
+
+[dependencies]
+rustc = { path = "../librustc" }
+syntax_pos = { path = "../libsyntax_pos" }
diff --git a/src/librustc_metadata_utils/lib.rs b/src/librustc_metadata_utils/lib.rs
new file mode 100644
index 00000000000..a1e5150390a
--- /dev/null
+++ b/src/librustc_metadata_utils/lib.rs
@@ -0,0 +1,42 @@
+// Copyright 2018 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.
+
+#[macro_use]
+extern crate rustc;
+extern crate syntax_pos;
+
+use rustc::session::Session;
+use syntax_pos::Span;
+
+pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
+    let mut err_count = 0;
+    {
+        let mut say = |s: &str| {
+            match (sp, sess) {
+                (_, None) => bug!("{}", s),
+                (Some(sp), Some(sess)) => sess.span_err(sp, s),
+                (None, Some(sess)) => sess.err(s),
+            }
+            err_count += 1;
+        };
+        if s.is_empty() {
+            say("crate name must not be empty");
+        }
+        for c in s.chars() {
+            if c.is_alphanumeric() { continue }
+            if c == '_'  { continue }
+            say(&format!("invalid character `{}` in crate name: `{}`", c, s));
+        }
+    }
+
+    if err_count > 0 {
+        sess.unwrap().abort_if_errors();
+    }
+}