]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/lib.rs
Rollup merge of #65777 - matthewjasper:allow-impl-trait-expansion, r=davidtwco
[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/",
8        test(attr(deny(warnings))))]
9
10 #![feature(box_syntax)]
11 #![feature(const_fn)]
12 #![feature(const_transmute)]
13 #![feature(crate_visibility_modifier)]
14 #![feature(label_break_value)]
15 #![feature(nll)]
16 #![feature(try_trait)]
17 #![feature(slice_patterns)]
18 #![feature(unicode_internals)]
19
20 #![recursion_limit="256"]
21
22 pub use errors;
23 use rustc_data_structures::sync::Lock;
24 use rustc_index::bit_set::GrowableBitSet;
25 pub use rustc_data_structures::thin_vec::ThinVec;
26 use ast::AttrId;
27 use syntax_pos::edition::Edition;
28
29 #[cfg(test)]
30 mod tests;
31
32 pub const MACRO_ARGUMENTS: Option<&'static str> = Some("macro arguments");
33
34 #[macro_export]
35 macro_rules! unwrap_or {
36     ($opt:expr, $default:expr) => {
37         match $opt {
38             Some(x) => x,
39             None => $default,
40         }
41     }
42 }
43
44 pub struct Globals {
45     used_attrs: Lock<GrowableBitSet<AttrId>>,
46     known_attrs: Lock<GrowableBitSet<AttrId>>,
47     syntax_pos_globals: syntax_pos::Globals,
48 }
49
50 impl Globals {
51     fn new(edition: Edition) -> Globals {
52         Globals {
53             // We have no idea how many attributes there will be, so just
54             // initiate the vectors with 0 bits. We'll grow them as necessary.
55             used_attrs: Lock::new(GrowableBitSet::new_empty()),
56             known_attrs: Lock::new(GrowableBitSet::new_empty()),
57             syntax_pos_globals: syntax_pos::Globals::new(edition),
58         }
59     }
60 }
61
62 pub fn with_globals<F, R>(edition: Edition, f: F) -> R
63     where F: FnOnce() -> R
64 {
65     let globals = Globals::new(edition);
66     GLOBALS.set(&globals, || {
67         syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
68     })
69 }
70
71 pub fn with_default_globals<F, R>(f: F) -> R
72     where F: FnOnce() -> R
73 {
74     with_globals(edition::DEFAULT_EDITION, f)
75 }
76
77 scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
78
79 #[macro_use]
80 pub mod diagnostics {
81     #[macro_use]
82     pub mod macros;
83 }
84
85 pub mod error_codes;
86
87 pub mod util {
88     pub mod lev_distance;
89     pub mod node_count;
90     pub mod parser;
91     pub mod map_in_place;
92 }
93
94 pub mod json;
95
96 pub mod ast;
97 pub mod attr;
98 pub mod source_map;
99 #[macro_use]
100 pub mod config;
101 pub mod entry;
102 pub mod feature_gate;
103 pub mod mut_visit;
104 pub mod parse;
105 pub mod ptr;
106 pub mod show_span;
107 pub use syntax_pos::edition;
108 pub use syntax_pos::symbol;
109 pub mod sess;
110 pub mod tokenstream;
111 pub mod visit;
112
113 pub mod print {
114     pub mod pp;
115     pub mod pprust;
116     mod helpers;
117 }
118
119 pub mod early_buffered_lints;