]> git.lizzy.rs Git - rust.git/blob - src/librustc_ast/lib.rs
Rollup merge of #74066 - thomcc:optimize-is-ascii, r=nagisa
[rust.git] / src / librustc_ast / 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/", test(attr(deny(warnings))))]
8 #![feature(bool_to_option)]
9 #![feature(box_syntax)]
10 #![cfg_attr(bootstrap, feature(const_if_match))]
11 #![feature(const_fn)] // For the `transmute` in `P::new`
12 #![feature(const_panic)]
13 #![cfg_attr(not(bootstrap), feature(const_fn_transmute))]
14 #![feature(crate_visibility_modifier)]
15 #![feature(label_break_value)]
16 #![feature(nll)]
17 #![feature(or_patterns)]
18 #![feature(try_trait)]
19 #![feature(unicode_internals)]
20 #![recursion_limit = "256"]
21
22 // FIXME(#56935): Work around ICEs during cross-compilation.
23 #[allow(unused)]
24 extern crate rustc_macros;
25
26 #[macro_export]
27 macro_rules! unwrap_or {
28     ($opt:expr, $default:expr) => {
29         match $opt {
30             Some(x) => x,
31             None => $default,
32         }
33     };
34 }
35
36 pub mod util {
37     pub mod classify;
38     pub mod comments;
39     pub mod lev_distance;
40     pub mod literal;
41     pub mod parser;
42 }
43
44 pub mod ast;
45 pub mod attr;
46 pub use attr::{with_default_session_globals, with_session_globals, SESSION_GLOBALS};
47 pub mod crate_disambiguator;
48 pub mod entry;
49 pub mod expand;
50 pub mod mut_visit;
51 pub mod node_id;
52 pub mod ptr;
53 pub mod token;
54 pub mod tokenstream;
55 pub mod visit;
56
57 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
58
59 /// Requirements for a `StableHashingContext` to be used in this crate.
60 /// This is a hack to allow using the `HashStable_Generic` derive macro
61 /// instead of implementing everything in librustc_middle.
62 pub trait HashStableContext: rustc_span::HashStableContext {
63     fn hash_attr(&mut self, _: &ast::Attribute, hasher: &mut StableHasher);
64 }
65
66 impl<AstCtx: crate::HashStableContext> HashStable<AstCtx> for ast::Attribute {
67     fn hash_stable(&self, hcx: &mut AstCtx, hasher: &mut StableHasher) {
68         hcx.hash_attr(self, hasher)
69     }
70 }