Skip to content

Commit 9a213f7

Browse files
committed
change idents for globvsglob example
1 parent db220a9 commit 9a213f7

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

src/names/name-resolution.md

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ use m1::ambig;
130130
fn f() {
131131
// This shadows `ambig` in the inner scope.
132132
use m2::ambig;
133-
// The `use` from the inner scope is used here.
133+
// The inner candidate is selected here
134+
// as the resolution of `ambig`.
134135
use ambig::C;
135136
const { assert!(C == 2) };
136137
}
@@ -148,65 +149,67 @@ r[names.resolution.expansion.imports.ambiguity]
148149
r[names.resolution.expansion.imports.ambiguity.intro]
149150
Some situations are an error when there is an ambiguity as to which macro definition, `use` declaration, or module an import or macro invocation's name refers to. This happens when there are two name candidates that do not resolve to the same entity where neither candidate is [permitted] to shadow the other.
150151

152+
TODO rewrite
153+
151154
r[names.resolution.expansion.imports.ambiguity.glob-vs-glob]
152155
Names may not be resolved through ambiguous glob imports. Glob imports are allowed to import conflicting names in the same namespace as long as the name is not used. Names with conflicting candidates from ambiguous glob imports may still be shadowed by non glob imports and used without producing an error. The errors occur at time of use, not time of import.
153156

154157
For example:
155158

156159
```rust,compile_fail,E0659
157-
mod foo {
158-
pub struct Qux;
160+
mod m1 {
161+
pub struct Ambig;
159162
}
160163
161-
mod bar {
162-
pub struct Qux;
164+
mod m2 {
165+
pub struct Ambig;
163166
}
164167
165-
use foo::*;
166-
use bar::*; // OK, no name conflict.
168+
use m1::*;
169+
use m2::*; // OK, no name conflict.
167170
168171
fn ambiguous_use() {
169-
let x = Qux; // ERROR: `Qux` is ambiguous
172+
let x = Ambig; // ERROR: `Ambig` is ambiguous
170173
}
171174
```
172175

173176
```rust
174-
# mod foo {
175-
# pub struct Qux;
177+
# mod m1 {
178+
# pub struct Ambig;
176179
# }
177180
#
178-
# mod bar {
179-
# pub struct Qux;
181+
# mod m2 {
182+
# pub struct Ambig;
180183
# }
181184
#
182-
# use foo::*;
183-
# use bar::*; // OK, no name conflict.
185+
# use m1::*;
186+
# use m2::*; // OK, no name conflict.
184187
fn ambiguous_shadow() {
185188
// This is permitted, since resolution is not through the ambiguous globs.
186-
struct Qux;
187-
let x = Qux;
189+
struct Ambig;
190+
let x = Ambig;
188191
}
189192
```
190193

191-
Multiple glob imports are allowed to import the same name, and that name is allowed to be used if the imports are of the same item (following re-exports). The visibility of the name is the maximum visibility of the imports. For example:
194+
Multiple glob imports are allowed to import the same name, and that name is allowed to be used if the imports are of the same item (following re-exports). The visibility of the name is the maximum visibility of the imports.
192195

193196
```rust
194-
mod foo {
195-
pub struct Qux;
197+
mod m1 {
198+
pub struct Ambig;
196199
}
197200

198-
mod bar {
199-
pub use super::foo::Qux;
201+
mod m2 {
202+
pub use super::m1::Ambig;
200203
}
201204

202-
// These both import the same `Qux`. The visibility of `Qux`
203-
// is `pub` because that is the maximum visibility between
204-
// these two `use` declarations.
205-
pub use bar::*;
206-
use foo::*;
205+
// These both import the same `Ambig`. The visibility of `Ambig` is
206+
// `pub` because that is the maximum visibility between these two `use`
207+
// declarations.
208+
pub use m2::*;
209+
use m1::*;
207210

208211
fn main() {
209-
let _: Qux = Qux;
212+
let _: Ambig = Ambig;
210213
}
211214
```
212215

0 commit comments

Comments
 (0)