@@ -1386,60 +1386,53 @@ impl LintPass for UnreachablePub {
1386
1386
1387
1387
impl UnreachablePub {
1388
1388
fn perform_lint ( & self , cx : & LateContext , what : & str , id : ast:: NodeId ,
1389
- vis : & hir:: Visibility , span : Span , exportable : bool ,
1390
- mut applicability : Applicability ) {
1391
- if !cx. access_levels . is_reachable ( id) && vis. node . is_pub ( ) {
1392
- if span. ctxt ( ) . outer ( ) . expn_info ( ) . is_some ( ) {
1393
- applicability = Applicability :: MaybeIncorrect ;
1394
- }
1395
- let def_span = cx. tcx . sess . codemap ( ) . def_span ( span) ;
1396
- let mut err = cx. struct_span_lint ( UNREACHABLE_PUB , def_span,
1397
- & format ! ( "unreachable `pub` {}" , what) ) ;
1398
- // We are presuming that visibility is token at start of
1399
- // declaration (can be macro variable rather than literal `pub`)
1400
- let pub_span = cx. tcx . sess . codemap ( ) . span_until_char ( def_span, ' ' ) ;
1401
- let replacement = if cx. tcx . features ( ) . crate_visibility_modifier {
1402
- "crate"
1403
- } else {
1404
- "pub(crate)"
1405
- } . to_owned ( ) ;
1406
- err. span_suggestion_with_applicability ( pub_span,
1407
- "consider restricting its visibility" ,
1408
- replacement,
1409
- applicability) ;
1410
- if exportable {
1411
- err. help ( "or consider exporting it for use by other crates" ) ;
1412
- }
1413
- err. emit ( ) ;
1389
+ vis : & hir:: Visibility , span : Span , exportable : bool ) {
1390
+ let mut applicability = Applicability :: MachineApplicable ;
1391
+ match vis. node {
1392
+ hir:: VisibilityPublic if !cx. access_levels . is_reachable ( id) => {
1393
+ if span. ctxt ( ) . outer ( ) . expn_info ( ) . is_some ( ) {
1394
+ applicability = Applicability :: MaybeIncorrect ;
1395
+ }
1396
+ let def_span = cx. tcx . sess . codemap ( ) . def_span ( span) ;
1397
+ let mut err = cx. struct_span_lint ( UNREACHABLE_PUB , def_span,
1398
+ & format ! ( "unreachable `pub` {}" , what) ) ;
1399
+ let replacement = if cx. tcx . features ( ) . crate_visibility_modifier {
1400
+ "crate"
1401
+ } else {
1402
+ "pub(crate)"
1403
+ } . to_owned ( ) ;
1404
+
1405
+ err. span_suggestion_with_applicability ( vis. span ,
1406
+ "consider restricting its visibility" ,
1407
+ replacement,
1408
+ applicability) ;
1409
+ if exportable {
1410
+ err. help ( "or consider exporting it for use by other crates" ) ;
1411
+ }
1412
+ err. emit ( ) ;
1413
+ } ,
1414
+ _ => { }
1414
1415
}
1415
1416
}
1416
1417
}
1417
1418
1418
1419
1419
1420
impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for UnreachablePub {
1420
1421
fn check_item ( & mut self , cx : & LateContext , item : & hir:: Item ) {
1421
- let applicability = match item. node {
1422
- // suggestion span-manipulation is inadequate for `pub use
1423
- // module::{item}` (Issue #50455)
1424
- hir:: ItemUse ( ..) => Applicability :: MaybeIncorrect ,
1425
- _ => Applicability :: MachineApplicable ,
1426
- } ;
1427
- self . perform_lint ( cx, "item" , item. id , & item. vis , item. span , true , applicability) ;
1422
+ self . perform_lint ( cx, "item" , item. id , & item. vis , item. span , true ) ;
1428
1423
}
1429
1424
1430
1425
fn check_foreign_item ( & mut self , cx : & LateContext , foreign_item : & hir:: ForeignItem ) {
1431
1426
self . perform_lint ( cx, "item" , foreign_item. id , & foreign_item. vis ,
1432
- foreign_item. span , true , Applicability :: MachineApplicable ) ;
1427
+ foreign_item. span , true ) ;
1433
1428
}
1434
1429
1435
1430
fn check_struct_field ( & mut self , cx : & LateContext , field : & hir:: StructField ) {
1436
- self . perform_lint ( cx, "field" , field. id , & field. vis , field. span , false ,
1437
- Applicability :: MachineApplicable ) ;
1431
+ self . perform_lint ( cx, "field" , field. id , & field. vis , field. span , false ) ;
1438
1432
}
1439
1433
1440
1434
fn check_impl_item ( & mut self , cx : & LateContext , impl_item : & hir:: ImplItem ) {
1441
- self . perform_lint ( cx, "item" , impl_item. id , & impl_item. vis , impl_item. span , false ,
1442
- Applicability :: MachineApplicable ) ;
1435
+ self . perform_lint ( cx, "item" , impl_item. id , & impl_item. vis , impl_item. span , false ) ;
1443
1436
}
1444
1437
}
1445
1438
0 commit comments