]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/lib.rs
Rollup merge of #65544 - dorfsmay:doc_keyword_break, r=Dylan-DPC
[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 // A variant of 'panictry!' that works on a Vec<Diagnostic> instead of a single DiagnosticBuilder.
35 macro_rules! panictry_buffer {
36     ($handler:expr, $e:expr) => ({
37         use std::result::Result::{Ok, Err};
38         use errors::FatalError;
39         match $e {
40             Ok(e) => e,
41             Err(errs) => {
42                 for e in errs {
43                     $handler.emit_diagnostic(&e);
44                 }
45                 FatalError.raise()
46             }
47         }
48     })
49 }
50
51 #[macro_export]
52 macro_rules! unwrap_or {
53     ($opt:expr, $default:expr) => {
54         match $opt {
55             Some(x) => x,
56             None => $default,
57         }
58     }
59 }
60
61 pub struct Globals {
62     used_attrs: Lock<GrowableBitSet<AttrId>>,
63     known_attrs: Lock<GrowableBitSet<AttrId>>,
64     syntax_pos_globals: syntax_pos::Globals,
65 }
66
67 impl Globals {
68     fn new(edition: Edition) -> Globals {
69         Globals {
70             // We have no idea how many attributes there will be, so just
71             // initiate the vectors with 0 bits. We'll grow them as necessary.
72             used_attrs: Lock::new(GrowableBitSet::new_empty()),
73             known_attrs: Lock::new(GrowableBitSet::new_empty()),
74             syntax_pos_globals: syntax_pos::Globals::new(edition),
75         }
76     }
77 }
78
79 pub fn with_globals<F, R>(edition: Edition, f: F) -> R
80     where F: FnOnce() -> R
81 {
82     let globals = Globals::new(edition);
83     GLOBALS.set(&globals, || {
84         syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
85     })
86 }
87
88 pub fn with_default_globals<F, R>(f: F) -> R
89     where F: FnOnce() -> R
90 {
91     with_globals(edition::DEFAULT_EDITION, f)
92 }
93
94 scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
95
96 #[macro_use]
97 pub mod diagnostics {
98     #[macro_use]
99     pub mod macros;
100 }
101
102 pub mod error_codes;
103
104 pub mod util {
105     pub mod lev_distance;
106     pub mod node_count;
107     pub mod parser;
108     pub mod map_in_place;
109 }
110
111 pub mod json;
112
113 pub mod ast;
114 pub mod attr;
115 pub mod source_map;
116 #[macro_use]
117 pub mod config;
118 pub mod entry;
119 pub mod feature_gate;
120 pub mod mut_visit;
121 pub mod parse;
122 pub mod ptr;
123 pub mod show_span;
124 pub use syntax_pos::edition;
125 pub use syntax_pos::symbol;
126 pub mod sess;
127 pub mod tokenstream;
128 pub mod visit;
129
130 pub mod print {
131     pub mod pp;
132     pub mod pprust;
133     mod helpers;
134 }
135
136 pub mod early_buffered_lints;