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 #![feature(bind_by_move_pattern_guards)]
11 #![feature(box_syntax)]
13 #![feature(const_transmute)]
14 #![feature(crate_visibility_modifier)]
15 #![feature(label_break_value)]
18 #![feature(proc_macro_diagnostic)]
19 #![feature(proc_macro_internals)]
20 #![feature(proc_macro_span)]
21 #![feature(try_trait)]
22 #![feature(unicode_internals)]
24 #![recursion_limit="256"]
26 extern crate proc_macro;
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;
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
45 macro_rules! panictry {
47 use std::result::Result::{Ok, Err};
48 use errors::FatalError;
59 // A variant of 'panictry!' that works on a Vec<Diagnostic> instead of a single DiagnosticBuilder.
60 macro_rules! panictry_buffer {
61 ($handler:expr, $e:expr) => ({
62 use std::result::Result::{Ok, Err};
63 use errors::{FatalError, DiagnosticBuilder};
68 DiagnosticBuilder::new_diagnostic($handler, e).emit();
77 macro_rules! unwrap_or {
78 ($opt:expr, $default:expr) => {
87 used_attrs: Lock<GrowableBitSet<AttrId>>,
88 known_attrs: Lock<GrowableBitSet<AttrId>>,
89 syntax_pos_globals: syntax_pos::Globals,
93 fn new(edition: Edition) -> Globals {
95 // We have no idea how many attributes their will be, so just
96 // initiate the vectors with 0 bits. We'll grow them as necessary.
97 used_attrs: Lock::new(GrowableBitSet::new_empty()),
98 known_attrs: Lock::new(GrowableBitSet::new_empty()),
99 syntax_pos_globals: syntax_pos::Globals::new(edition),
104 pub fn with_globals<F, R>(edition: Edition, f: F) -> R
105 where F: FnOnce() -> R
107 let globals = Globals::new(edition);
108 GLOBALS.set(&globals, || {
109 syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
113 pub fn with_default_globals<F, R>(f: F) -> R
114 where F: FnOnce() -> R
116 with_globals(edition::DEFAULT_EDITION, f)
119 scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
122 pub mod diagnostics {
130 pub mod lev_distance;
133 pub mod map_in_place;
144 pub mod feature_gate;
149 pub use syntax_pos::edition;
150 pub use syntax_pos::symbol;
162 mod proc_macro_server;
164 pub use syntax_pos::hygiene;
174 pub mod macro_parser;
180 pub mod early_buffered_lints;