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(str_escape)]
19 #![feature(step_trait)]
20 #![feature(try_trait)]
21 #![feature(unicode_internals)]
23 #![recursion_limit="256"]
25 #[allow(unused_extern_crates)]
26 extern crate serialize as rustc_serialize; // used by deriving
28 pub use rustc_errors as errors;
29 use rustc_data_structures::sync::Lock;
30 use rustc_data_structures::bit_set::GrowableBitSet;
31 pub use rustc_data_structures::thin_vec::ThinVec;
34 // A variant of 'try!' that panics on an Err. This is used as a crutch on the
35 // way towards a non-panic!-prone parser. It should be used for fatal parsing
36 // errors; eventually we plan to convert all code using panictry to just use
38 macro_rules! panictry {
40 use std::result::Result::{Ok, Err};
41 use crate::errors::FatalError;
52 // A variant of 'panictry!' that works on a Vec<Diagnostic> instead of a single DiagnosticBuilder.
53 macro_rules! panictry_buffer {
54 ($handler:expr, $e:expr) => ({
55 use std::result::Result::{Ok, Err};
56 use crate::errors::{FatalError, DiagnosticBuilder};
61 DiagnosticBuilder::new_diagnostic($handler, e).emit();
70 macro_rules! unwrap_or {
71 ($opt:expr, $default:expr) => {
80 used_attrs: Lock<GrowableBitSet<AttrId>>,
81 known_attrs: Lock<GrowableBitSet<AttrId>>,
82 syntax_pos_globals: syntax_pos::Globals,
88 // We have no idea how many attributes their will be, so just
89 // initiate the vectors with 0 bits. We'll grow them as necessary.
90 used_attrs: Lock::new(GrowableBitSet::new_empty()),
91 known_attrs: Lock::new(GrowableBitSet::new_empty()),
92 syntax_pos_globals: syntax_pos::Globals::new(),
97 pub fn with_globals<F, R>(f: F) -> R
98 where F: FnOnce() -> R
100 let globals = Globals::new();
101 GLOBALS.set(&globals, || {
102 syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
106 scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
109 pub mod diagnostics {
116 // N.B., this module needs to be declared first so diagnostics are
117 // registered before they are used.
118 pub mod diagnostic_list;
121 pub mod lev_distance;
125 pub mod parser_testing;
126 pub mod map_in_place;
133 pub use crate::parse;
143 pub mod feature_gate;
149 pub use syntax_pos::edition;
150 pub use syntax_pos::symbol;
161 pub use syntax_pos::hygiene;
166 pub mod placeholders;
171 pub mod macro_parser;
177 pub mod early_buffered_lints;
182 __build_diagnostic_array! { libsyntax, DIAGNOSTICS }