@@ -459,7 +459,7 @@ struct EmbargoVisitor<'tcx> {
459
459
}
460
460
461
461
struct ReachEverythingInTheInterfaceVisitor < ' a , ' tcx > {
462
- effective_vis : Option < EffectiveVisibility > ,
462
+ effective_vis : EffectiveVisibility ,
463
463
item_def_id : LocalDefId ,
464
464
ev : & ' a mut EmbargoVisitor < ' tcx > ,
465
465
level : Level ,
@@ -507,7 +507,7 @@ impl<'tcx> EmbargoVisitor<'tcx> {
507
507
fn reach (
508
508
& mut self ,
509
509
def_id : LocalDefId ,
510
- effective_vis : Option < EffectiveVisibility > ,
510
+ effective_vis : EffectiveVisibility ,
511
511
) -> ReachEverythingInTheInterfaceVisitor < ' _ , ' tcx > {
512
512
ReachEverythingInTheInterfaceVisitor {
513
513
effective_vis,
@@ -520,7 +520,7 @@ impl<'tcx> EmbargoVisitor<'tcx> {
520
520
fn reach_through_impl_trait (
521
521
& mut self ,
522
522
def_id : LocalDefId ,
523
- effective_vis : Option < EffectiveVisibility > ,
523
+ effective_vis : EffectiveVisibility ,
524
524
) -> ReachEverythingInTheInterfaceVisitor < ' _ , ' tcx > {
525
525
ReachEverythingInTheInterfaceVisitor {
526
526
effective_vis,
@@ -554,8 +554,8 @@ impl<'tcx> EmbargoVisitor<'tcx> {
554
554
// Since we are starting from an externally visible module,
555
555
// all the parents in the loop below are also guaranteed to be modules.
556
556
let mut module_def_id = macro_module_def_id;
557
- let macro_ev = self . get ( local_def_id ) ;
558
- assert ! ( macro_ev. is_some ( ) ) ;
557
+ // If the macro eff vis is not in the table the condition above will return.
558
+ let macro_ev = self . get ( local_def_id ) . unwrap ( ) ;
559
559
loop {
560
560
let changed_reachability =
561
561
self . update_macro_reachable ( module_def_id, macro_module_def_id, macro_ev) ;
@@ -572,7 +572,7 @@ impl<'tcx> EmbargoVisitor<'tcx> {
572
572
& mut self ,
573
573
module_def_id : LocalDefId ,
574
574
defining_mod : LocalDefId ,
575
- macro_ev : Option < EffectiveVisibility > ,
575
+ macro_ev : EffectiveVisibility ,
576
576
) -> bool {
577
577
if self . macro_reachable . insert ( ( module_def_id, defining_mod) ) {
578
578
self . update_macro_reachable_mod ( module_def_id, defining_mod, macro_ev) ;
@@ -586,7 +586,7 @@ impl<'tcx> EmbargoVisitor<'tcx> {
586
586
& mut self ,
587
587
module_def_id : LocalDefId ,
588
588
defining_mod : LocalDefId ,
589
- macro_ev : Option < EffectiveVisibility > ,
589
+ macro_ev : EffectiveVisibility ,
590
590
) {
591
591
let module = self . tcx . hir ( ) . get_module ( module_def_id) . 0 ;
592
592
for item_id in module. item_ids {
@@ -618,14 +618,14 @@ impl<'tcx> EmbargoVisitor<'tcx> {
618
618
def_kind : DefKind ,
619
619
vis : ty:: Visibility ,
620
620
module : LocalDefId ,
621
- macro_ev : Option < EffectiveVisibility > ,
621
+ macro_ev : EffectiveVisibility ,
622
622
) {
623
- self . update ( def_id, macro_ev, Level :: Reachable ) ;
623
+ self . update ( def_id, Some ( macro_ev) , Level :: Reachable ) ;
624
624
match def_kind {
625
625
// No type privacy, so can be directly marked as reachable.
626
626
DefKind :: Const | DefKind :: Static ( _) | DefKind :: TraitAlias | DefKind :: TyAlias => {
627
627
if vis. is_accessible_from ( module, self . tcx ) {
628
- self . update ( def_id, macro_ev, Level :: Reachable ) ;
628
+ self . update ( def_id, Some ( macro_ev) , Level :: Reachable ) ;
629
629
}
630
630
}
631
631
@@ -637,7 +637,7 @@ impl<'tcx> EmbargoVisitor<'tcx> {
637
637
let item = self . tcx . hir ( ) . expect_item ( def_id) ;
638
638
if let hir:: ItemKind :: Macro ( MacroDef { macro_rules : false , .. } , _) = item. kind {
639
639
if vis. is_accessible_from ( module, self . tcx ) {
640
- self . update ( def_id, macro_ev, Level :: Reachable ) ;
640
+ self . update ( def_id, Some ( macro_ev) , Level :: Reachable ) ;
641
641
}
642
642
}
643
643
}
@@ -790,7 +790,7 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
790
790
// FIXME: This is some serious pessimization intended to workaround deficiencies
791
791
// in the reachability pass (`middle/reachable.rs`). Types are marked as link-time
792
792
// reachable if they are returned via `impl Trait`, even from private functions.
793
- let exist_ev = Some ( EffectiveVisibility :: from_vis ( ty:: Visibility :: Public ) ) ;
793
+ let exist_ev = EffectiveVisibility :: from_vis ( ty:: Visibility :: Public ) ;
794
794
self . reach_through_impl_trait ( item. owner_id . def_id , exist_ev)
795
795
. generics ( )
796
796
. predicates ( )
@@ -802,12 +802,12 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
802
802
| hir:: ItemKind :: Static ( ..)
803
803
| hir:: ItemKind :: Fn ( ..)
804
804
| hir:: ItemKind :: TyAlias ( ..) => {
805
- if item_ev . is_some ( ) {
805
+ if let Some ( item_ev ) = item_ev {
806
806
self . reach ( item. owner_id . def_id , item_ev) . generics ( ) . predicates ( ) . ty ( ) ;
807
807
}
808
808
}
809
809
hir:: ItemKind :: Trait ( .., trait_item_refs) => {
810
- if item_ev . is_some ( ) {
810
+ if let Some ( item_ev ) = item_ev {
811
811
self . reach ( item. owner_id . def_id , item_ev) . generics ( ) . predicates ( ) ;
812
812
813
813
for trait_item_ref in trait_item_refs {
@@ -827,23 +827,21 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
827
827
}
828
828
}
829
829
hir:: ItemKind :: TraitAlias ( ..) => {
830
- if item_ev . is_some ( ) {
830
+ if let Some ( item_ev ) = item_ev {
831
831
self . reach ( item. owner_id . def_id , item_ev) . generics ( ) . predicates ( ) ;
832
832
}
833
833
}
834
834
// Visit everything except for private impl items.
835
835
hir:: ItemKind :: Impl ( ref impl_) => {
836
- if item_ev . is_some ( ) {
836
+ if let Some ( item_ev ) = item_ev {
837
837
self . reach ( item. owner_id . def_id , item_ev)
838
838
. generics ( )
839
839
. predicates ( )
840
840
. ty ( )
841
841
. trait_ref ( ) ;
842
842
843
843
for impl_item_ref in impl_. items {
844
- let impl_item_ev = self . get ( impl_item_ref. id . owner_id . def_id ) ;
845
-
846
- if impl_item_ev. is_some ( ) {
844
+ if let Some ( impl_item_ev) = self . get ( impl_item_ref. id . owner_id . def_id ) {
847
845
self . reach ( impl_item_ref. id . owner_id . def_id , impl_item_ev)
848
846
. generics ( )
849
847
. predicates ( )
@@ -855,12 +853,11 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
855
853
856
854
// Visit everything, but enum variants have their own levels.
857
855
hir:: ItemKind :: Enum ( ref def, _) => {
858
- if item_ev . is_some ( ) {
856
+ if let Some ( item_ev ) = item_ev {
859
857
self . reach ( item. owner_id . def_id , item_ev) . generics ( ) . predicates ( ) ;
860
858
}
861
859
for variant in def. variants {
862
- let variant_ev = self . get ( variant. def_id ) ;
863
- if variant_ev. is_some ( ) {
860
+ if let Some ( variant_ev) = self . get ( variant. def_id ) {
864
861
for field in variant. data . fields ( ) {
865
862
self . reach ( field. def_id , variant_ev) . ty ( ) ;
866
863
}
@@ -869,8 +866,7 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
869
866
self . reach ( item. owner_id . def_id , variant_ev) . ty ( ) ;
870
867
}
871
868
if let Some ( ctor_def_id) = variant. data . ctor_def_id ( ) {
872
- let ctor_ev = self . get ( ctor_def_id) ;
873
- if ctor_ev. is_some ( ) {
869
+ if let Some ( ctor_ev) = self . get ( ctor_def_id) {
874
870
self . reach ( item. owner_id . def_id , ctor_ev) . ty ( ) ;
875
871
}
876
872
}
@@ -879,8 +875,7 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
879
875
// Visit everything, but foreign items have their own levels.
880
876
hir:: ItemKind :: ForeignMod { items, .. } => {
881
877
for foreign_item in items {
882
- let foreign_item_ev = self . get ( foreign_item. id . owner_id . def_id ) ;
883
- if foreign_item_ev. is_some ( ) {
878
+ if let Some ( foreign_item_ev) = self . get ( foreign_item. id . owner_id . def_id ) {
884
879
self . reach ( foreign_item. id . owner_id . def_id , foreign_item_ev)
885
880
. generics ( )
886
881
. predicates ( )
@@ -890,18 +885,16 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
890
885
}
891
886
// Visit everything except for private fields.
892
887
hir:: ItemKind :: Struct ( ref struct_def, _) | hir:: ItemKind :: Union ( ref struct_def, _) => {
893
- if item_ev . is_some ( ) {
888
+ if let Some ( item_ev ) = item_ev {
894
889
self . reach ( item. owner_id . def_id , item_ev) . generics ( ) . predicates ( ) ;
895
890
for field in struct_def. fields ( ) {
896
- let field_ev = self . get ( field. def_id ) ;
897
- if field_ev. is_some ( ) {
891
+ if let Some ( field_ev) = self . get ( field. def_id ) {
898
892
self . reach ( field. def_id , field_ev) . ty ( ) ;
899
893
}
900
894
}
901
895
}
902
896
if let Some ( ctor_def_id) = struct_def. ctor_def_id ( ) {
903
- let ctor_ev = self . get ( ctor_def_id) ;
904
- if ctor_ev. is_some ( ) {
897
+ if let Some ( ctor_ev) = self . get ( ctor_def_id) {
905
898
self . reach ( item. owner_id . def_id , ctor_ev) . ty ( ) ;
906
899
}
907
900
}
@@ -960,7 +953,7 @@ impl<'tcx> DefIdVisitor<'tcx> for ReachEverythingInTheInterfaceVisitor<'_, 'tcx>
960
953
_descr : & dyn fmt:: Display ,
961
954
) -> ControlFlow < Self :: BreakTy > {
962
955
if let Some ( def_id) = def_id. as_local ( ) {
963
- self . ev . update_eff_vis ( def_id, self . effective_vis , None , self . level ) ;
956
+ self . ev . update_eff_vis ( def_id, Some ( self . effective_vis ) , None , self . level ) ;
964
957
}
965
958
ControlFlow :: Continue ( ( ) )
966
959
}
0 commit comments