@@ -1129,35 +1129,12 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
1129
1129
1130
1130
struct SanePrivacyVisitor < ' a , ' tcx : ' a > {
1131
1131
tcx : & ' a ty:: ctxt < ' tcx > ,
1132
- in_block : bool ,
1133
1132
}
1134
1133
1135
1134
impl < ' a , ' tcx , ' v > Visitor < ' v > for SanePrivacyVisitor < ' a , ' tcx > {
1136
- /// We want to visit items in the context of their containing
1137
- /// module and so forth, so supply a crate for doing a deep walk.
1138
- fn visit_nested_item ( & mut self , item : hir:: ItemId ) {
1139
- self . visit_item ( self . tcx . map . expect_item ( item. id ) )
1140
- }
1141
-
1142
1135
fn visit_item ( & mut self , item : & hir:: Item ) {
1143
1136
self . check_sane_privacy ( item) ;
1144
- if self . in_block {
1145
- self . check_all_inherited ( item) ;
1146
- }
1147
-
1148
- let orig_in_block = self . in_block ;
1149
-
1150
- // Modules turn privacy back on, otherwise we inherit
1151
- self . in_block = if let hir:: ItemMod ( ..) = item. node { false } else { orig_in_block } ;
1152
-
1153
1137
intravisit:: walk_item ( self , item) ;
1154
- self . in_block = orig_in_block;
1155
- }
1156
-
1157
- fn visit_block ( & mut self , b : & ' v hir:: Block ) {
1158
- let orig_in_block = replace ( & mut self . in_block , true ) ;
1159
- intravisit:: walk_block ( self , b) ;
1160
- self . in_block = orig_in_block;
1161
1138
}
1162
1139
}
1163
1140
@@ -1206,40 +1183,6 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
1206
1183
hir:: ItemUse ( ..) | hir:: ItemTy ( ..) => { }
1207
1184
}
1208
1185
}
1209
-
1210
- /// When inside of something like a function or a method, visibility has no
1211
- /// control over anything so this forbids any mention of any visibility
1212
- fn check_all_inherited ( & self , item : & hir:: Item ) {
1213
- let check_inherited = |sp, vis| {
1214
- if vis != hir:: Inherited {
1215
- span_err ! ( self . tcx. sess, sp, E0447 ,
1216
- "visibility has no effect inside functions or block expressions" ) ;
1217
- }
1218
- } ;
1219
-
1220
- check_inherited ( item. span , item. vis ) ;
1221
- match item. node {
1222
- hir:: ItemImpl ( _, _, _, _, _, ref impl_items) => {
1223
- for impl_item in impl_items {
1224
- check_inherited ( impl_item. span , impl_item. vis ) ;
1225
- }
1226
- }
1227
- hir:: ItemForeignMod ( ref fm) => {
1228
- for fi in & fm. items {
1229
- check_inherited ( fi. span , fi. vis ) ;
1230
- }
1231
- }
1232
- hir:: ItemStruct ( ref vdata, _) => {
1233
- for f in vdata. fields ( ) {
1234
- check_inherited ( f. span , f. node . kind . visibility ( ) ) ;
1235
- }
1236
- }
1237
- hir:: ItemDefaultImpl ( ..) | hir:: ItemEnum ( ..) | hir:: ItemTrait ( ..) |
1238
- hir:: ItemConst ( ..) | hir:: ItemStatic ( ..) | hir:: ItemFn ( ..) |
1239
- hir:: ItemMod ( ..) | hir:: ItemExternCrate ( ..) |
1240
- hir:: ItemUse ( ..) | hir:: ItemTy ( ..) => { }
1241
- }
1242
- }
1243
1186
}
1244
1187
1245
1188
///////////////////////////////////////////////////////////////////////////////
@@ -1823,11 +1766,8 @@ pub fn check_crate(tcx: &ty::ctxt,
1823
1766
1824
1767
// Sanity check to make sure that all privacy usage and controls are
1825
1768
// reasonable.
1826
- let mut visitor = SanePrivacyVisitor {
1827
- tcx : tcx,
1828
- in_block : false ,
1829
- } ;
1830
- intravisit:: walk_crate ( & mut visitor, krate) ;
1769
+ let mut visitor = SanePrivacyVisitor { tcx : tcx } ;
1770
+ krate. visit_all_items ( & mut visitor) ;
1831
1771
1832
1772
// Figure out who everyone's parent is
1833
1773
let mut visitor = ParentVisitor {
0 commit comments