]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/lib.rs
Remove unnecessary `const_fn` feature gates
[rust.git] / src / libsyntax / lib.rs
1 //! The Rust parser and macro expander.
2 //!
3 //! # Note
4 //!
5 //! This API is completely unstable and subject to change.
6
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)]
14 #![feature(nll)]
15 #![feature(try_trait)]
16 #![feature(slice_patterns)]
17 #![feature(unicode_internals)]
18 #![recursion_limit = "256"]
19
20 use ast::AttrId;
21 pub use errors;
22 use rustc_data_structures::sync::Lock;
23 use rustc_index::bit_set::GrowableBitSet;
24 use rustc_span::edition::{Edition, DEFAULT_EDITION};
25
26 #[macro_export]
27 macro_rules! unwrap_or {
28     ($opt:expr, $default:expr) => {
29         match $opt {
30             Some(x) => x,
31             None => $default,
32         }
33     };
34 }
35
36 pub struct Globals {
37     used_attrs: Lock<GrowableBitSet<AttrId>>,
38     known_attrs: Lock<GrowableBitSet<AttrId>>,
39     rustc_span_globals: rustc_span::Globals,
40 }
41
42 impl Globals {
43     fn new(edition: Edition) -> Globals {
44         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),
50         }
51     }
52 }
53
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))
57 }
58
59 pub fn with_default_globals<R>(f: impl FnOnce() -> R) -> R {
60     with_globals(DEFAULT_EDITION, f)
61 }
62
63 scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
64
65 pub mod util {
66     pub mod classify;
67     pub mod comments;
68     pub mod lev_distance;
69     pub mod literal;
70     pub mod map_in_place;
71     pub mod node_count;
72     pub mod parser;
73 }
74
75 pub mod ast;
76 pub mod attr;
77 pub mod entry;
78 pub mod expand;
79 pub mod feature_gate {
80     mod check;
81     pub use check::{check_attribute, check_crate, feature_err, feature_err_issue, get_features};
82 }
83 pub mod mut_visit;
84 pub mod ptr;
85 pub mod show_span;
86 pub use rustc_session::parse as sess;
87 pub mod token;
88 pub mod tokenstream;
89 pub mod visit;
90
91 pub mod print {
92     mod helpers;
93     pub mod pp;
94     pub mod pprust;
95 }
96
97 pub mod early_buffered_lints;
98
99 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
100
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);
106 }
107
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)
111     }
112 }