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