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(bool_to_option)]
11 #![feature(box_syntax)]
13 #![feature(const_transmute)]
14 #![feature(crate_visibility_modifier)]
15 #![feature(label_break_value)]
16 #![feature(matches_macro)]
18 #![feature(try_trait)]
19 #![feature(slice_patterns)]
20 #![feature(unicode_internals)]
22 #![recursion_limit="256"]
25 use rustc_data_structures::sync::Lock;
26 use rustc_index::bit_set::GrowableBitSet;
28 use syntax_pos::edition::Edition;
31 macro_rules! unwrap_or {
32 ($opt:expr, $default:expr) => {
41 used_attrs: Lock<GrowableBitSet<AttrId>>,
42 known_attrs: Lock<GrowableBitSet<AttrId>>,
43 syntax_pos_globals: syntax_pos::Globals,
47 fn new(edition: Edition) -> Globals {
49 // We have no idea how many attributes there will be, so just
50 // initiate the vectors with 0 bits. We'll grow them as necessary.
51 used_attrs: Lock::new(GrowableBitSet::new_empty()),
52 known_attrs: Lock::new(GrowableBitSet::new_empty()),
53 syntax_pos_globals: syntax_pos::Globals::new(edition),
58 pub fn with_globals<F, R>(edition: Edition, f: F) -> R
59 where F: FnOnce() -> R
61 let globals = Globals::new(edition);
62 GLOBALS.set(&globals, || {
63 syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
67 pub fn with_default_globals<F, R>(f: F) -> R
68 where F: FnOnce() -> R
70 with_globals(edition::DEFAULT_EDITION, f)
73 scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
94 pub use syntax_pos::source_map;
96 pub mod feature_gate {
98 pub use check::{check_crate, check_attribute, get_features, feature_err, feature_err_issue};
103 pub use syntax_pos::edition;
104 pub use syntax_pos::symbol;
105 pub use rustc_session::parse as sess;
116 pub mod early_buffered_lints;
118 /// Requirements for a `StableHashingContext` to be used in this crate.
119 /// This is a hack to allow using the `HashStable_Generic` derive macro
120 /// instead of implementing everything in librustc.
121 pub trait HashStableContext: syntax_pos::HashStableContext {}