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(box_syntax)]
12 #![feature(const_transmute)]
13 #![feature(crate_visibility_modifier)]
14 #![feature(label_break_value)]
17 #![feature(proc_macro_diagnostic)]
18 #![feature(proc_macro_internals)]
19 #![feature(proc_macro_span)]
20 #![feature(try_trait)]
21 #![feature(unicode_internals)]
23 #![recursion_limit="256"]
25 extern crate proc_macro;
28 use rustc_data_structures::sync::Lock;
29 use rustc_data_structures::bit_set::GrowableBitSet;
30 pub use rustc_data_structures::thin_vec::ThinVec;
32 use syntax_pos::edition::Edition;
37 const MACRO_ARGUMENTS: Option<&'static str> = Some("macro arguments");
39 // A variant of 'try!' that panics on an Err. This is used as a crutch on the
40 // way towards a non-panic!-prone parser. It should be used for fatal parsing
41 // 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;
67 $handler.emit_diagnostic(&e);
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 {
129 pub mod lev_distance;
132 pub mod map_in_place;
143 pub mod feature_gate;
148 pub use syntax_pos::edition;
149 pub use syntax_pos::symbol;
161 mod proc_macro_server;
163 pub use syntax_pos::hygiene;
164 pub use mbe::macro_rules::compile_declarative_macro;
174 pub mod early_buffered_lints;