]> git.lizzy.rs Git - rust.git/blob - src/librustc_metadata/lib.rs
Auto merge of #57158 - estebank:as-ref, r=zackmdavis
[rust.git] / src / librustc_metadata / lib.rs
1 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
2        html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
3        html_root_url = "https://doc.rust-lang.org/nightly/")]
4
5 #![feature(box_patterns)]
6 #![feature(libc)]
7 #![feature(nll)]
8 #![feature(proc_macro_internals)]
9 #![feature(proc_macro_quote)]
10 #![feature(quote)]
11 #![feature(rustc_diagnostic_macros)]
12 #![feature(slice_sort_by_cached_key)]
13 #![feature(crate_visibility_modifier)]
14 #![feature(specialization)]
15 #![feature(rustc_private)]
16
17 #![recursion_limit="256"]
18
19 extern crate libc;
20 #[macro_use]
21 extern crate log;
22 extern crate memmap;
23 extern crate stable_deref_trait;
24 #[macro_use]
25 extern crate syntax;
26 extern crate syntax_pos;
27 extern crate flate2;
28 extern crate serialize as rustc_serialize; // used by deriving
29 extern crate rustc_errors as errors;
30 extern crate syntax_ext;
31 extern crate proc_macro;
32
33 #[macro_use]
34 extern crate rustc;
35 extern crate rustc_target;
36 #[macro_use]
37 extern crate rustc_data_structures;
38
39 mod diagnostics;
40
41 mod index_builder;
42 mod index;
43 mod encoder;
44 mod decoder;
45 mod cstore_impl;
46 mod isolated_encoder;
47 mod schema;
48 mod native_libs;
49 mod link_args;
50 mod foreign_modules;
51
52 pub mod creader;
53 pub mod cstore;
54 pub mod dynamic_lib;
55 pub mod locator;
56
57 pub fn validate_crate_name(
58     sess: Option<&rustc::session::Session>,
59     s: &str,
60     sp: Option<syntax_pos::Span>
61 ) {
62     let mut err_count = 0;
63     {
64         let mut say = |s: &str| {
65             match (sp, sess) {
66                 (_, None) => bug!("{}", s),
67                 (Some(sp), Some(sess)) => sess.span_err(sp, s),
68                 (None, Some(sess)) => sess.err(s),
69             }
70             err_count += 1;
71         };
72         if s.is_empty() {
73             say("crate name must not be empty");
74         }
75         for c in s.chars() {
76             if c.is_alphanumeric() { continue }
77             if c == '_'  { continue }
78             say(&format!("invalid character `{}` in crate name: `{}`", c, s));
79         }
80     }
81
82     if err_count > 0 {
83         sess.unwrap().abort_if_errors();
84     }
85 }
86
87 __build_diagnostic_array! { librustc_metadata, DIAGNOSTICS }