Skip to content

Commit fb51ac5

Browse files
committed
split expansion intro into multiple sections
1 parent 2191910 commit fb51ac5

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/names/name-resolution.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,24 @@ r[names.resolution.expansion]
1717
r[names.resolution.expansion.intro]
1818
Expansion-time name resolution is the stage of name resolution necessary to complete macro expansion and fully generate a crate's AST. This stage requires the resolution of macro invocations and use declarations. Resolving use declarations is required to resolve [path-based scope] macro invocations. Resolving macro invocations is required in order to expand them.
1919

20-
After expansion-time name resolution, the AST must not contain any unexpanded macro invocations. Every macro invocation resolves to a valid definition that exists in the final AST or an external crate. The resolution of imports must be *stable*. After expansion, imports in the fully expanded AST must resolve to the same definition, regardless of the order in which macros are expanded. Once the crate has been fully expanded all speculative import resolutions are validated to ensure that no new ambiguities were introduced by macro expansion.
20+
r[names.resolution.expansion.unresolved-invocations]
21+
After expansion-time name resolution, the AST must not contain any unexpanded macro invocations. Every macro invocation resolves to a valid definition that exists in the final AST or an external crate.
22+
23+
```rust,compile_fail
24+
fn main() {
25+
foo!(); // ERROR: cannot find macro `foo` in this scope
26+
}
27+
```
28+
29+
r[names.resolution.expansion.expansion-order-stability]
30+
The resolution of names must be *stable*. After expansion, names in the fully expanded AST must resolve to the same definition, regardless of the order in which macros are expanded.
31+
32+
r[names.resolution.expansion.speculation]
33+
All name resolution candidates selected during macro expansion are considering speculative. Once the crate has been fully expanded all speculative import resolutions are validated to ensure that no new ambiguities were introduced by macro expansion.
2134

2235
> [!NOTE]
2336
>
24-
> Due to the iterative nature of macro expansion, this causes so called time traveling ambiguities, such as when a glob import introduces an item that is ambiguous with its own base path.
37+
> Due to the iterative nature of macro expansion, this causes so called time traveling ambiguities, such as when a macro or glob import introduces an item that is ambiguous with its own base path.
2538
>
2639
> ```rust,compile_fail,E0659
2740
> macro_rules! m {
@@ -329,6 +342,7 @@ r[names.resolution.type-dependent]
329342
330343
[Macros]: ../macros.md
331344
[`let` bindings]: ../statements.md#let-statements
345+
[`use` glob shadowing]: ../items/use-declarations.md#r-items.use.glob.shadowing
332346
[item definitions]: ../items.md
333347
[macro invocations]: ../macros.md#macro-invocation
334348
[macro textual scope shadowing]: ../macros-by-example.md#r-macro.decl.scope.textual.shadow
@@ -338,5 +352,4 @@ r[names.resolution.type-dependent]
338352
[scope]: ../names/scopes.md
339353
[sub-namespace]: ../names/namespaces.md#r-names.namespaces.sub-namespaces
340354
[use declarations]: ../items/use-declarations.md
341-
[use glob shadowing]: ../items/use-declarations.md#r-items.use.glob.shadowing
342355
[visibility]: ../visibility-and-privacy.md

0 commit comments

Comments
 (0)