]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/lib.rs
Rollup merge of #67337 - oli-obk:no_mut_static_ref_from_const, r=RalfJung
[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)]
11 #![feature(const_transmute)]
12 #![feature(crate_visibility_modifier)]
13 #![feature(label_break_value)]
14 #![feature(matches_macro)]
15 #![feature(nll)]
16 #![feature(try_trait)]
17 #![feature(slice_patterns)]
18 #![feature(unicode_internals)]
19 #![recursion_limit = "256"]
20
21 use ast::AttrId;
22 pub use errors;
23 use rustc_data_structures::sync::Lock;
24 use rustc_index::bit_set::GrowableBitSet;
25 use syntax_pos::edition::Edition;
26
27 #[macro_export]
28 macro_rules! unwrap_or {
29     ($opt:expr, $default:expr) => {
30         match $opt {
31             Some(x) => x,
32             None => $default,
33         }
34     };
35 }
36
37 pub struct Globals {
38     used_attrs: Lock<GrowableBitSet<AttrId>>,
39     known_attrs: Lock<GrowableBitSet<AttrId>>,
40     syntax_pos_globals: syntax_pos::Globals,
41 }
42
43 impl Globals {
44     fn new(edition: Edition) -> Globals {
45         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),
51         }
52     }
53 }
54
55 pub fn with_globals<F, R>(edition: Edition, f: F) -> R
56 where
57     F: FnOnce() -> R,
58 {
59     let globals = Globals::new(edition);
60     GLOBALS.set(&globals, || syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f))
61 }
62
63 pub fn with_default_globals<F, R>(f: F) -> R
64 where
65     F: FnOnce() -> R,
66 {
67     with_globals(edition::DEFAULT_EDITION, f)
68 }
69
70 scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
71
72 #[macro_use]
73 pub mod diagnostics {
74     #[macro_use]
75     pub mod macros;
76 }
77
78 pub mod util {
79     pub mod classify;
80     pub mod comments;
81     pub mod lev_distance;
82     pub mod literal;
83     pub mod map_in_place;
84     pub mod node_count;
85     pub mod parser;
86 }
87
88 pub mod ast;
89 pub mod attr;
90 pub mod expand;
91 pub use syntax_pos::source_map;
92 pub mod entry;
93 pub mod feature_gate {
94     mod check;
95     pub use check::{check_attribute, check_crate, feature_err, feature_err_issue, get_features};
96 }
97 pub mod mut_visit;
98 pub mod ptr;
99 pub mod show_span;
100 pub use rustc_session::parse as sess;
101 pub use syntax_pos::edition;
102 pub use syntax_pos::symbol;
103 pub mod token;
104 pub mod tokenstream;
105 pub mod visit;
106
107 pub mod print {
108     mod helpers;
109     pub mod pp;
110     pub mod pprust;
111 }
112
113 pub mod early_buffered_lints;
114
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 {}