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
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.
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.
153
156
154
157
For example:
155
158
156
159
```rust,compile_fail,E0659
157
-
mod foo {
158
-
pub struct Qux;
160
+
mod m1 {
161
+
pub struct Ambig;
159
162
}
160
163
161
-
mod bar {
162
-
pub struct Qux;
164
+
mod m2 {
165
+
pub struct Ambig;
163
166
}
164
167
165
-
use foo::*;
166
-
use bar::*; // OK, no name conflict.
168
+
use m1::*;
169
+
use m2::*; // OK, no name conflict.
167
170
168
171
fn ambiguous_use() {
169
-
let x = Qux; // ERROR: `Qux` is ambiguous
172
+
let x = Ambig; // ERROR: `Ambig` is ambiguous
170
173
}
171
174
```
172
175
173
176
```rust
174
-
# modfoo {
175
-
# pubstructQux;
177
+
# modm1 {
178
+
# pubstructAmbig;
176
179
# }
177
180
#
178
-
# modbar {
179
-
# pubstructQux;
181
+
# modm2 {
182
+
# pubstructAmbig;
180
183
# }
181
184
#
182
-
# usefoo::*;
183
-
# usebar::*; // OK, no name conflict.
185
+
# usem1::*;
186
+
# usem2::*; // OK, no name conflict.
184
187
fnambiguous_shadow() {
185
188
// This is permitted, since resolution is not through the ambiguous globs.
186
-
structQux;
187
-
letx=Qux;
189
+
structAmbig;
190
+
letx=Ambig;
188
191
}
189
192
```
190
193
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.
192
195
193
196
```rust
194
-
modfoo {
195
-
pubstructQux;
197
+
modm1 {
198
+
pubstructAmbig;
196
199
}
197
200
198
-
modbar {
199
-
pubusesuper::foo::Qux;
201
+
modm2 {
202
+
pubusesuper::m1::Ambig;
200
203
}
201
204
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
-
pubusebar::*;
206
-
usefoo::*;
205
+
// These both import the same `Ambig`. The visibility of `Ambig` is
206
+
// `pub` because that is the maximum visibility between these two `use`
0 commit comments