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