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(slice_sort_by_cached_key)]
18 #![feature(step_trait)]
19 #![feature(try_trait)]
20 #![feature(unicode_internals)]
22 #![recursion_limit="256"]
24 #[allow(unused_extern_crates)]
25 extern crate serialize as rustc_serialize; // used by deriving
28 use rustc_data_structures::sync::Lock;
29 use rustc_data_structures::bit_set::GrowableBitSet;
30 pub use rustc_data_structures::thin_vec::ThinVec;
33 // A variant of 'try!' that panics on an Err. This is used as a crutch on the
34 // way towards a non-panic!-prone parser. It should be used for fatal parsing
35 // errors; eventually we plan to convert all code using panictry to just use
37 macro_rules! panictry {
39 use std::result::Result::{Ok, Err};
40 use errors::FatalError;
51 // A variant of 'panictry!' that works on a Vec<Diagnostic> instead of a single DiagnosticBuilder.
52 macro_rules! panictry_buffer {
53 ($handler:expr, $e:expr) => ({
54 use std::result::Result::{Ok, Err};
55 use errors::{FatalError, DiagnosticBuilder};
60 DiagnosticBuilder::new_diagnostic($handler, e).emit();
69 macro_rules! unwrap_or {
70 ($opt:expr, $default:expr) => {
79 used_attrs: Lock<GrowableBitSet<AttrId>>,
80 known_attrs: Lock<GrowableBitSet<AttrId>>,
81 syntax_pos_globals: syntax_pos::Globals,
87 // We have no idea how many attributes their will be, so just
88 // initiate the vectors with 0 bits. We'll grow them as necessary.
89 used_attrs: Lock::new(GrowableBitSet::new_empty()),
90 known_attrs: Lock::new(GrowableBitSet::new_empty()),
91 syntax_pos_globals: syntax_pos::Globals::new(),
96 pub fn with_globals<F, R>(f: F) -> R
97 where F: FnOnce() -> R
99 let globals = Globals::new();
100 GLOBALS.set(&globals, || {
101 syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
105 scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
108 pub mod diagnostics {
115 // N.B., this module needs to be declared first so diagnostics are
116 // registered before they are used.
117 pub mod diagnostic_list;
120 pub mod lev_distance;
124 pub mod parser_testing;
125 pub mod map_in_place;
132 pub use crate::parse;
142 pub mod feature_gate;
148 pub use syntax_pos::edition;
149 pub use syntax_pos::symbol;
160 pub use syntax_pos::hygiene;
165 pub mod placeholders;
170 pub mod macro_parser;
176 pub mod early_buffered_lints;
181 __build_diagnostic_array! { libsyntax, DIAGNOSTICS }