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)]
13 #![feature(bind_by_move_pattern_guards)]
14 #![feature(crate_visibility_modifier)]
15 #![feature(label_break_value)]
17 #![feature(rustc_attrs)]
18 #![feature(rustc_diagnostic_macros)]
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
29 use rustc_data_structures::sync::Lock;
30 use rustc_data_structures::bit_set::GrowableBitSet;
31 pub use rustc_data_structures::thin_vec::ThinVec;
33 use syntax_pos::edition::Edition;
35 const MACRO_ARGUMENTS: Option<&'static str> = Some("macro arguments");
37 // A variant of 'try!' that panics on an Err. This is used as a crutch on the
38 // way towards a non-panic!-prone parser. It should be used for fatal parsing
39 // errors; eventually we plan to convert all code using panictry to just use
41 macro_rules! panictry {
43 use std::result::Result::{Ok, Err};
44 use errors::FatalError;
55 // A variant of 'panictry!' that works on a Vec<Diagnostic> instead of a single DiagnosticBuilder.
56 macro_rules! panictry_buffer {
57 ($handler:expr, $e:expr) => ({
58 use std::result::Result::{Ok, Err};
59 use errors::{FatalError, DiagnosticBuilder};
64 DiagnosticBuilder::new_diagnostic($handler, e).emit();
73 macro_rules! unwrap_or {
74 ($opt:expr, $default:expr) => {
83 used_attrs: Lock<GrowableBitSet<AttrId>>,
84 known_attrs: Lock<GrowableBitSet<AttrId>>,
85 syntax_pos_globals: syntax_pos::Globals,
89 fn new(edition: Edition) -> Globals {
91 // We have no idea how many attributes their will be, so just
92 // initiate the vectors with 0 bits. We'll grow them as necessary.
93 used_attrs: Lock::new(GrowableBitSet::new_empty()),
94 known_attrs: Lock::new(GrowableBitSet::new_empty()),
95 syntax_pos_globals: syntax_pos::Globals::new(edition),
100 pub fn with_globals<F, R>(edition: Edition, f: F) -> R
101 where F: FnOnce() -> R
103 let globals = Globals::new(edition);
104 GLOBALS.set(&globals, || {
105 syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
109 pub fn with_default_globals<F, R>(f: F) -> R
110 where F: FnOnce() -> R
112 with_globals(edition::DEFAULT_EDITION, f)
115 scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
118 pub mod diagnostics {
125 // N.B., this module needs to be declared first so diagnostics are
126 // registered before they are used.
130 pub mod lev_distance;
134 pub mod parser_testing;
135 pub mod map_in_place;
146 pub mod feature_gate;
152 pub use syntax_pos::edition;
153 pub use syntax_pos::symbol;
164 pub use syntax_pos::hygiene;
169 pub mod placeholders;
174 pub mod macro_parser;
180 pub mod early_buffered_lints;
185 __build_diagnostic_array! { libsyntax, DIAGNOSTICS }