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)]
10 #![feature(const_fn)] // For the `transmute` in `P::new`
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, DEFAULT_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<R>(edition: Edition, f: impl FnOnce() -> R) -> R {
55 let globals = Globals::new(edition);
56 GLOBALS.set(&globals, || rustc_span::GLOBALS.set(&globals.rustc_span_globals, f))
59 pub fn with_default_globals<R>(f: impl FnOnce() -> R) -> R {
60 with_globals(DEFAULT_EDITION, f)
63 scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
79 pub mod feature_gate {
81 pub use check::{check_attribute, check_crate, feature_err, feature_err_issue, get_features};
86 pub use rustc_session::parse as sess;
97 pub mod early_buffered_lints;
99 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
101 /// Requirements for a `StableHashingContext` to be used in this crate.
102 /// This is a hack to allow using the `HashStable_Generic` derive macro
103 /// instead of implementing everything in librustc.
104 pub trait HashStableContext: rustc_span::HashStableContext {
105 fn hash_attr(&mut self, _: &ast::Attribute, hasher: &mut StableHasher);
108 impl<AstCtx: crate::HashStableContext> HashStable<AstCtx> for ast::Attribute {
109 fn hash_stable(&self, hcx: &mut AstCtx, hasher: &mut StableHasher) {
110 hcx.hash_attr(self, hasher)