@@ -81,7 +81,8 @@ impl ImportDirective {
8181
8282 // Given the binding to which this directive resolves in a particular namespace,
8383 // this returns the binding for the name this directive defines in that namespace.
84- fn import < ' a > ( & self , mut binding : NameBinding < ' a > ) -> NameBinding < ' a > {
84+ fn import < ' a > ( & self , binding : & ' a NameBinding < ' a > ) -> NameBinding < ' a > {
85+ let mut binding = binding. clone ( ) ;
8586 if self . shadowable == Shadowable :: Always {
8687 binding. modifiers = binding. modifiers | DefModifiers :: PRELUDE ;
8788 }
@@ -107,7 +108,7 @@ pub struct ImportResolution<'a> {
107108 pub is_public : bool ,
108109
109110 /// Resolution of the name in the namespace
110- pub binding : Option < NameBinding < ' a > > ,
111+ pub binding : Option < & ' a NameBinding < ' a > > ,
111112
112113 /// The source node of the `use` directive
113114 pub id : NodeId ,
@@ -125,7 +126,7 @@ impl<'a> ImportResolution<'a> {
125126
126127 pub fn shadowable ( & self ) -> Shadowable {
127128 match self . binding {
128- Some ( ref binding) if binding. defined_with ( DefModifiers :: PRELUDE ) =>
129+ Some ( binding) if binding. defined_with ( DefModifiers :: PRELUDE ) =>
129130 Shadowable :: Always ,
130131 Some ( _) => Shadowable :: Never ,
131132 None => Shadowable :: Always ,
@@ -195,7 +196,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
195196
196197 /// Resolves an `ImportResolvingError` into the correct enum discriminant
197198 /// and passes that on to `resolve_error`.
198- fn import_resolving_error ( & self , e : ImportResolvingError ) {
199+ fn import_resolving_error ( & self , e : ImportResolvingError < ' b > ) {
199200 // If it's a single failed import then create a "fake" import
200201 // resolution for it so that later resolve stages won't complain.
201202 if let SingleImport ( target, _) = e. import_directive . subclass {
@@ -213,11 +214,11 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
213214 debug ! ( "(resolving import error) adding fake target to import resolution of `{}`" ,
214215 target) ;
215216
216- let dummy_binding = NameBinding {
217+ let dummy_binding = self . resolver . new_name_binding ( NameBinding {
217218 modifiers : DefModifiers :: IMPORTABLE ,
218219 def_or_module : DefOrModule :: Def ( Def :: Err ) ,
219220 span : None ,
220- } ;
221+ } ) ;
221222
222223 resolution. binding = Some ( dummy_binding) ;
223224 }
@@ -367,7 +368,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
367368 name : Name ,
368369 ns : Namespace ,
369370 importing_module : Module < ' b > ) // Module importing the name
370- -> ( ResolveResult < NameBinding < ' b > > , bool ) {
371+ -> ( ResolveResult < & ' b NameBinding < ' b > > , bool ) {
371372 build_reduced_graph:: populate_module_if_necessary ( self . resolver , module) ;
372373 if let Some ( name_binding) = module. get_child ( name, ns) {
373374 if name_binding. is_extern_crate ( ) {
@@ -397,7 +398,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
397398 return ( Failed ( None ) , false ) ;
398399 }
399400
400- if let Some ( binding) = resolution. binding . clone ( ) {
401+ if let Some ( binding) = resolution. binding {
401402 self . resolver . record_import_use ( name, ns, & resolution) ;
402403 ( Success ( binding) , true )
403404 } else {
@@ -455,9 +456,9 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
455456 self . resolve_name_in_module ( target_module, source, TypeNS , module_) ;
456457
457458 match ( & value_result, & type_result) {
458- ( & Success ( ref name_binding) , _) if !value_used_reexport &&
459- directive. is_public &&
460- !name_binding. is_public ( ) => {
459+ ( & Success ( name_binding) , _) if !value_used_reexport &&
460+ directive. is_public &&
461+ !name_binding. is_public ( ) => {
461462 let msg = format ! ( "`{}` is private, and cannot be reexported" , source) ;
462463 let note_msg = format ! ( "Consider marking `{}` as `pub` in the imported module" ,
463464 source) ;
@@ -466,8 +467,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
466467 . emit ( ) ;
467468 }
468469
469- ( _, & Success ( ref name_binding) ) if !type_used_reexport &&
470- directive. is_public => {
470+ ( _, & Success ( name_binding) ) if !type_used_reexport && directive. is_public => {
471471 if !name_binding. is_public ( ) {
472472 let msg = format ! ( "`{}` is private, and cannot be reexported" , source) ;
473473 let note_msg =
@@ -519,7 +519,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
519519
520520 {
521521 let mut check_and_write_import = |namespace, result, used_public : & mut bool | {
522- let result: & ResolveResult < NameBinding > = result;
522+ let result: & ResolveResult < & NameBinding > = result;
523523
524524 let import_resolution = import_resolutions. get_mut ( & ( target, namespace) ) . unwrap ( ) ;
525525 let namespace_name = match namespace {
@@ -528,7 +528,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
528528 } ;
529529
530530 match * result {
531- Success ( ref name_binding) => {
531+ Success ( name_binding) => {
532532 debug ! ( "(resolving single import) found {:?} target: {:?}" ,
533533 namespace_name,
534534 name_binding. def( ) ) ;
@@ -541,7 +541,8 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
541541 directive. span ,
542542 target) ;
543543
544- import_resolution. binding = Some ( directive. import ( name_binding. clone ( ) ) ) ;
544+ import_resolution. binding =
545+ Some ( self . resolver . new_name_binding ( directive. import ( name_binding) ) ) ;
545546 import_resolution. id = directive. id ;
546547 import_resolution. is_public = directive. is_public ;
547548
@@ -679,14 +680,15 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
679680 . or_insert_with ( || ImportResolution :: new ( id, is_public) ) ;
680681
681682 match target_import_resolution. binding {
682- Some ( ref binding) if target_import_resolution. is_public => {
683+ Some ( binding) if target_import_resolution. is_public => {
683684 self . check_for_conflicting_import ( & dest_import_resolution,
684685 import_directive. span ,
685686 name,
686687 ns) ;
687688 dest_import_resolution. id = id;
688689 dest_import_resolution. is_public = is_public;
689- dest_import_resolution. binding = Some ( import_directive. import ( binding. clone ( ) ) ) ;
690+ dest_import_resolution. binding =
691+ Some ( self . resolver . new_name_binding ( import_directive. import ( binding) ) ) ;
690692 self . add_export ( module_, name, & dest_import_resolution) ;
691693 }
692694 _ => { }
@@ -701,7 +703,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
701703 target_module,
702704 import_directive,
703705 ( name, ns) ,
704- name_binding. clone ( ) ) ;
706+ name_binding) ;
705707 } ) ;
706708
707709 // Record the destination of this import
@@ -723,7 +725,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
723725 containing_module : Module < ' b > ,
724726 import_directive : & ImportDirective ,
725727 ( name, ns) : ( Name , Namespace ) ,
726- name_binding : NameBinding < ' b > ) {
728+ name_binding : & ' b NameBinding < ' b > ) {
727729 let id = import_directive. id ;
728730 let is_public = import_directive. is_public ;
729731
@@ -761,7 +763,8 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
761763 name) ;
762764 span_err ! ( self . resolver. session, import_directive. span, E0251 , "{}" , msg) ;
763765 } else {
764- dest_import_resolution. binding = Some ( import_directive. import ( name_binding. clone ( ) ) ) ;
766+ dest_import_resolution. binding =
767+ Some ( self . resolver . new_name_binding ( import_directive. import ( name_binding) ) ) ;
765768 dest_import_resolution. id = id;
766769 dest_import_resolution. is_public = is_public;
767770 self . add_export ( module_, name, & dest_import_resolution) ;
@@ -799,7 +802,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
799802 binding. is_some( ) ) ;
800803
801804 match * binding {
802- Some ( ref binding) if !binding. defined_with ( DefModifiers :: PRELUDE ) => {
805+ Some ( binding) if !binding. defined_with ( DefModifiers :: PRELUDE ) => {
803806 let ns_word = match namespace {
804807 TypeNS => {
805808 match binding. module ( ) {
@@ -857,7 +860,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
857860
858861 if ns == ValueNS {
859862 match import. binding {
860- Some ( ref binding) if !binding. defined_with ( DefModifiers :: PRELUDE ) => {
863+ Some ( binding) if !binding. defined_with ( DefModifiers :: PRELUDE ) => {
861864 let mut err = struct_span_err ! ( self . resolver. session,
862865 import_span,
863866 E0255 ,
@@ -873,7 +876,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
873876 }
874877 } else {
875878 match import. binding {
876- Some ( ref binding) if !binding. defined_with ( DefModifiers :: PRELUDE ) => {
879+ Some ( binding) if !binding. defined_with ( DefModifiers :: PRELUDE ) => {
877880 if name_binding. is_extern_crate ( ) {
878881 let msg = format ! ( "import `{0}` conflicts with imported crate \
879882 in this module (maybe you meant `use {0}::*`?)",
0 commit comments