@@ -459,7 +459,7 @@ struct EmbargoVisitor<'tcx> {
459459}
460460
461461struct ReachEverythingInTheInterfaceVisitor < ' a , ' tcx > {
462- effective_vis : Option < EffectiveVisibility > ,
462+ effective_vis : EffectiveVisibility ,
463463 item_def_id : LocalDefId ,
464464 ev : & ' a mut EmbargoVisitor < ' tcx > ,
465465 level : Level ,
@@ -507,7 +507,7 @@ impl<'tcx> EmbargoVisitor<'tcx> {
507507 fn reach (
508508 & mut self ,
509509 def_id : LocalDefId ,
510- effective_vis : Option < EffectiveVisibility > ,
510+ effective_vis : EffectiveVisibility ,
511511 ) -> ReachEverythingInTheInterfaceVisitor < ' _ , ' tcx > {
512512 ReachEverythingInTheInterfaceVisitor {
513513 effective_vis,
@@ -520,7 +520,7 @@ impl<'tcx> EmbargoVisitor<'tcx> {
520520 fn reach_through_impl_trait (
521521 & mut self ,
522522 def_id : LocalDefId ,
523- effective_vis : Option < EffectiveVisibility > ,
523+ effective_vis : EffectiveVisibility ,
524524 ) -> ReachEverythingInTheInterfaceVisitor < ' _ , ' tcx > {
525525 ReachEverythingInTheInterfaceVisitor {
526526 effective_vis,
@@ -554,8 +554,8 @@ impl<'tcx> EmbargoVisitor<'tcx> {
554554 // Since we are starting from an externally visible module,
555555 // all the parents in the loop below are also guaranteed to be modules.
556556 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 ( ) ;
559559 loop {
560560 let changed_reachability =
561561 self . update_macro_reachable ( module_def_id, macro_module_def_id, macro_ev) ;
@@ -572,7 +572,7 @@ impl<'tcx> EmbargoVisitor<'tcx> {
572572 & mut self ,
573573 module_def_id : LocalDefId ,
574574 defining_mod : LocalDefId ,
575- macro_ev : Option < EffectiveVisibility > ,
575+ macro_ev : EffectiveVisibility ,
576576 ) -> bool {
577577 if self . macro_reachable . insert ( ( module_def_id, defining_mod) ) {
578578 self . update_macro_reachable_mod ( module_def_id, defining_mod, macro_ev) ;
@@ -586,7 +586,7 @@ impl<'tcx> EmbargoVisitor<'tcx> {
586586 & mut self ,
587587 module_def_id : LocalDefId ,
588588 defining_mod : LocalDefId ,
589- macro_ev : Option < EffectiveVisibility > ,
589+ macro_ev : EffectiveVisibility ,
590590 ) {
591591 let module = self . tcx . hir ( ) . get_module ( module_def_id) . 0 ;
592592 for item_id in module. item_ids {
@@ -618,14 +618,14 @@ impl<'tcx> EmbargoVisitor<'tcx> {
618618 def_kind : DefKind ,
619619 vis : ty:: Visibility ,
620620 module : LocalDefId ,
621- macro_ev : Option < EffectiveVisibility > ,
621+ macro_ev : EffectiveVisibility ,
622622 ) {
623- self . update ( def_id, macro_ev, Level :: Reachable ) ;
623+ self . update ( def_id, Some ( macro_ev) , Level :: Reachable ) ;
624624 match def_kind {
625625 // No type privacy, so can be directly marked as reachable.
626626 DefKind :: Const | DefKind :: Static ( _) | DefKind :: TraitAlias | DefKind :: TyAlias => {
627627 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 ) ;
629629 }
630630 }
631631
@@ -637,7 +637,7 @@ impl<'tcx> EmbargoVisitor<'tcx> {
637637 let item = self . tcx . hir ( ) . expect_item ( def_id) ;
638638 if let hir:: ItemKind :: Macro ( MacroDef { macro_rules : false , .. } , _) = item. kind {
639639 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 ) ;
641641 }
642642 }
643643 }
@@ -790,7 +790,7 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
790790 // FIXME: This is some serious pessimization intended to workaround deficiencies
791791 // in the reachability pass (`middle/reachable.rs`). Types are marked as link-time
792792 // 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 ) ;
794794 self . reach_through_impl_trait ( item. owner_id . def_id , exist_ev)
795795 . generics ( )
796796 . predicates ( )
@@ -802,12 +802,12 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
802802 | hir:: ItemKind :: Static ( ..)
803803 | hir:: ItemKind :: Fn ( ..)
804804 | hir:: ItemKind :: TyAlias ( ..) => {
805- if item_ev . is_some ( ) {
805+ if let Some ( item_ev ) = item_ev {
806806 self . reach ( item. owner_id . def_id , item_ev) . generics ( ) . predicates ( ) . ty ( ) ;
807807 }
808808 }
809809 hir:: ItemKind :: Trait ( .., trait_item_refs) => {
810- if item_ev . is_some ( ) {
810+ if let Some ( item_ev ) = item_ev {
811811 self . reach ( item. owner_id . def_id , item_ev) . generics ( ) . predicates ( ) ;
812812
813813 for trait_item_ref in trait_item_refs {
@@ -827,23 +827,21 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
827827 }
828828 }
829829 hir:: ItemKind :: TraitAlias ( ..) => {
830- if item_ev . is_some ( ) {
830+ if let Some ( item_ev ) = item_ev {
831831 self . reach ( item. owner_id . def_id , item_ev) . generics ( ) . predicates ( ) ;
832832 }
833833 }
834834 // Visit everything except for private impl items.
835835 hir:: ItemKind :: Impl ( ref impl_) => {
836- if item_ev . is_some ( ) {
836+ if let Some ( item_ev ) = item_ev {
837837 self . reach ( item. owner_id . def_id , item_ev)
838838 . generics ( )
839839 . predicates ( )
840840 . ty ( )
841841 . trait_ref ( ) ;
842842
843843 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 ) {
847845 self . reach ( impl_item_ref. id . owner_id . def_id , impl_item_ev)
848846 . generics ( )
849847 . predicates ( )
@@ -855,12 +853,11 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
855853
856854 // Visit everything, but enum variants have their own levels.
857855 hir:: ItemKind :: Enum ( ref def, _) => {
858- if item_ev . is_some ( ) {
856+ if let Some ( item_ev ) = item_ev {
859857 self . reach ( item. owner_id . def_id , item_ev) . generics ( ) . predicates ( ) ;
860858 }
861859 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 ) {
864861 for field in variant. data . fields ( ) {
865862 self . reach ( field. def_id , variant_ev) . ty ( ) ;
866863 }
@@ -869,8 +866,7 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
869866 self . reach ( item. owner_id . def_id , variant_ev) . ty ( ) ;
870867 }
871868 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) {
874870 self . reach ( item. owner_id . def_id , ctor_ev) . ty ( ) ;
875871 }
876872 }
@@ -879,8 +875,7 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
879875 // Visit everything, but foreign items have their own levels.
880876 hir:: ItemKind :: ForeignMod { items, .. } => {
881877 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 ) {
884879 self . reach ( foreign_item. id . owner_id . def_id , foreign_item_ev)
885880 . generics ( )
886881 . predicates ( )
@@ -890,18 +885,16 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
890885 }
891886 // Visit everything except for private fields.
892887 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 {
894889 self . reach ( item. owner_id . def_id , item_ev) . generics ( ) . predicates ( ) ;
895890 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 ) {
898892 self . reach ( field. def_id , field_ev) . ty ( ) ;
899893 }
900894 }
901895 }
902896 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) {
905898 self . reach ( item. owner_id . def_id , ctor_ev) . ty ( ) ;
906899 }
907900 }
@@ -960,7 +953,7 @@ impl<'tcx> DefIdVisitor<'tcx> for ReachEverythingInTheInterfaceVisitor<'_, 'tcx>
960953 _descr : & dyn fmt:: Display ,
961954 ) -> ControlFlow < Self :: BreakTy > {
962955 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 ) ;
964957 }
965958 ControlFlow :: Continue ( ( ) )
966959 }
0 commit comments