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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use crate::ast::Spanned;
use crate::compile::{Located, MetaError, MetaRef};
use crate::{Hash, Item, SourceId};
/// A visitor that will be called for every language item compiled.
pub trait CompileVisitor {
/// Called when a meta item is registered.
fn register_meta(&mut self, _meta: MetaRef<'_>) -> Result<(), MetaError> {
Ok(())
}
/// Mark that we've resolved a specific compile meta at the given location.
fn visit_meta(&mut self, _location: &dyn Located, _meta: MetaRef<'_>) -> Result<(), MetaError> {
Ok(())
}
/// Visit a variable use.
fn visit_variable_use(
&mut self,
_source_id: SourceId,
_var_span: &dyn Spanned,
_span: &dyn Spanned,
) -> Result<(), MetaError> {
Ok(())
}
/// Visit something that is a module.
fn visit_mod(&mut self, _location: &dyn Located) -> Result<(), MetaError> {
Ok(())
}
/// Visit anterior `///`-style comments, and interior `//!`-style doc
/// comments for an item.
///
/// This may be called several times for a single item. Each attribute
/// should eventually be combined for the full doc string.
///
/// This can be called in any order, before or after
/// [CompileVisitor::visit_meta] for any given item.
fn visit_doc_comment(
&mut self,
_location: &dyn Located,
_item: &Item,
_hash: Hash,
_docstr: &str,
) -> Result<(), MetaError> {
Ok(())
}
/// Visit anterior `///`-style comments, and interior `//!`-style doc
/// comments for a field contained in a struct / enum variant struct.
///
/// This may be called several times for a single field. Each attribute
/// should eventually be combined for the full doc string.
fn visit_field_doc_comment(
&mut self,
_location: &dyn Located,
_item: &Item,
_hash: Hash,
_field: &str,
_docstr: &str,
) -> Result<(), MetaError> {
Ok(())
}
}
/// A [CompileVisitor] which does nothing.
#[cfg(feature = "std")]
pub(crate) struct NoopCompileVisitor(());
#[cfg(feature = "std")]
impl NoopCompileVisitor {
/// Construct a new noop compile visitor.
pub(crate) const fn new() -> Self {
Self(())
}
}
#[cfg(feature = "std")]
impl CompileVisitor for NoopCompileVisitor {}