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 #![cfg_attr(bootstrap, feature(slice_patterns))]
17 #![feature(unicode_internals)]
18 #![recursion_limit = "256"]
21 use rustc_data_structures::sync::Lock;
22 use rustc_index::bit_set::GrowableBitSet;
23 use rustc_span::edition::{Edition, DEFAULT_EDITION};
26 macro_rules! unwrap_or {
27 ($opt:expr, $default:expr) => {
36 used_attrs: Lock<GrowableBitSet<AttrId>>,
37 known_attrs: Lock<GrowableBitSet<AttrId>>,
38 rustc_span_globals: rustc_span::Globals,
42 fn new(edition: Edition) -> Globals {
44 // We have no idea how many attributes there will be, so just
45 // initiate the vectors with 0 bits. We'll grow them as necessary.
46 used_attrs: Lock::new(GrowableBitSet::new_empty()),
47 known_attrs: Lock::new(GrowableBitSet::new_empty()),
48 rustc_span_globals: rustc_span::Globals::new(edition),
53 pub fn with_globals<R>(edition: Edition, f: impl FnOnce() -> R) -> R {
54 let globals = Globals::new(edition);
55 GLOBALS.set(&globals, || rustc_span::GLOBALS.set(&globals.rustc_span_globals, f))
58 pub fn with_default_globals<R>(f: impl FnOnce() -> R) -> R {
59 with_globals(DEFAULT_EDITION, f)
62 scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
80 pub use rustc_session::parse as sess;
91 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
93 /// Requirements for a `StableHashingContext` to be used in this crate.
94 /// This is a hack to allow using the `HashStable_Generic` derive macro
95 /// instead of implementing everything in librustc.
96 pub trait HashStableContext: rustc_span::HashStableContext {
97 fn hash_attr(&mut self, _: &ast::Attribute, hasher: &mut StableHasher);
100 impl<AstCtx: crate::HashStableContext> HashStable<AstCtx> for ast::Attribute {
101 fn hash_stable(&self, hcx: &mut AstCtx, hasher: &mut StableHasher) {
102 hcx.hash_attr(self, hasher)