1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use super::*;
use crate::{
common::{source::Span, NodeId},
param_env::ParamEnv,
ty, value,
};
use std::collections::HashMap;
pub trait AcceptVisitor<'a> {
fn accept(&'a self, _visitor: &mut dyn Visitor<'a>);
}
pub trait WalkVisitor<'a> {
fn walk(&'a self, _visitor: &mut dyn Visitor<'a>) {}
}
impl<'a> WalkVisitor<'a> for bool {}
impl<'a> WalkVisitor<'a> for usize {}
impl<'a> WalkVisitor<'a> for NodeId {}
impl<'a> WalkVisitor<'a> for ParamEnv {}
impl<'a> WalkVisitor<'a> for Span {}
impl<'a> WalkVisitor<'a> for ty::UnpackedType<'a> {}
impl<'a> WalkVisitor<'a> for ty::Sign {}
impl<'a> WalkVisitor<'a> for ty::Domain {}
impl<'a> WalkVisitor<'a> for value::Value<'_> {}
impl<'a, T: WalkVisitor<'a>> WalkVisitor<'a> for &'_ T {
fn walk(&'a self, visitor: &mut dyn Visitor<'a>) {
(*self).walk(visitor);
}
}
impl<'a, T: WalkVisitor<'a>> WalkVisitor<'a> for Vec<T> {
fn walk(&'a self, visitor: &mut dyn Visitor<'a>) {
for x in self {
x.walk(visitor);
}
}
}
impl<'a, K, T: WalkVisitor<'a>> WalkVisitor<'a> for HashMap<K, T> {
fn walk(&'a self, visitor: &mut dyn Visitor<'a>) {
for x in self.values() {
x.walk(visitor);
}
}
}
moore_derive::derive_visitor!();