]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/lib.rs
Rollup merge of #67531 - RalfJung:tame-promotion, r=nikomatsakis
[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(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;
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<F, R>(edition: Edition, f: F) -> R
55 where
56     F: FnOnce() -> R,
57 {
58     let globals = Globals::new(edition);
59     GLOBALS.set(&globals, || rustc_span::GLOBALS.set(&globals.rustc_span_globals, f))
60 }
61
62 pub fn with_default_globals<F, R>(f: F) -> R
63 where
64     F: FnOnce() -> R,
65 {
66     with_globals(edition::DEFAULT_EDITION, f)
67 }
68
69 scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
70
71 #[macro_use]
72 pub mod diagnostics {
73     #[macro_use]
74     pub mod macros;
75 }
76
77 pub mod util {
78     pub mod classify;
79     pub mod comments;
80     pub mod lev_distance;
81     pub mod literal;
82     pub mod map_in_place;
83     pub mod node_count;
84     pub mod parser;
85 }
86
87 pub mod ast;
88 pub mod attr;
89 pub mod expand;
90 pub use rustc_span::source_map;
91 pub mod entry;
92 pub mod feature_gate {
93     mod check;
94     pub use check::{check_attribute, check_crate, feature_err, feature_err_issue, get_features};
95 }
96 pub mod mut_visit;
97 pub mod ptr;
98 pub mod show_span;
99 pub use rustc_session::parse as sess;
100 pub use rustc_span::edition;
101 pub use rustc_span::symbol;
102 pub mod token;
103 pub mod tokenstream;
104 pub mod visit;
105
106 pub mod print {
107     mod helpers;
108     pub mod pp;
109     pub mod pprust;
110 }
111
112 pub mod early_buffered_lints;
113
114 /// Requirements for a `StableHashingContext` to be used in this crate.
115 /// This is a hack to allow using the `HashStable_Generic` derive macro
116 /// instead of implementing everything in librustc.
117 pub trait HashStableContext: rustc_span::HashStableContext {}