@@ -98,6 +98,8 @@ iteration, this represents a compile error. Here is the [algorithm][original]:
98
98
[ inv ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/expand/struct.Invocation.html
99
99
[ `AstFragment` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/expand/enum.AstFragment.html
100
100
101
+ ### Error Recovery
102
+
101
103
If we make no progress in an iteration, then we have reached a compilation
102
104
error (e.g. an undefined macro). We attempt to recover from failures
103
105
(unresolved macros or imports) for the sake of diagnostics. This allows
@@ -108,6 +110,8 @@ fail at this point. The recovery happens by expanding unresolved macros into
108
110
109
111
[ err ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/ast/enum.ExprKind.html#variant.Err
110
112
113
+ ### Name Resolution
114
+
111
115
Notice that name resolution is involved here: we need to resolve imports and
112
116
macro names in the above algorithm. This is done in
113
117
[ ` rustc_resolve::macros ` ] [ mresolve ] , which resolves macro paths, validates
@@ -118,28 +122,6 @@ chapter](./name-resolution.md).
118
122
119
123
[ mresolve ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_resolve/macros/index.html
120
124
121
- Here are some other notable data structures involved in expansion and integration:
122
- - [ ` Resolver ` ] - a trait used to break crate dependencies. This allows the
123
- resolver services to be used in [ ` rustc_ast ` ] , despite [ ` rustc_resolve ` ] and
124
- pretty much everything else depending on [ ` rustc_ast ` ] .
125
- - [ ` ExtCtxt ` ] /[ ` ExpansionData ` ] - various intermediate data kept and used by expansion
126
- infrastructure in the process of its work
127
- - [ ` Annotatable ` ] - a piece of AST that can be an attribute target, almost same
128
- thing as AstFragment except for types and patterns that can be produced by
129
- macros but cannot be annotated with attributes
130
- - [ ` MacResult ` ] - a "polymorphic" AST fragment, something that can turn into a
131
- different ` AstFragment ` depending on its [ ` AstFragmentKind ` ] - item,
132
- or expression, or pattern etc.
133
-
134
- [ `rustc_ast` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/index.html
135
- [ `rustc_resolve` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_resolve/index.html
136
- [ `Resolver` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/base/trait.Resolver.html
137
- [ `ExtCtxt` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/base/struct.ExtCtxt.html
138
- [ `ExpansionData` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/base/struct.ExpansionData.html
139
- [ `Annotatable` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/base/enum.Annotatable.html
140
- [ `MacResult` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/base/trait.MacResult.html
141
- [ `AstFragmentKind` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/expand/enum.AstFragmentKind.html
142
-
143
125
### Eager Expansion
144
126
145
127
_ Eager expansion_ means that we expand the arguments of a macro invocation
@@ -169,6 +151,30 @@ performs a subset of the things that lazy (normal) expansion. It is done by
169
151
invoking [ ` fully_expand_fragment ` ] [ fef ] on only part of a crate (as opposed to
170
152
whole crate, like we normally do).
171
153
154
+ ### Other Data Structures
155
+
156
+ Here are some other notable data structures involved in expansion and integration:
157
+ - [ ` Resolver ` ] - a trait used to break crate dependencies. This allows the
158
+ resolver services to be used in [ ` rustc_ast ` ] , despite [ ` rustc_resolve ` ] and
159
+ pretty much everything else depending on [ ` rustc_ast ` ] .
160
+ - [ ` ExtCtxt ` ] /[ ` ExpansionData ` ] - various intermediate data kept and used by expansion
161
+ infrastructure in the process of its work
162
+ - [ ` Annotatable ` ] - a piece of AST that can be an attribute target, almost same
163
+ thing as AstFragment except for types and patterns that can be produced by
164
+ macros but cannot be annotated with attributes
165
+ - [ ` MacResult ` ] - a "polymorphic" AST fragment, something that can turn into a
166
+ different ` AstFragment ` depending on its [ ` AstFragmentKind ` ] - item,
167
+ or expression, or pattern etc.
168
+
169
+ [ `rustc_ast` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/index.html
170
+ [ `rustc_resolve` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_resolve/index.html
171
+ [ `Resolver` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/base/trait.Resolver.html
172
+ [ `ExtCtxt` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/base/struct.ExtCtxt.html
173
+ [ `ExpansionData` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/base/struct.ExpansionData.html
174
+ [ `Annotatable` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/base/enum.Annotatable.html
175
+ [ `MacResult` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/base/trait.MacResult.html
176
+ [ `AstFragmentKind` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/expand/enum.AstFragmentKind.html
177
+
172
178
## Hygiene and Hierarchies
173
179
174
180
If you have ever used C/C++ preprocessor macros, you know that there are some
0 commit comments