You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/items/use-declarations.md
+113Lines changed: 113 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -398,6 +398,13 @@ r[items.use.ambiguities]
398
398
r[items.use.ambiguities.intro]
399
399
Some situations are an error when there is an ambiguity as to which name a `use` declaration refers. This happens when there are two name candidates that do not resolve to the same entity.
* it is an error to name an item through ambiguous use declarations
404
+
* two globs imports which both have an item matching that name where the items are different
405
+
* this is still an error even if there is a third non glob binding resolution to an item with the same name
406
+
* it is not an error to have two glob imports which include items which would be ambiguous so long as you do not name one of those items through the ambiguous glob imports
407
+
401
408
r[items.use.ambiguities.glob]
402
409
Glob imports are allowed to import conflicting names in the same namespace as long as the name is not used.
* derive helpers used before their associated derive may not shadow other attributes or other derive helpers that are otherwise in scope after their derive
460
+
* TODO example? This ones harder to do concisely afaik
_Name resolution_ is the process of tying paths and other identifiers to the
7
+
declarations of those entities. Names are segregated into different
8
+
[namespaces], allowing entities in different namespaces to share the same name
9
+
without conflict. Each name is valid within a [scope], or a region of source
10
+
text where that name may be referenced. Access to certain names may be
11
+
restricted based on their [visibility].
12
+
13
+
* Names are resolved at three different stages of compilation.
14
+
*[Macros] and [use declarations] are resolved during macro expansion.
15
+
* This stage of resolution is known as "Early Resolution".
16
+
* Associated consts and functions, methods, and enum variants are resolved during type checking.
17
+
* This stage of resolution is known as type dependent resolution.
18
+
* in reality this is never talked about so I doubt it has a name yet.
19
+
* All other names are resolved during AST lowering.
20
+
* This stage of resolution is known as "Late Resolution".
21
+
* Note, late resolution occurs before type dependent resolution.
22
+
23
+
r[names.resolution.early]
24
+
## Early name resolution
25
+
26
+
r[names.resolution.early.intro]
27
+
28
+
* early name resolution is the part of name resolution that happens during macro expansion
29
+
* early name resolution includes the resolution of imports and macros
30
+
* early name resolution is the minimum amount of resolution required to resolve macro invocations so they can be expanded.
31
+
* resolving imports is necessary to resolve macro invocations (as of 2018 edition i think, pretty sure this applies specifically to path-based scope for macros)
32
+
* resolving macro invocations and tying them to macro declarations is necessary so they can be expanded
33
+
* this process is iterative and repeats until there are no remaining unexpanded macro invocations (fixed point algorithm)
34
+
* Post expansion these resolutions are checked again to ensure no new ambiguities were introduced by the expansion process
35
+
* This causes so called time traveling ambiguities, such as when a glob import introduces an item that is ambiguous with its own base path.
36
+
37
+
TODO Document some time traveling ambiguitie examples, place in relevant ambiguity section
38
+
39
+
r[names.resolution.early.imports]
40
+
41
+
* All imports are fully resolved at this point.
42
+
* imports of names that cannot be fully resolved during macro expansion, such as those depending on type information, are not supported and will produce an error.
43
+
44
+
TODO example of unsupported type dependent import
45
+
46
+
r[names.resolution.early.imports.shadowing]
47
+
48
+
The following is a list of situations where shadowing of use declarations is permitted:
* shadowing and ambiguity may or may not represent the same section or one may be a subsection of the other
57
+
58
+
* Builtin Attributes
59
+
* Derive Helpers
60
+
* Textual Vs Path-based Scope
61
+
* Glob vs Outer
62
+
* Glob vs Glob
63
+
*~~Glob vs Expanded~~ pretty certain we don't want to mention this one
64
+
* More Expanded vs Outer
65
+
66
+
r[names.resolution.early.macros]
67
+
68
+
* .visitation-order
69
+
* derive helpers
70
+
* not visited when resolving derive macros in the parent scope (starting scope)
71
+
* derive helpers compat
72
+
* always visited
73
+
* macro rules bindings (textual scope macros)
74
+
* always visited
75
+
* modules (path-based scope macros)
76
+
* always visited
77
+
* macrouseprelude
78
+
* not visited in 2018 and later when `#[no_implicit_prelude]` is present
79
+
* stdlibprelude
80
+
* always visited for macro resolutions
81
+
* builtinattrs
82
+
* always visited
83
+
* .subnamespaces
84
+
* macros are split into two subnamespaces, one for bang macros, and the other for attributes and derives. Resolution candidates from the incorrect subnamespace are ignored
0 commit comments