@@ -12,7 +12,7 @@ use self::ImportDirectiveSubclass::*;
12
12
13
13
use { AmbiguityError , Module , PerNS } ;
14
14
use Namespace :: { self , TypeNS , MacroNS } ;
15
- use { NameBinding , NameBindingKind , PathResult , PathScope , PrivacyError , ToNameBinding } ;
15
+ use { NameBinding , NameBindingKind , PathResult , PathScope , PrivacyError } ;
16
16
use Resolver ;
17
17
use { names_to_string, module_to_string} ;
18
18
use { resolve_error, ResolutionError } ;
@@ -273,7 +273,7 @@ impl<'a> Resolver<'a> {
273
273
// Given a binding and an import directive that resolves to it,
274
274
// return the corresponding binding defined by the import directive.
275
275
pub fn import ( & mut self , binding : & ' a NameBinding < ' a > , directive : & ' a ImportDirective < ' a > )
276
- -> NameBinding < ' a > {
276
+ -> & ' a NameBinding < ' a > {
277
277
let vis = if binding. pseudo_vis ( ) . is_at_least ( directive. vis . get ( ) , self ) ||
278
278
!directive. is_glob ( ) && binding. is_extern_crate ( ) { // c.f. `PRIVATE_IN_PUBLIC`
279
279
directive. vis . get ( )
@@ -287,7 +287,7 @@ impl<'a> Resolver<'a> {
287
287
}
288
288
}
289
289
290
- NameBinding {
290
+ self . arenas . alloc_name_binding ( NameBinding {
291
291
kind : NameBindingKind :: Import {
292
292
binding : binding,
293
293
directive : directive,
@@ -296,16 +296,17 @@ impl<'a> Resolver<'a> {
296
296
span : directive. span ,
297
297
vis : vis,
298
298
expansion : directive. expansion ,
299
- }
299
+ } )
300
300
}
301
301
302
302
// Define the name or return the existing binding if there is a collision.
303
- pub fn try_define < T > ( & mut self , module : Module < ' a > , ident : Ident , ns : Namespace , binding : T )
304
- -> Result < ( ) , & ' a NameBinding < ' a > >
305
- where T : ToNameBinding < ' a >
306
- {
303
+ pub fn try_define ( & mut self ,
304
+ module : Module < ' a > ,
305
+ ident : Ident ,
306
+ ns : Namespace ,
307
+ binding : & ' a NameBinding < ' a > )
308
+ -> Result < ( ) , & ' a NameBinding < ' a > > {
307
309
let ident = ident. unhygienize ( ) ;
308
- let binding = self . arenas . alloc_name_binding ( binding. to_name_binding ( ) ) ;
309
310
self . update_resolution ( module, ident, ns, |this, resolution| {
310
311
if let Some ( old_binding) = resolution. binding {
311
312
if binding. is_glob_import ( ) {
@@ -389,7 +390,7 @@ impl<'a> Resolver<'a> {
389
390
let dummy_binding = self . dummy_binding ;
390
391
let dummy_binding = self . import ( dummy_binding, directive) ;
391
392
self . per_ns ( |this, ns| {
392
- let _ = this. try_define ( directive. parent , target, ns, dummy_binding. clone ( ) ) ;
393
+ let _ = this. try_define ( directive. parent , target, ns, dummy_binding) ;
393
394
} ) ;
394
395
}
395
396
}
@@ -516,10 +517,11 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
516
517
return
517
518
} ;
518
519
520
+ let parent = directive. parent ;
519
521
match result[ ns] . get ( ) {
520
522
Err ( Undetermined ) => indeterminate = true ,
521
523
Err ( Determined ) => {
522
- this. update_resolution ( directive . parent , target, ns, |_, resolution| {
524
+ this. update_resolution ( parent, target, ns, |_, resolution| {
523
525
resolution. single_imports . directive_failed ( )
524
526
} ) ;
525
527
}
@@ -534,10 +536,9 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
534
536
}
535
537
Ok ( binding) => {
536
538
let imported_binding = this. import ( binding, directive) ;
537
- let conflict = this. try_define ( directive . parent , target, ns, imported_binding) ;
539
+ let conflict = this. try_define ( parent, target, ns, imported_binding) ;
538
540
if let Err ( old_binding) = conflict {
539
- let binding = & this. import ( binding, directive) ;
540
- this. report_conflict ( directive. parent , target, ns, binding, old_binding) ;
541
+ this. report_conflict ( parent, target, ns, imported_binding, old_binding) ;
541
542
}
542
543
}
543
544
}
0 commit comments