@@ -81,7 +81,8 @@ impl ImportDirective {
81
81
82
82
// Given the binding to which this directive resolves in a particular namespace,
83
83
// 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 ( ) ;
85
86
if self . shadowable == Shadowable :: Always {
86
87
binding. modifiers = binding. modifiers | DefModifiers :: PRELUDE ;
87
88
}
@@ -107,7 +108,7 @@ pub struct ImportResolution<'a> {
107
108
pub is_public : bool ,
108
109
109
110
/// Resolution of the name in the namespace
110
- pub binding : Option < NameBinding < ' a > > ,
111
+ pub binding : Option < & ' a NameBinding < ' a > > ,
111
112
112
113
/// The source node of the `use` directive
113
114
pub id : NodeId ,
@@ -125,7 +126,7 @@ impl<'a> ImportResolution<'a> {
125
126
126
127
pub fn shadowable ( & self ) -> Shadowable {
127
128
match self . binding {
128
- Some ( ref binding) if binding. defined_with ( DefModifiers :: PRELUDE ) =>
129
+ Some ( binding) if binding. defined_with ( DefModifiers :: PRELUDE ) =>
129
130
Shadowable :: Always ,
130
131
Some ( _) => Shadowable :: Never ,
131
132
None => Shadowable :: Always ,
@@ -195,7 +196,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
195
196
196
197
/// Resolves an `ImportResolvingError` into the correct enum discriminant
197
198
/// and passes that on to `resolve_error`.
198
- fn import_resolving_error ( & self , e : ImportResolvingError ) {
199
+ fn import_resolving_error ( & self , e : ImportResolvingError < ' b > ) {
199
200
// If it's a single failed import then create a "fake" import
200
201
// resolution for it so that later resolve stages won't complain.
201
202
if let SingleImport ( target, _) = e. import_directive . subclass {
@@ -213,11 +214,11 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
213
214
debug ! ( "(resolving import error) adding fake target to import resolution of `{}`" ,
214
215
target) ;
215
216
216
- let dummy_binding = NameBinding {
217
+ let dummy_binding = self . resolver . new_name_binding ( NameBinding {
217
218
modifiers : DefModifiers :: IMPORTABLE ,
218
219
def_or_module : DefOrModule :: Def ( Def :: Err ) ,
219
220
span : None ,
220
- } ;
221
+ } ) ;
221
222
222
223
resolution. binding = Some ( dummy_binding) ;
223
224
}
@@ -367,7 +368,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
367
368
name : Name ,
368
369
ns : Namespace ,
369
370
importing_module : Module < ' b > ) // Module importing the name
370
- -> ( ResolveResult < NameBinding < ' b > > , bool ) {
371
+ -> ( ResolveResult < & ' b NameBinding < ' b > > , bool ) {
371
372
build_reduced_graph:: populate_module_if_necessary ( self . resolver , module) ;
372
373
if let Some ( name_binding) = module. get_child ( name, ns) {
373
374
if name_binding. is_extern_crate ( ) {
@@ -397,7 +398,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
397
398
return ( Failed ( None ) , false ) ;
398
399
}
399
400
400
- if let Some ( binding) = resolution. binding . clone ( ) {
401
+ if let Some ( binding) = resolution. binding {
401
402
self . resolver . record_import_use ( name, ns, & resolution) ;
402
403
( Success ( binding) , true )
403
404
} else {
@@ -455,9 +456,9 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
455
456
self . resolve_name_in_module ( target_module, source, TypeNS , module_) ;
456
457
457
458
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 ( ) => {
461
462
let msg = format ! ( "`{}` is private, and cannot be reexported" , source) ;
462
463
let note_msg = format ! ( "Consider marking `{}` as `pub` in the imported module" ,
463
464
source) ;
@@ -466,8 +467,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
466
467
. emit ( ) ;
467
468
}
468
469
469
- ( _, & Success ( ref name_binding) ) if !type_used_reexport &&
470
- directive. is_public => {
470
+ ( _, & Success ( name_binding) ) if !type_used_reexport && directive. is_public => {
471
471
if !name_binding. is_public ( ) {
472
472
let msg = format ! ( "`{}` is private, and cannot be reexported" , source) ;
473
473
let note_msg =
@@ -519,7 +519,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
519
519
520
520
{
521
521
let mut check_and_write_import = |namespace, result, used_public : & mut bool | {
522
- let result: & ResolveResult < NameBinding > = result;
522
+ let result: & ResolveResult < & NameBinding > = result;
523
523
524
524
let import_resolution = import_resolutions. get_mut ( & ( target, namespace) ) . unwrap ( ) ;
525
525
let namespace_name = match namespace {
@@ -528,7 +528,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
528
528
} ;
529
529
530
530
match * result {
531
- Success ( ref name_binding) => {
531
+ Success ( name_binding) => {
532
532
debug ! ( "(resolving single import) found {:?} target: {:?}" ,
533
533
namespace_name,
534
534
name_binding. def( ) ) ;
@@ -541,7 +541,8 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
541
541
directive. span ,
542
542
target) ;
543
543
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) ) ) ;
545
546
import_resolution. id = directive. id ;
546
547
import_resolution. is_public = directive. is_public ;
547
548
@@ -679,14 +680,15 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
679
680
. or_insert_with ( || ImportResolution :: new ( id, is_public) ) ;
680
681
681
682
match target_import_resolution. binding {
682
- Some ( ref binding) if target_import_resolution. is_public => {
683
+ Some ( binding) if target_import_resolution. is_public => {
683
684
self . check_for_conflicting_import ( & dest_import_resolution,
684
685
import_directive. span ,
685
686
name,
686
687
ns) ;
687
688
dest_import_resolution. id = id;
688
689
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) ) ) ;
690
692
self . add_export ( module_, name, & dest_import_resolution) ;
691
693
}
692
694
_ => { }
@@ -701,7 +703,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
701
703
target_module,
702
704
import_directive,
703
705
( name, ns) ,
704
- name_binding. clone ( ) ) ;
706
+ name_binding) ;
705
707
} ) ;
706
708
707
709
// Record the destination of this import
@@ -723,7 +725,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
723
725
containing_module : Module < ' b > ,
724
726
import_directive : & ImportDirective ,
725
727
( name, ns) : ( Name , Namespace ) ,
726
- name_binding : NameBinding < ' b > ) {
728
+ name_binding : & ' b NameBinding < ' b > ) {
727
729
let id = import_directive. id ;
728
730
let is_public = import_directive. is_public ;
729
731
@@ -761,7 +763,8 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
761
763
name) ;
762
764
span_err ! ( self . resolver. session, import_directive. span, E0251 , "{}" , msg) ;
763
765
} 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) ) ) ;
765
768
dest_import_resolution. id = id;
766
769
dest_import_resolution. is_public = is_public;
767
770
self . add_export ( module_, name, & dest_import_resolution) ;
@@ -799,7 +802,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
799
802
binding. is_some( ) ) ;
800
803
801
804
match * binding {
802
- Some ( ref binding) if !binding. defined_with ( DefModifiers :: PRELUDE ) => {
805
+ Some ( binding) if !binding. defined_with ( DefModifiers :: PRELUDE ) => {
803
806
let ns_word = match namespace {
804
807
TypeNS => {
805
808
match binding. module ( ) {
@@ -857,7 +860,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
857
860
858
861
if ns == ValueNS {
859
862
match import. binding {
860
- Some ( ref binding) if !binding. defined_with ( DefModifiers :: PRELUDE ) => {
863
+ Some ( binding) if !binding. defined_with ( DefModifiers :: PRELUDE ) => {
861
864
let mut err = struct_span_err ! ( self . resolver. session,
862
865
import_span,
863
866
E0255 ,
@@ -873,7 +876,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
873
876
}
874
877
} else {
875
878
match import. binding {
876
- Some ( ref binding) if !binding. defined_with ( DefModifiers :: PRELUDE ) => {
879
+ Some ( binding) if !binding. defined_with ( DefModifiers :: PRELUDE ) => {
877
880
if name_binding. is_extern_crate ( ) {
878
881
let msg = format ! ( "import `{0}` conflicts with imported crate \
879
882
in this module (maybe you meant `use {0}::*`?)",
0 commit comments