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)]
14 #![feature(matches_macro)]
16 #![feature(try_trait)]
17 #![feature(slice_patterns)]
18 #![feature(unicode_internals)]
19 #![recursion_limit = "256"]
23 use rustc_data_structures::sync::Lock;
24 use rustc_index::bit_set::GrowableBitSet;
25 use syntax_pos::edition::Edition;
28 macro_rules! unwrap_or {
29 ($opt:expr, $default:expr) => {
38 used_attrs: Lock<GrowableBitSet<AttrId>>,
39 known_attrs: Lock<GrowableBitSet<AttrId>>,
40 syntax_pos_globals: syntax_pos::Globals,
44 fn new(edition: Edition) -> Globals {
46 // We have no idea how many attributes there will be, so just
47 // initiate the vectors with 0 bits. We'll grow them as necessary.
48 used_attrs: Lock::new(GrowableBitSet::new_empty()),
49 known_attrs: Lock::new(GrowableBitSet::new_empty()),
50 syntax_pos_globals: syntax_pos::Globals::new(edition),
55 pub fn with_globals<F, R>(edition: Edition, f: F) -> R
59 let globals = Globals::new(edition);
60 GLOBALS.set(&globals, || syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f))
63 pub fn with_default_globals<F, R>(f: F) -> R
67 with_globals(edition::DEFAULT_EDITION, f)
70 scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
91 pub use syntax_pos::source_map;
93 pub mod feature_gate {
95 pub use check::{check_attribute, check_crate, feature_err, feature_err_issue, get_features};
100 pub use rustc_session::parse as sess;
101 pub use syntax_pos::edition;
102 pub use syntax_pos::symbol;
113 pub mod early_buffered_lints;
115 /// Requirements for a `StableHashingContext` to be used in this crate.
116 /// This is a hack to allow using the `HashStable_Generic` derive macro
117 /// instead of implementing everything in librustc.
118 pub trait HashStableContext: syntax_pos::HashStableContext {}