1 //! The Rust parser and macro expander.
5 //! This API is completely unstable and subject to change.
7 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
8 html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
9 html_root_url = "https://doc.rust-lang.org/nightly/",
10 test(attr(deny(warnings))))]
12 #![feature(crate_visibility_modifier)]
14 #![feature(rustc_attrs)]
15 #![feature(rustc_diagnostic_macros)]
16 #![feature(slice_sort_by_cached_key)]
17 #![feature(str_escape)]
18 #![feature(step_trait)]
19 #![feature(try_trait)]
20 #![feature(unicode_internals)]
22 #![recursion_limit="256"]
24 #[macro_use] extern crate bitflags;
26 extern crate serialize;
27 #[macro_use] extern crate log;
28 pub extern crate rustc_errors as errors;
29 extern crate syntax_pos;
30 #[macro_use] extern crate rustc_data_structures;
31 extern crate rustc_target;
32 #[macro_use] extern crate scoped_tls;
34 extern crate smallvec;
36 extern crate serialize as rustc_serialize; // used by deriving
38 use rustc_data_structures::sync::Lock;
39 use rustc_data_structures::bit_set::GrowableBitSet;
40 pub use rustc_data_structures::thin_vec::ThinVec;
43 // A variant of 'try!' that panics on an Err. This is used as a crutch on the
44 // way towards a non-panic!-prone parser. It should be used for fatal parsing
45 // errors; eventually we plan to convert all code using panictry to just use
47 macro_rules! panictry {
49 use std::result::Result::{Ok, Err};
50 use errors::FatalError;
61 // A variant of 'panictry!' that works on a Vec<Diagnostic> instead of a single DiagnosticBuilder.
62 macro_rules! panictry_buffer {
63 ($handler:expr, $e:expr) => ({
64 use std::result::Result::{Ok, Err};
65 use errors::{FatalError, DiagnosticBuilder};
70 DiagnosticBuilder::new_diagnostic($handler, e).emit();
79 macro_rules! unwrap_or {
80 ($opt:expr, $default:expr) => {
89 used_attrs: Lock<GrowableBitSet<AttrId>>,
90 known_attrs: Lock<GrowableBitSet<AttrId>>,
91 syntax_pos_globals: syntax_pos::Globals,
97 // We have no idea how many attributes their will be, so just
98 // initiate the vectors with 0 bits. We'll grow them as necessary.
99 used_attrs: Lock::new(GrowableBitSet::new_empty()),
100 known_attrs: Lock::new(GrowableBitSet::new_empty()),
101 syntax_pos_globals: syntax_pos::Globals::new(),
106 pub fn with_globals<F, R>(f: F) -> R
107 where F: FnOnce() -> R
109 let globals = Globals::new();
110 GLOBALS.set(&globals, || {
111 syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
115 scoped_thread_local!(pub static GLOBALS: Globals);
118 pub mod diagnostics {
125 // N.B., this module needs to be declared first so diagnostics are
126 // registered before they are used.
127 pub mod diagnostic_list;
130 pub mod lev_distance;
134 pub mod parser_testing;
152 pub mod feature_gate;
158 pub use syntax_pos::edition;
159 pub use syntax_pos::symbol;
170 pub use syntax_pos::hygiene;
175 pub mod placeholders;
181 pub mod macro_parser;
187 pub mod early_buffered_lints;
192 __build_diagnostic_array! { libsyntax, DIAGNOSTICS }