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 #![deny(unused_lifetimes)]
14 #![feature(bind_by_move_pattern_guards)]
16 #![feature(const_transmute)]
17 #![feature(crate_visibility_modifier)]
18 #![feature(label_break_value)]
20 #![feature(rustc_attrs)]
21 #![feature(rustc_diagnostic_macros)]
22 #![feature(step_trait)]
23 #![feature(try_trait)]
24 #![feature(unicode_internals)]
26 #![recursion_limit="256"]
28 #[allow(unused_extern_crates)]
29 extern crate serialize as rustc_serialize; // used by deriving
32 use rustc_data_structures::sync::Lock;
33 use rustc_data_structures::bit_set::GrowableBitSet;
34 pub use rustc_data_structures::thin_vec::ThinVec;
36 use syntax_pos::edition::Edition;
38 const MACRO_ARGUMENTS: Option<&'static str> = Some("macro arguments");
40 // A variant of 'try!' that panics on an Err. This is used as a crutch on the
41 // way towards a non-panic!-prone parser. It should be used for fatal parsing
42 // errors; eventually we plan to convert all code using panictry to just use
44 macro_rules! panictry {
46 use std::result::Result::{Ok, Err};
47 use errors::FatalError;
58 // A variant of 'panictry!' that works on a Vec<Diagnostic> instead of a single DiagnosticBuilder.
59 macro_rules! panictry_buffer {
60 ($handler:expr, $e:expr) => ({
61 use std::result::Result::{Ok, Err};
62 use errors::{FatalError, DiagnosticBuilder};
67 DiagnosticBuilder::new_diagnostic($handler, e).emit();
76 macro_rules! unwrap_or {
77 ($opt:expr, $default:expr) => {
86 used_attrs: Lock<GrowableBitSet<AttrId>>,
87 known_attrs: Lock<GrowableBitSet<AttrId>>,
88 syntax_pos_globals: syntax_pos::Globals,
92 fn new(edition: Edition) -> Globals {
94 // We have no idea how many attributes their will be, so just
95 // initiate the vectors with 0 bits. We'll grow them as necessary.
96 used_attrs: Lock::new(GrowableBitSet::new_empty()),
97 known_attrs: Lock::new(GrowableBitSet::new_empty()),
98 syntax_pos_globals: syntax_pos::Globals::new(edition),
103 pub fn with_globals<F, R>(edition: Edition, f: F) -> R
104 where F: FnOnce() -> R
106 let globals = Globals::new(edition);
107 GLOBALS.set(&globals, || {
108 syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
112 pub fn with_default_globals<F, R>(f: F) -> R
113 where F: FnOnce() -> R
115 with_globals(edition::DEFAULT_EDITION, f)
118 scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
121 pub mod diagnostics {
128 // N.B., this module needs to be declared first so diagnostics are
129 // registered before they are used.
133 pub mod lev_distance;
137 pub mod parser_testing;
138 pub mod map_in_place;
149 pub mod feature_gate;
155 pub use syntax_pos::edition;
156 pub use syntax_pos::symbol;
167 pub use syntax_pos::hygiene;
172 pub mod placeholders;
177 pub mod macro_parser;
183 pub mod early_buffered_lints;
188 __build_diagnostic_array! { libsyntax, DIAGNOSTICS }