@@ -116,17 +116,14 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
116
116
id : NodeId ,
117
117
parent_prefix : & [ Ident ] ,
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,98 +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 < Ident > | {
200
- let subclass = SingleImport {
201
- target : Ident {
202
- name : keywords:: Underscore . name ( ) . gensymed ( ) ,
203
- span : source. span ,
204
- } ,
205
- source,
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. 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 ( Ident {
228
- name : keywords:: SelfValue . name ( ) ,
229
- span : source. span ,
230
- } ) ) ;
231
-
232
- // One special unprefixed canary per block scope around
233
- // the import, to detect items unreachable by `self::x`.
234
- let orig_current_module = self . current_module ;
235
- let mut span = source. span . modern ( ) ;
236
- loop {
237
- match self . current_module . kind {
238
- ModuleKind :: Block ( ..) => emit ( self , None ) ,
239
- ModuleKind :: Def ( ..) => break ,
240
- }
241
- match self . hygienic_lexical_parent ( self . current_module , & mut span) {
242
- Some ( module) => {
243
- self . current_module = module;
244
- }
245
- None => break ,
246
- }
247
- }
248
- self . current_module = orig_current_module;
249
-
250
- uniform_paths_canary_emitted = true ;
251
- }
252
-
253
158
let empty_for_self = |prefix : & [ Ident ] | {
254
159
prefix. is_empty ( ) ||
255
160
prefix. len ( ) == 1 && prefix[ 0 ] . name == keywords:: CrateRoot . name ( )
@@ -344,7 +249,6 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
344
249
item. id ,
345
250
vis,
346
251
parent_scope,
347
- false , // is_uniform_paths_canary
348
252
) ;
349
253
}
350
254
ast:: UseTreeKind :: Glob => {
@@ -361,7 +265,6 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
361
265
item. id ,
362
266
vis,
363
267
parent_scope,
364
- false , // is_uniform_paths_canary
365
268
) ;
366
269
}
367
270
ast:: UseTreeKind :: Nested ( ref items) => {
@@ -390,7 +293,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
390
293
for & ( ref tree, id) in items {
391
294
self . build_reduced_graph_for_use_tree (
392
295
// This particular use tree
393
- tree, id, & prefix, true , uniform_paths_canary_emitted ,
296
+ tree, id, & prefix, true ,
394
297
// The whole `use` item
395
298
parent_scope. clone ( ) , item, vis, root_span,
396
299
) ;
@@ -414,7 +317,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
414
317
} ;
415
318
self . build_reduced_graph_for_use_tree (
416
319
// This particular use tree
417
- & tree, id, & prefix, true , uniform_paths_canary_emitted ,
320
+ & tree, id, & prefix, true ,
418
321
// The whole `use` item
419
322
parent_scope. clone ( ) , item, ty:: Visibility :: Invisible , root_span,
420
323
) ;
@@ -435,7 +338,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
435
338
ItemKind :: Use ( ref use_tree) => {
436
339
self . build_reduced_graph_for_use_tree (
437
340
// This particular use tree
438
- use_tree, item. id , & [ ] , false , false ,
341
+ use_tree, item. id , & [ ] , false ,
439
342
// The whole `use` item
440
343
parent_scope, item, vis, use_tree. span ,
441
344
) ;
@@ -486,7 +389,6 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
486
389
module_path : Vec :: new ( ) ,
487
390
vis : Cell :: new ( vis) ,
488
391
used : Cell :: new ( used) ,
489
- is_uniform_paths_canary : false ,
490
392
} ) ;
491
393
self . potentially_unused_imports . push ( directive) ;
492
394
let imported_binding = self . import ( binding, directive) ;
@@ -899,7 +801,6 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
899
801
module_path : Vec :: new ( ) ,
900
802
vis : Cell :: new ( ty:: Visibility :: Restricted ( DefId :: local ( CRATE_DEF_INDEX ) ) ) ,
901
803
used : Cell :: new ( false ) ,
902
- is_uniform_paths_canary : false ,
903
804
} ) ;
904
805
905
806
let allow_shadowing = parent_scope. expansion == Mark :: root ( ) ;
0 commit comments