@@ -116,17 +116,14 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
116
116
id : NodeId ,
117
117
parent_prefix : & [ Segment ] ,
118
118
nested : bool ,
119
- mut uniform_paths_canary_emitted : bool ,
120
119
// The whole `use` item
121
120
parent_scope : ParentScope < ' a > ,
122
121
item : & Item ,
123
122
vis : ty:: Visibility ,
124
123
root_span : Span ,
125
124
) {
126
- debug ! ( "build_reduced_graph_for_use_tree(parent_prefix={:?}, \
127
- uniform_paths_canary_emitted={}, \
128
- use_tree={:?}, nested={})",
129
- parent_prefix, uniform_paths_canary_emitted, use_tree, nested) ;
125
+ debug ! ( "build_reduced_graph_for_use_tree(parent_prefix={:?}, use_tree={:?}, nested={})" ,
126
+ parent_prefix, use_tree, nested) ;
130
127
131
128
let uniform_paths =
132
129
self . session . rust_2018 ( ) &&
@@ -158,101 +155,6 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
158
155
let prefix: Vec < _ > = root. into_iter ( ) . chain ( prefix_iter ( ) ) . collect ( ) ;
159
156
160
157
debug ! ( "build_reduced_graph_for_use_tree: prefix={:?}" , prefix) ;
161
-
162
- // `#[feature(uniform_paths)]` allows an unqualified import path,
163
- // e.g. `use x::...;` to resolve not just globally (`use ::x::...;`)
164
- // but also relatively (`use self::x::...;`). To catch ambiguities
165
- // that might arise from both of these being available and resolution
166
- // silently picking one of them, an artificial `use self::x as _;`
167
- // import is injected as a "canary", and an error is emitted if it
168
- // successfully resolves while an `x` external crate exists.
169
- //
170
- // For each block scope around the `use` item, one special canary
171
- // import of the form `use x as _;` is also injected, having its
172
- // parent set to that scope; `resolve_imports` will only resolve
173
- // it within its appropriate scope; if any of them successfully
174
- // resolve, an ambiguity error is emitted, since the original
175
- // import can't see the item in the block scope (`self::x` only
176
- // looks in the enclosing module), but a non-`use` path could.
177
- //
178
- // Additionally, the canary might be able to catch limitations of the
179
- // current implementation, where `::x` may be chosen due to `self::x`
180
- // not existing, but `self::x` could appear later, from macro expansion.
181
- //
182
- // NB. The canary currently only errors if the `x::...` path *could*
183
- // resolve as a relative path through the extern crate, i.e. `x` is
184
- // in `extern_prelude`, *even though* `::x` might still forcefully
185
- // load a non-`extern_prelude` crate.
186
- // While always producing an ambiguity errors if `self::x` exists and
187
- // a crate *could* be loaded, would be more conservative, imports for
188
- // local modules named `test` (or less commonly, `syntax` or `log`),
189
- // would need to be qualified (e.g. `self::test`), which is considered
190
- // ergonomically unacceptable.
191
- let emit_uniform_paths_canary =
192
- !uniform_paths_canary_emitted &&
193
- self . session . rust_2018 ( ) &&
194
- starts_with_non_keyword;
195
- if emit_uniform_paths_canary {
196
- let source = prefix_start. unwrap ( ) ;
197
-
198
- // Helper closure to emit a canary with the given base path.
199
- let emit = |this : & mut Self , base : Option < Segment > | {
200
- let subclass = SingleImport {
201
- target : Ident {
202
- name : keywords:: Underscore . name ( ) . gensymed ( ) ,
203
- span : source. ident . span ,
204
- } ,
205
- source : source. ident ,
206
- result : PerNS {
207
- type_ns : Cell :: new ( Err ( Undetermined ) ) ,
208
- value_ns : Cell :: new ( Err ( Undetermined ) ) ,
209
- macro_ns : Cell :: new ( Err ( Undetermined ) ) ,
210
- } ,
211
- type_ns_only : false ,
212
- } ;
213
- this. add_import_directive (
214
- base. into_iter ( ) . collect ( ) ,
215
- subclass,
216
- source. ident . span ,
217
- id,
218
- root_span,
219
- item. id ,
220
- ty:: Visibility :: Invisible ,
221
- parent_scope. clone ( ) ,
222
- true , // is_uniform_paths_canary
223
- ) ;
224
- } ;
225
-
226
- // A single simple `self::x` canary.
227
- emit ( self , Some ( Segment {
228
- ident : Ident {
229
- name : keywords:: SelfValue . name ( ) ,
230
- span : source. ident . span ,
231
- } ,
232
- id : source. id
233
- } ) ) ;
234
-
235
- // One special unprefixed canary per block scope around
236
- // the import, to detect items unreachable by `self::x`.
237
- let orig_current_module = self . current_module ;
238
- let mut span = source. ident . span . modern ( ) ;
239
- loop {
240
- match self . current_module . kind {
241
- ModuleKind :: Block ( ..) => emit ( self , None ) ,
242
- ModuleKind :: Def ( ..) => break ,
243
- }
244
- match self . hygienic_lexical_parent ( self . current_module , & mut span) {
245
- Some ( module) => {
246
- self . current_module = module;
247
- }
248
- None => break ,
249
- }
250
- }
251
- self . current_module = orig_current_module;
252
-
253
- uniform_paths_canary_emitted = true ;
254
- }
255
-
256
158
let empty_for_self = |prefix : & [ Segment ] | {
257
159
prefix. is_empty ( ) ||
258
160
prefix. len ( ) == 1 && prefix[ 0 ] . ident . name == keywords:: CrateRoot . name ( )
@@ -350,7 +252,6 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
350
252
item. id ,
351
253
vis,
352
254
parent_scope,
353
- false , // is_uniform_paths_canary
354
255
) ;
355
256
}
356
257
ast:: UseTreeKind :: Glob => {
@@ -367,7 +268,6 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
367
268
item. id ,
368
269
vis,
369
270
parent_scope,
370
- false , // is_uniform_paths_canary
371
271
) ;
372
272
}
373
273
ast:: UseTreeKind :: Nested ( ref items) => {
@@ -396,7 +296,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
396
296
for & ( ref tree, id) in items {
397
297
self . build_reduced_graph_for_use_tree (
398
298
// This particular use tree
399
- tree, id, & prefix, true , uniform_paths_canary_emitted ,
299
+ tree, id, & prefix, true ,
400
300
// The whole `use` item
401
301
parent_scope. clone ( ) , item, vis, root_span,
402
302
) ;
@@ -420,7 +320,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
420
320
} ;
421
321
self . build_reduced_graph_for_use_tree (
422
322
// This particular use tree
423
- & tree, id, & prefix, true , uniform_paths_canary_emitted ,
323
+ & tree, id, & prefix, true ,
424
324
// The whole `use` item
425
325
parent_scope. clone ( ) , item, ty:: Visibility :: Invisible , root_span,
426
326
) ;
@@ -441,7 +341,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
441
341
ItemKind :: Use ( ref use_tree) => {
442
342
self . build_reduced_graph_for_use_tree (
443
343
// This particular use tree
444
- use_tree, item. id , & [ ] , false , false ,
344
+ use_tree, item. id , & [ ] , false ,
445
345
// The whole `use` item
446
346
parent_scope, item, vis, use_tree. span ,
447
347
) ;
@@ -492,7 +392,6 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
492
392
module_path : Vec :: new ( ) ,
493
393
vis : Cell :: new ( vis) ,
494
394
used : Cell :: new ( used) ,
495
- is_uniform_paths_canary : false ,
496
395
} ) ;
497
396
self . potentially_unused_imports . push ( directive) ;
498
397
let imported_binding = self . import ( binding, directive) ;
@@ -905,7 +804,6 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
905
804
module_path : Vec :: new ( ) ,
906
805
vis : Cell :: new ( ty:: Visibility :: Restricted ( DefId :: local ( CRATE_DEF_INDEX ) ) ) ,
907
806
used : Cell :: new ( false ) ,
908
- is_uniform_paths_canary : false ,
909
807
} ) ;
910
808
911
809
let allow_shadowing = parent_scope. expansion == Mark :: root ( ) ;
0 commit comments