]> git.lizzy.rs Git - rust.git/blob - src/librustc_metadata/lib.rs
Rollup merge of #56641 - GuillaumeGomez:span-trait-method-invalid-nb-parameters,...
[rust.git] / src / librustc_metadata / lib.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
12        html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
13        html_root_url = "https://doc.rust-lang.org/nightly/")]
14
15 #![feature(box_patterns)]
16 #![feature(libc)]
17 #![feature(nll)]
18 #![feature(proc_macro_internals)]
19 #![feature(proc_macro_quote)]
20 #![feature(quote)]
21 #![feature(rustc_diagnostic_macros)]
22 #![feature(slice_sort_by_cached_key)]
23 #![feature(crate_visibility_modifier)]
24 #![feature(specialization)]
25 #![feature(rustc_private)]
26
27 #![recursion_limit="256"]
28
29 extern crate libc;
30 #[macro_use]
31 extern crate log;
32 extern crate memmap;
33 extern crate stable_deref_trait;
34 #[macro_use]
35 extern crate syntax;
36 extern crate syntax_pos;
37 extern crate flate2;
38 extern crate serialize as rustc_serialize; // used by deriving
39 extern crate rustc_errors as errors;
40 extern crate syntax_ext;
41 extern crate proc_macro;
42
43 #[macro_use]
44 extern crate rustc;
45 extern crate rustc_target;
46 #[macro_use]
47 extern crate rustc_data_structures;
48
49 mod diagnostics;
50
51 mod index_builder;
52 mod index;
53 mod encoder;
54 mod decoder;
55 mod cstore_impl;
56 mod isolated_encoder;
57 mod schema;
58 mod native_libs;
59 mod link_args;
60 mod foreign_modules;
61
62 pub mod creader;
63 pub mod cstore;
64 pub mod dynamic_lib;
65 pub mod locator;
66
67 pub fn validate_crate_name(
68     sess: Option<&rustc::session::Session>,
69     s: &str,
70     sp: Option<syntax_pos::Span>
71 ) {
72     let mut err_count = 0;
73     {
74         let mut say = |s: &str| {
75             match (sp, sess) {
76                 (_, None) => bug!("{}", s),
77                 (Some(sp), Some(sess)) => sess.span_err(sp, s),
78                 (None, Some(sess)) => sess.err(s),
79             }
80             err_count += 1;
81         };
82         if s.is_empty() {
83             say("crate name must not be empty");
84         }
85         for c in s.chars() {
86             if c.is_alphanumeric() { continue }
87             if c == '_'  { continue }
88             say(&format!("invalid character `{}` in crate name: `{}`", c, s));
89         }
90     }
91
92     if err_count > 0 {
93         sess.unwrap().abort_if_errors();
94     }
95 }
96
97 __build_diagnostic_array! { librustc_metadata, DIAGNOSTICS }