Skip to content

Commit 1dcac03

Browse files
committed
clarify shadowing behavior for imports
1 parent b6acfd7 commit 1dcac03

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/names/name-resolution.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,9 @@ use m::A::V; // ERROR: Unresolved import `m::A::V`.
110110
```
111111

112112
r[names.resolution.expansion.imports.shadowing]
113-
Shadowing of names with a `use` declaration is permitted only with:
114-
115-
- [`use` glob shadowing]
116-
- [Macro textual scope shadowing]
117-
- TODO: Also `use` declarations in anonymous scopes.
118-
119-
Example for the TODO:
113+
Names introduced via `use` declarations in an [outer scope] are shadowed by
114+
candidates in the same namespace with the same name from an inner scope except
115+
where otherwise restricted by [name resolution ambiguities].
120116

121117
```rust
122118
pub mod foo {
@@ -127,17 +123,24 @@ pub mod foo {
127123

128124
pub mod bar {
129125
pub mod baz {
130-
pub struct Name;
126+
pub struct Name(pub ());
131127
}
132128
}
133129

134-
use foo::baz::Name;
130+
use foo::baz;
135131
fn f() {
136-
use bar::baz::Name;
137-
Name;
132+
use bar::baz;
133+
use baz::Name
134+
Name(());
138135
}
139136
```
140137

138+
r[names.resolution.expansion.imports.shadowing.shared-scope]
139+
Shadowing of names introduced via `use` declarations within a single scope is permitted in the following situations:
140+
141+
- [`use` glob shadowing]
142+
- [Macro textual scope shadowing]
143+
141144
r[names.resolution.expansion.imports.ambiguity]
142145
#### Ambiguities
143146

@@ -389,6 +392,7 @@ r[names.resolution.type-relative]
389392
[item definitions]: ../items.md
390393
[macro invocations]: ../macros.md#macro-invocation
391394
[macro textual scope shadowing]: ../macros-by-example.md#r-macro.decl.scope.textual.shadow
395+
[name resolution ambiguities]: #r-names.resolution.expansion.imports.ambiguity
392396
[namespaces]: ../names/namespaces.md
393397
[outer scope]: #r-names.resolution.general.scopes
394398
[path-based scope]: ../macros.md#r-macro.invocation.name-resolution

0 commit comments

Comments
 (0)