]> git.lizzy.rs Git - rust.git/commitdiff
Move validate_crate_name to rustc_metadata
authorMark Rousskov <mark.simulacrum@gmail.com>
Tue, 31 Jul 2018 18:07:37 +0000 (12:07 -0600)
committerMark Rousskov <mark.simulacrum@gmail.com>
Fri, 3 Aug 2018 17:09:02 +0000 (11:09 -0600)
src/Cargo.lock
src/librustc/middle/cstore.rs
src/librustc_codegen_utils/Cargo.toml
src/librustc_codegen_utils/lib.rs
src/librustc_codegen_utils/link.rs
src/librustc_metadata/Cargo.toml
src/librustc_metadata/creader.rs
src/librustc_metadata/lib.rs
src/librustc_metadata_utils/Cargo.toml [new file with mode: 0644]
src/librustc_metadata_utils/lib.rs [new file with mode: 0644]

index 8a94faf2c5294608ab0b0c372fc24e125a9c3fac..1455ea506e64ae96b30f6b995d8f6ea231da56ae 100644 (file)
@@ -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",
@@ -2359,6 +2361,14 @@ dependencies = [
  "syntax_pos 0.0.0",
 ]
 
+[[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"
index 54169acac46acabb00e36be540a6f64aa9e58591..6132d8f2bf6a1701edf7e761a3646902d375b56b 100644 (file)
@@ -260,33 +260,6 @@ fn encode_metadata<'a, 'tcx>(&self,
 
 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;
index 30f533285ddfdc809e3f54a7a323a8120541578e..a1f4a323f849ee3feecf5ec2f11526aee2bdb6b3 100644 (file)
@@ -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" }
index f59cf5832fcb4eb7a423364ca8d9059626332c0e..3ff2388beea2ad55af1bbf216c3c513dcc777eee 100644 (file)
@@ -37,6 +37,7 @@
 extern crate syntax;
 extern crate syntax_pos;
 #[macro_use] extern crate rustc_data_structures;
+extern crate rustc_metadata_utils;
 
 use rustc::ty::TyCtxt;
 
index aabe931d79c579af326fa6a93ef1263fa72a898f..b33482eb868ffb54cae93623c8a6b8653d002c9d 100644 (file)
 
 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
     };
 
index 338824d5efe4caa862256121941b11a7e38bdbce..6142fe78149ce219c5715d8c43f629d0c07d71a9 100644 (file)
@@ -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" }
index 4f808dee61f2173f5554a4efb135cde271188fe1..1910540f00b116c87b6cc1353a64949b6eba9291 100644 (file)
 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};
index 5cba0387d17bb6ba4ff46ae92076c47a6954051e..798b631989bd57ad642ed9cc4ae30e91f4c74306 100644 (file)
@@ -37,6 +37,7 @@
 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 (file)
index 0000000..ef2e73f
--- /dev/null
@@ -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 (file)
index 0000000..a1e5150
--- /dev/null
@@ -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();
+    }
+}