@@ -371,14 +371,13 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
371
371
}
372
372
373
373
/// Resolves the name in the namespace of the module because it is being imported by
374
- /// importing_module. Returns the name bindings defining the name
375
- /// and whether or not the name was imported.
374
+ /// importing_module. Returns the name bindings defining the name.
376
375
fn resolve_name_in_module ( & mut self ,
377
376
module : Module < ' b > , // Module containing the name
378
377
name : Name ,
379
378
ns : Namespace ,
380
379
importing_module : Module < ' b > ) // Module importing the name
381
- -> ( ResolveResult < & ' b NameBinding < ' b > > , bool ) {
380
+ -> ResolveResult < & ' b NameBinding < ' b > > {
382
381
build_reduced_graph:: populate_module_if_necessary ( self . resolver , module) ;
383
382
if let Some ( name_binding) = module. get_child ( name, ns) {
384
383
if name_binding. is_extern_crate ( ) {
@@ -387,32 +386,32 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
387
386
self . resolver . used_crates . insert ( krate) ;
388
387
}
389
388
}
390
- return ( Success ( name_binding) , false )
389
+ return Success ( name_binding) ;
391
390
}
392
391
393
392
// If there is an unresolved glob at this point in the containing module, bail out.
394
393
// We don't know enough to be able to resolve the name.
395
394
if module. pub_glob_count . get ( ) > 0 {
396
- return ( Indeterminate , false ) ;
395
+ return Indeterminate ;
397
396
}
398
397
399
398
match module. import_resolutions . borrow ( ) . get ( & ( name, ns) ) {
400
399
// The containing module definitely doesn't have an exported import with the
401
400
// name in question. We can therefore accurately report that names are unbound.
402
- None => ( Failed ( None ) , false ) ,
401
+ None => Failed ( None ) ,
403
402
404
403
// The name is an import which has been fully resolved, so we just follow it.
405
404
Some ( resolution) if resolution. outstanding_references == 0 => {
406
405
// Import resolutions must be declared with "pub" in order to be exported.
407
406
if !resolution. is_public {
408
- return ( Failed ( None ) , false ) ;
407
+ return Failed ( None ) ;
409
408
}
410
409
411
410
if let Some ( binding) = resolution. binding {
412
411
self . resolver . record_import_use ( name, ns, & resolution) ;
413
- ( Success ( binding) , true )
412
+ Success ( binding)
414
413
} else {
415
- ( Failed ( None ) , false )
414
+ Failed ( None )
416
415
}
417
416
}
418
417
@@ -427,8 +426,8 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
427
426
// In this case we continue as if we resolved the import and let
428
427
// check_for_conflicts_between_imports_and_items handle the conflict
429
428
Some ( _) => match ( importing_module. def_id ( ) , module. def_id ( ) ) {
430
- ( Some ( id1) , Some ( id2) ) if id1 == id2 => ( Failed ( None ) , false ) ,
431
- _ => ( Indeterminate , false )
429
+ ( Some ( id1) , Some ( id2) ) if id1 == id2 => Failed ( None ) ,
430
+ _ => Indeterminate
432
431
} ,
433
432
}
434
433
}
@@ -460,13 +459,13 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
460
459
} ;
461
460
462
461
// We need to resolve both namespaces for this to succeed.
463
- let ( value_result, value_used_reexport ) =
462
+ let value_result =
464
463
self . resolve_name_in_module ( target_module, source, ValueNS , module_) ;
465
- let ( type_result, type_used_reexport ) =
464
+ let type_result =
466
465
self . resolve_name_in_module ( target_module, source, TypeNS , module_) ;
467
466
468
467
match ( & value_result, & type_result) {
469
- ( & Success ( name_binding) , _) if !value_used_reexport &&
468
+ ( & Success ( name_binding) , _) if !name_binding . is_import ( ) &&
470
469
directive. is_public &&
471
470
!name_binding. is_public ( ) => {
472
471
let msg = format ! ( "`{}` is private, and cannot be reexported" , source) ;
@@ -477,7 +476,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
477
476
. emit ( ) ;
478
477
}
479
478
480
- ( _, & Success ( name_binding) ) if !type_used_reexport && directive. is_public => {
479
+ ( _, & Success ( name_binding) ) if !name_binding . is_import ( ) && directive. is_public => {
481
480
if !name_binding. is_public ( ) {
482
481
let msg = format ! ( "`{}` is private, and cannot be reexported" , source) ;
483
482
let note_msg =
@@ -521,14 +520,11 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
521
520
_ => ( ) ,
522
521
}
523
522
524
- let mut value_used_public = false ;
525
- let mut type_used_public = false ;
526
-
527
523
// We've successfully resolved the import. Write the results in.
528
524
let mut import_resolutions = module_. import_resolutions . borrow_mut ( ) ;
529
525
530
526
{
531
- let mut check_and_write_import = |namespace, result, used_public : & mut bool | {
527
+ let mut check_and_write_import = |namespace, result| {
532
528
let result: & ResolveResult < & NameBinding > = result;
533
529
534
530
let import_resolution = import_resolutions. get_mut ( & ( target, namespace) ) . unwrap ( ) ;
@@ -557,7 +553,6 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
557
553
import_resolution. is_public = directive. is_public ;
558
554
559
555
self . add_export ( module_, target, & import_resolution) ;
560
- * used_public = name_binding. is_public ( ) ;
561
556
}
562
557
Failed ( _) => {
563
558
// Continue.
@@ -572,8 +567,8 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
572
567
directive. span ,
573
568
( target, namespace) ) ;
574
569
} ;
575
- check_and_write_import ( ValueNS , & value_result, & mut value_used_public ) ;
576
- check_and_write_import ( TypeNS , & type_result, & mut type_used_public ) ;
570
+ check_and_write_import ( ValueNS , & value_result) ;
571
+ check_and_write_import ( TypeNS , & type_result) ;
577
572
}
578
573
579
574
if let ( & Failed ( _) , & Failed ( _) ) = ( & value_result, & type_result) {
@@ -583,9 +578,6 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
583
578
return Failed ( Some ( ( directive. span , msg) ) ) ;
584
579
}
585
580
586
- let value_used_public = value_used_reexport || value_used_public;
587
- let type_used_public = type_used_reexport || type_used_public;
588
-
589
581
let value_def_and_priv = {
590
582
let import_resolution_value = import_resolutions. get_mut ( & ( target, ValueNS ) ) . unwrap ( ) ;
591
583
assert ! ( import_resolution_value. outstanding_references >= 1 ) ;
@@ -596,7 +588,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
596
588
// purposes it's good enough to just favor one over the other.
597
589
import_resolution_value. binding . as_ref ( ) . map ( |binding| {
598
590
let def = binding. def ( ) . unwrap ( ) ;
599
- let last_private = if value_used_public { lp } else { DependsOn ( def. def_id ( ) ) } ;
591
+ let last_private = if binding . is_public ( ) { lp } else { DependsOn ( def. def_id ( ) ) } ;
600
592
( def, last_private)
601
593
} )
602
594
} ;
@@ -608,7 +600,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
608
600
609
601
import_resolution_type. binding . as_ref ( ) . map ( |binding| {
610
602
let def = binding. def ( ) . unwrap ( ) ;
611
- let last_private = if type_used_public { lp } else { DependsOn ( def. def_id ( ) ) } ;
603
+ let last_private = if binding . is_public ( ) { lp } else { DependsOn ( def. def_id ( ) ) } ;
612
604
( def, last_private)
613
605
} )
614
606
} ;
0 commit comments