]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/lib.rs
Further HashStable_Generic derives.
[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 #[macro_use] extern crate rustc_macros;
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 pub mod mut_visit;
99 pub mod ptr;
100 pub mod show_span;
101 pub use syntax_pos::edition;
102 pub use syntax_pos::symbol;
103 pub mod sess;
104 pub mod token;
105 pub mod tokenstream;
106 pub mod visit;
107
108 pub mod print {
109     pub mod pp;
110     pub mod pprust;
111     mod helpers;
112 }
113
114 pub mod early_buffered_lints;