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/", test(attr(deny(warnings))))]
8 #![feature(bool_to_option)]
9 #![feature(box_syntax)]
11 #![feature(const_transmute)]
12 #![feature(crate_visibility_modifier)]
13 #![feature(label_break_value)]
15 #![feature(try_trait)]
16 #![feature(slice_patterns)]
17 #![feature(unicode_internals)]
18 #![recursion_limit = "256"]
22 use rustc_data_structures::sync::Lock;
23 use rustc_index::bit_set::GrowableBitSet;
24 use rustc_span::edition::Edition;
27 macro_rules! unwrap_or {
28 ($opt:expr, $default:expr) => {
37 used_attrs: Lock<GrowableBitSet<AttrId>>,
38 known_attrs: Lock<GrowableBitSet<AttrId>>,
39 rustc_span_globals: rustc_span::Globals,
43 fn new(edition: Edition) -> Globals {
45 // We have no idea how many attributes there will be, so just
46 // initiate the vectors with 0 bits. We'll grow them as necessary.
47 used_attrs: Lock::new(GrowableBitSet::new_empty()),
48 known_attrs: Lock::new(GrowableBitSet::new_empty()),
49 rustc_span_globals: rustc_span::Globals::new(edition),
54 pub fn with_globals<F, R>(edition: Edition, f: F) -> R
58 let globals = Globals::new(edition);
59 GLOBALS.set(&globals, || rustc_span::GLOBALS.set(&globals.rustc_span_globals, f))
62 pub fn with_default_globals<F, R>(f: F) -> R
66 with_globals(edition::DEFAULT_EDITION, f)
69 scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
90 pub use rustc_span::source_map;
92 pub mod feature_gate {
94 pub use check::{check_attribute, check_crate, feature_err, feature_err_issue, get_features};
99 pub use rustc_session::parse as sess;
100 pub use rustc_span::edition;
101 pub use rustc_span::symbol;
112 pub mod early_buffered_lints;
114 /// Requirements for a `StableHashingContext` to be used in this crate.
115 /// This is a hack to allow using the `HashStable_Generic` derive macro
116 /// instead of implementing everything in librustc.
117 pub trait HashStableContext: rustc_span::HashStableContext {}