]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_ast/src/lib.rs
1e6da044ec03969c4e05353829e831cee5788ec3
[rust.git] / compiler / rustc_ast / src / 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(
8     html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/",
9     test(attr(deny(warnings)))
10 )]
11 #![feature(box_syntax)]
12 #![feature(box_patterns)]
13 #![feature(const_fn)] // For the `transmute` in `P::new`
14 #![feature(const_fn_transmute)]
15 #![feature(const_panic)]
16 #![feature(crate_visibility_modifier)]
17 #![feature(iter_zip)]
18 #![feature(label_break_value)]
19 #![feature(nll)]
20 #![cfg_attr(bootstrap, feature(or_patterns))]
21 #![recursion_limit = "256"]
22
23 #[macro_use]
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 literal;
40     pub mod parser;
41 }
42
43 pub mod ast;
44 pub mod ast_like;
45 pub mod attr;
46 pub mod entry;
47 pub mod expand;
48 pub mod mut_visit;
49 pub mod node_id;
50 pub mod ptr;
51 pub mod token;
52 pub mod tokenstream;
53 pub mod visit;
54
55 pub use self::ast::*;
56 pub use self::ast_like::AstLike;
57
58 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
59
60 /// Requirements for a `StableHashingContext` to be used in this crate.
61 /// This is a hack to allow using the `HashStable_Generic` derive macro
62 /// instead of implementing everything in `rustc_middle`.
63 pub trait HashStableContext: rustc_span::HashStableContext {
64     fn hash_attr(&mut self, _: &ast::Attribute, hasher: &mut StableHasher);
65 }
66
67 impl<AstCtx: crate::HashStableContext> HashStable<AstCtx> for ast::Attribute {
68     fn hash_stable(&self, hcx: &mut AstCtx, hasher: &mut StableHasher) {
69         hcx.hash_attr(self, hasher)
70     }
71 }