1 //! The Rust parser and macro expander.
5 //! This API is completely unstable and subject to change.
7 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/",
8 test(attr(deny(warnings))))]
10 #![deny(rust_2018_idioms)]
12 #![feature(crate_visibility_modifier)]
13 #![feature(label_break_value)]
15 #![feature(rustc_attrs)]
16 #![feature(rustc_diagnostic_macros)]
17 #![feature(step_trait)]
18 #![feature(try_trait)]
19 #![feature(unicode_internals)]
21 #![recursion_limit="256"]
23 #[allow(unused_extern_crates)]
24 extern crate serialize as rustc_serialize; // used by deriving
27 use rustc_data_structures::sync::Lock;
28 use rustc_data_structures::bit_set::GrowableBitSet;
29 pub use rustc_data_structures::thin_vec::ThinVec;
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
36 macro_rules! panictry {
38 use std::result::Result::{Ok, Err};
39 use errors::FatalError;
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};
59 DiagnosticBuilder::new_diagnostic($handler, e).emit();
68 macro_rules! unwrap_or {
69 ($opt:expr, $default:expr) => {
78 used_attrs: Lock<GrowableBitSet<AttrId>>,
79 known_attrs: Lock<GrowableBitSet<AttrId>>,
80 syntax_pos_globals: syntax_pos::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(),
95 pub fn with_globals<F, R>(f: F) -> R
96 where F: FnOnce() -> R
98 let globals = Globals::new();
99 GLOBALS.set(&globals, || {
100 syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
104 scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
107 pub mod diagnostics {
114 // N.B., this module needs to be declared first so diagnostics are
115 // registered before they are used.
116 pub mod diagnostic_list;
119 pub mod lev_distance;
123 pub mod parser_testing;
124 pub mod map_in_place;
131 pub use crate::parse;
141 pub mod feature_gate;
147 pub use syntax_pos::edition;
148 pub use syntax_pos::symbol;
159 pub use syntax_pos::hygiene;
164 pub mod placeholders;
169 pub mod macro_parser;
175 pub mod early_buffered_lints;
180 __build_diagnostic_array! { libsyntax, DIAGNOSTICS }