Skip to content

Commit b59fd3e

Browse files
committed
Add ref_t!, result!, make_visit! and P!
1 parent 81f6b09 commit b59fd3e

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

compiler/rustc_ast/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#![feature(box_patterns)]
1616
#![feature(if_let_guard)]
1717
#![feature(let_chains)]
18+
#![feature(macro_metavar_expr)]
1819
#![feature(negative_impls)]
1920
#![feature(never_type)]
2021
#![feature(rustdoc_internals)]

compiler/rustc_ast/src/visitors.rs

+43
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,49 @@ macro_rules! macro_if {
2626

2727
macro_rules! make_ast_visitor {
2828
($trait: ident $(<$lt: lifetime>)? $(, $mut: ident)?) => {
29+
#[allow(unused)]
30+
macro_rules! ref_t {
31+
($t: ty) => { & $($lt)? $($mut)? $t };
32+
}
33+
34+
#[allow(unused)]
35+
macro_rules! result {
36+
($V: ty) => {
37+
macro_if!($($mut)? { () } else { <$V>::Result })
38+
};
39+
() => {
40+
result!(Self)
41+
};
42+
}
43+
44+
#[allow(unused)]
45+
macro_rules! make_visit {
46+
(
47+
$ty: ty
48+
$$(, $$($arg: ident)? $$(_ $ignored_arg: ident)?: $arg_ty: ty)*;
49+
$visit: ident, $walk: ident
50+
) => {
51+
fn $visit(
52+
&mut self,
53+
node: ref_t!($ty)
54+
$$(, $$($arg)? $$(#[allow(unused)] $ignored_arg)?: $arg_ty)*
55+
) -> result!() {
56+
$walk(self, node $$($$(, $arg)?)*)
57+
}
58+
};
59+
}
60+
61+
#[allow(unused)]
62+
macro_rules! P {
63+
($t: ty) => {
64+
macro_if!{$($mut)? {
65+
P<$t>
66+
} else {
67+
$t
68+
}}
69+
};
70+
}
71+
2972
/// Each method of the traits `Visitor` and `MutVisitor` trait is a hook
3073
/// to be potentially overridden. Each method's default implementation
3174
/// recursively visits the substructure of the input via the corresponding

0 commit comments

Comments
 (0)