]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/lib.rs
Stabilize match_default_bindings
[rust.git] / src / libsyntax / lib.rs
1 // Copyright 2012-2013 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 //! The Rust parser and macro expander.
12 //!
13 //! # Note
14 //!
15 //! This API is completely unstable and subject to change.
16
17 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
18        html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
19        html_root_url = "https://doc.rust-lang.org/nightly/",
20        test(attr(deny(warnings))))]
21 #![deny(warnings)]
22
23 #![feature(unicode)]
24 #![feature(rustc_diagnostic_macros)]
25 #![cfg_attr(stage0, feature(match_default_bindings))]
26 #![feature(non_exhaustive)]
27 #![cfg_attr(stage0, feature(i128_type))]
28 #![feature(const_atomic_usize_new)]
29 #![feature(rustc_attrs)]
30
31 // See librustc_cratesio_shim/Cargo.toml for a comment explaining this.
32 #[allow(unused_extern_crates)]
33 extern crate rustc_cratesio_shim;
34
35 #[macro_use] extern crate bitflags;
36 extern crate serialize;
37 #[macro_use] extern crate log;
38 extern crate std_unicode;
39 pub extern crate rustc_errors as errors;
40 extern crate syntax_pos;
41 extern crate rustc_data_structures;
42 #[macro_use] extern crate scoped_tls;
43
44 extern crate serialize as rustc_serialize; // used by deriving
45
46 use rustc_data_structures::sync::Lock;
47
48 // A variant of 'try!' that panics on an Err. This is used as a crutch on the
49 // way towards a non-panic!-prone parser. It should be used for fatal parsing
50 // errors; eventually we plan to convert all code using panictry to just use
51 // normal try.
52 // Exported for syntax_ext, not meant for general use.
53 #[macro_export]
54 macro_rules! panictry {
55     ($e:expr) => ({
56         use std::result::Result::{Ok, Err};
57         use errors::FatalError;
58         match $e {
59             Ok(e) => e,
60             Err(mut e) => {
61                 e.emit();
62                 FatalError.raise()
63             }
64         }
65     })
66 }
67
68 #[macro_export]
69 macro_rules! unwrap_or {
70     ($opt:expr, $default:expr) => {
71         match $opt {
72             Some(x) => x,
73             None => $default,
74         }
75     }
76 }
77
78 struct Globals {
79     used_attrs: Lock<Vec<u64>>,
80     known_attrs: Lock<Vec<u64>>,
81     syntax_pos_globals: syntax_pos::Globals,
82 }
83
84 impl Globals {
85     fn new() -> Globals {
86         Globals {
87             used_attrs: Lock::new(Vec::new()),
88             known_attrs: Lock::new(Vec::new()),
89             syntax_pos_globals: syntax_pos::Globals::new(),
90         }
91     }
92 }
93
94 pub fn with_globals<F, R>(f: F) -> R
95     where F: FnOnce() -> R
96 {
97     let globals = Globals::new();
98     GLOBALS.set(&globals, || {
99         syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
100     })
101 }
102
103 scoped_thread_local!(static GLOBALS: Globals);
104
105 #[macro_use]
106 pub mod diagnostics {
107     #[macro_use]
108     pub mod macros;
109     pub mod plugin;
110     pub mod metadata;
111 }
112
113 // NB: This module needs to be declared first so diagnostics are
114 // registered before they are used.
115 pub mod diagnostic_list;
116
117 pub mod util {
118     pub mod lev_distance;
119     pub mod node_count;
120     pub mod parser;
121     #[cfg(test)]
122     pub mod parser_testing;
123     pub mod small_vector;
124     pub mod move_map;
125
126     mod thin_vec;
127     pub use self::thin_vec::ThinVec;
128
129     mod rc_slice;
130     pub use self::rc_slice::RcSlice;
131 }
132
133 pub mod json;
134
135 pub mod syntax {
136     pub use ext;
137     pub use parse;
138     pub use ast;
139 }
140
141 pub mod abi;
142 pub mod ast;
143 pub mod attr;
144 pub mod codemap;
145 #[macro_use]
146 pub mod config;
147 pub mod entry;
148 pub mod edition;
149 pub mod feature_gate;
150 pub mod fold;
151 pub mod parse;
152 pub mod ptr;
153 pub mod show_span;
154 pub mod std_inject;
155 pub mod str;
156 pub use syntax_pos::symbol;
157 pub mod test;
158 pub mod tokenstream;
159 pub mod visit;
160
161 pub mod print {
162     pub mod pp;
163     pub mod pprust;
164 }
165
166 pub mod ext {
167     pub use syntax_pos::hygiene;
168     pub mod base;
169     pub mod build;
170     pub mod derive;
171     pub mod expand;
172     pub mod placeholders;
173     pub mod quote;
174     pub mod source_util;
175
176     pub mod tt {
177         pub mod transcribe;
178         pub mod macro_parser;
179         pub mod macro_rules;
180         pub mod quoted;
181     }
182 }
183
184 #[cfg(test)]
185 mod test_snippet;
186
187 __build_diagnostic_array! { libsyntax, DIAGNOSTICS }