]> git.proxmox.com Git - rustc.git/blame - src/libsyntax/lib.rs
New upstream version 1.41.1+dfsg1
[rustc.git] / src / libsyntax / lib.rs
CommitLineData
1a4d82fc
JJ
1//! The Rust parser and macro expander.
2//!
3//! # Note
4//!
5//! This API is completely unstable and subject to change.
6
9fa01778 7#![doc(html_root_url = "https://doc.rust-lang.org/nightly/",
92a42be0 8 test(attr(deny(warnings))))]
1a4d82fc 9
60c5eb7d 10#![feature(bool_to_option)]
416331ca 11#![feature(box_syntax)]
dc9dc135
XL
12#![feature(const_fn)]
13#![feature(const_transmute)]
8faf50e0 14#![feature(crate_visibility_modifier)]
9fa01778 15#![feature(label_break_value)]
60c5eb7d 16#![feature(matches_macro)]
0bf4aa26 17#![feature(nll)]
b7449926 18#![feature(try_trait)]
e74abb32 19#![feature(slice_patterns)]
8faf50e0 20#![feature(unicode_internals)]
1a4d82fc 21
83c7162d 22#![recursion_limit="256"]
ea8adc8c 23
9fa01778 24pub use errors;
0531ce1d 25use rustc_data_structures::sync::Lock;
e74abb32 26use rustc_index::bit_set::GrowableBitSet;
b7449926
XL
27pub use rustc_data_structures::thin_vec::ThinVec;
28use ast::AttrId;
dc9dc135
XL
29use syntax_pos::edition::Edition;
30
cc61c64b
XL
31#[macro_export]
32macro_rules! unwrap_or {
33 ($opt:expr, $default:expr) => {
34 match $opt {
35 Some(x) => x,
36 None => $default,
37 }
38 }
39}
40
94b46f34 41pub struct Globals {
0bf4aa26
XL
42 used_attrs: Lock<GrowableBitSet<AttrId>>,
43 known_attrs: Lock<GrowableBitSet<AttrId>>,
0531ce1d
XL
44 syntax_pos_globals: syntax_pos::Globals,
45}
46
47impl Globals {
dc9dc135 48 fn new(edition: Edition) -> Globals {
0531ce1d 49 Globals {
e74abb32 50 // We have no idea how many attributes there will be, so just
b7449926 51 // initiate the vectors with 0 bits. We'll grow them as necessary.
0bf4aa26
XL
52 used_attrs: Lock::new(GrowableBitSet::new_empty()),
53 known_attrs: Lock::new(GrowableBitSet::new_empty()),
dc9dc135 54 syntax_pos_globals: syntax_pos::Globals::new(edition),
0531ce1d
XL
55 }
56 }
57}
58
dc9dc135 59pub fn with_globals<F, R>(edition: Edition, f: F) -> R
0531ce1d
XL
60 where F: FnOnce() -> R
61{
dc9dc135 62 let globals = Globals::new(edition);
0531ce1d
XL
63 GLOBALS.set(&globals, || {
64 syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
65 })
66}
67
dc9dc135
XL
68pub fn with_default_globals<F, R>(f: F) -> R
69 where F: FnOnce() -> R
70{
71 with_globals(edition::DEFAULT_EDITION, f)
72}
73
9fa01778 74scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
0531ce1d 75
3157f602
XL
76#[macro_use]
77pub mod diagnostics {
78 #[macro_use]
79 pub mod macros;
3157f602
XL
80}
81
970d7e83 82pub mod util {
60c5eb7d
XL
83 pub mod classify;
84 pub mod comments;
92a42be0 85 pub mod lev_distance;
60c5eb7d 86 pub mod literal;
92a42be0
SL
87 pub mod node_count;
88 pub mod parser;
9fa01778 89 pub mod map_in_place;
970d7e83 90}
223e47cc 91
223e47cc 92pub mod ast;
1a4d82fc 93pub mod attr;
e74abb32 94pub mod expand;
60c5eb7d 95pub use syntax_pos::source_map;
e9174d1e 96pub mod entry;
60c5eb7d
XL
97pub mod feature_gate {
98 mod check;
99 pub use check::{check_crate, check_attribute, get_features, feature_err, feature_err_issue};
100}
9fa01778 101pub mod mut_visit;
1a4d82fc
JJ
102pub mod ptr;
103pub mod show_span;
94b46f34 104pub use syntax_pos::edition;
cc61c64b 105pub use syntax_pos::symbol;
60c5eb7d
XL
106pub use rustc_session::parse as sess;
107pub mod token;
3157f602 108pub mod tokenstream;
1a4d82fc 109pub mod visit;
223e47cc
LB
110
111pub mod print {
112 pub mod pp;
113 pub mod pprust;
416331ca 114 mod helpers;
223e47cc
LB
115}
116
8faf50e0 117pub mod early_buffered_lints;
60c5eb7d
XL
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.
122pub trait HashStableContext: syntax_pos::HashStableContext {}