]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/lib.rs
remove extern_in_paths.
[rust.git] / src / libsyntax / lib.rs
1 //! The Rust parser and macro expander.
2 //!
3 //! # Note
4 //!
5 //! This API is completely unstable and subject to change.
6
7 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
8        html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
9        html_root_url = "https://doc.rust-lang.org/nightly/",
10        test(attr(deny(warnings))))]
11
12 #![feature(crate_visibility_modifier)]
13 #![feature(nll)]
14 #![feature(rustc_attrs)]
15 #![feature(rustc_diagnostic_macros)]
16 #![feature(slice_sort_by_cached_key)]
17 #![feature(str_escape)]
18 #![feature(step_trait)]
19 #![feature(try_trait)]
20 #![feature(unicode_internals)]
21
22 #![recursion_limit="256"]
23
24 #[macro_use] extern crate bitflags;
25 extern crate core;
26 extern crate serialize;
27 #[macro_use] extern crate log;
28 pub extern crate rustc_errors as errors;
29 extern crate syntax_pos;
30 #[macro_use] extern crate rustc_data_structures;
31 extern crate rustc_target;
32 #[macro_use] extern crate scoped_tls;
33 #[macro_use]
34 extern crate smallvec;
35
36 extern crate serialize as rustc_serialize; // used by deriving
37
38 use rustc_data_structures::sync::Lock;
39 use rustc_data_structures::bit_set::GrowableBitSet;
40 pub use rustc_data_structures::thin_vec::ThinVec;
41 use ast::AttrId;
42
43 // A variant of 'try!' that panics on an Err. This is used as a crutch on the
44 // way towards a non-panic!-prone parser. It should be used for fatal parsing
45 // errors; eventually we plan to convert all code using panictry to just use
46 // normal try.
47 macro_rules! panictry {
48     ($e:expr) => ({
49         use std::result::Result::{Ok, Err};
50         use errors::FatalError;
51         match $e {
52             Ok(e) => e,
53             Err(mut e) => {
54                 e.emit();
55                 FatalError.raise()
56             }
57         }
58     })
59 }
60
61 // A variant of 'panictry!' that works on a Vec<Diagnostic> instead of a single DiagnosticBuilder.
62 macro_rules! panictry_buffer {
63     ($handler:expr, $e:expr) => ({
64         use std::result::Result::{Ok, Err};
65         use errors::{FatalError, DiagnosticBuilder};
66         match $e {
67             Ok(e) => e,
68             Err(errs) => {
69                 for e in errs {
70                     DiagnosticBuilder::new_diagnostic($handler, e).emit();
71                 }
72                 FatalError.raise()
73             }
74         }
75     })
76 }
77
78 #[macro_export]
79 macro_rules! unwrap_or {
80     ($opt:expr, $default:expr) => {
81         match $opt {
82             Some(x) => x,
83             None => $default,
84         }
85     }
86 }
87
88 pub struct Globals {
89     used_attrs: Lock<GrowableBitSet<AttrId>>,
90     known_attrs: Lock<GrowableBitSet<AttrId>>,
91     syntax_pos_globals: syntax_pos::Globals,
92 }
93
94 impl Globals {
95     fn new() -> Globals {
96         Globals {
97             // We have no idea how many attributes their will be, so just
98             // initiate the vectors with 0 bits. We'll grow them as necessary.
99             used_attrs: Lock::new(GrowableBitSet::new_empty()),
100             known_attrs: Lock::new(GrowableBitSet::new_empty()),
101             syntax_pos_globals: syntax_pos::Globals::new(),
102         }
103     }
104 }
105
106 pub fn with_globals<F, R>(f: F) -> R
107     where F: FnOnce() -> R
108 {
109     let globals = Globals::new();
110     GLOBALS.set(&globals, || {
111         syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
112     })
113 }
114
115 scoped_thread_local!(pub static GLOBALS: Globals);
116
117 #[macro_use]
118 pub mod diagnostics {
119     #[macro_use]
120     pub mod macros;
121     pub mod plugin;
122     pub mod metadata;
123 }
124
125 // N.B., this module needs to be declared first so diagnostics are
126 // registered before they are used.
127 pub mod diagnostic_list;
128
129 pub mod util {
130     pub mod lev_distance;
131     pub mod node_count;
132     pub mod parser;
133     #[cfg(test)]
134     pub mod parser_testing;
135     pub mod move_map;
136 }
137
138 pub mod json;
139
140 pub mod syntax {
141     pub use ext;
142     pub use parse;
143     pub use ast;
144 }
145
146 pub mod ast;
147 pub mod attr;
148 pub mod source_map;
149 #[macro_use]
150 pub mod config;
151 pub mod entry;
152 pub mod feature_gate;
153 pub mod fold;
154 pub mod parse;
155 pub mod ptr;
156 pub mod show_span;
157 pub mod std_inject;
158 pub use syntax_pos::edition;
159 pub use syntax_pos::symbol;
160 pub mod test;
161 pub mod tokenstream;
162 pub mod visit;
163
164 pub mod print {
165     pub mod pp;
166     pub mod pprust;
167 }
168
169 pub mod ext {
170     pub use syntax_pos::hygiene;
171     pub mod base;
172     pub mod build;
173     pub mod derive;
174     pub mod expand;
175     pub mod placeholders;
176     pub mod quote;
177     pub mod source_util;
178
179     pub mod tt {
180         pub mod transcribe;
181         pub mod macro_parser;
182         pub mod macro_rules;
183         pub mod quoted;
184     }
185 }
186
187 pub mod early_buffered_lints;
188
189 #[cfg(test)]
190 mod test_snippet;
191
192 __build_diagnostic_array! { libsyntax, DIAGNOSTICS }