11use std:: iter;
22use std:: ops:: ControlFlow ;
33
4- use rustc_abi:: { BackendRepr , ExternAbi , TagEncoding , VariantIdx , Variants , WrappingRange } ;
4+ use rustc_abi:: { BackendRepr , TagEncoding , VariantIdx , Variants , WrappingRange } ;
55use rustc_data_structures:: fx:: FxHashSet ;
66use rustc_errors:: DiagMessage ;
77use rustc_hir:: intravisit:: VisitorExt ;
@@ -1349,7 +1349,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
13491349
13501350 ty:: FnPtr ( sig_tys, hdr) => {
13511351 let sig = sig_tys. with ( hdr) ;
1352- if self . is_internal_abi ( sig. abi ( ) ) {
1352+ if sig. abi ( ) . is_rustic_abi ( ) {
13531353 return FfiUnsafe {
13541354 ty,
13551355 reason : fluent:: lint_improper_ctypes_fnptr_reason,
@@ -1552,13 +1552,6 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
15521552 self . check_type_for_ffi_and_report_errors ( span, ty, true , false ) ;
15531553 }
15541554
1555- fn is_internal_abi ( & self , abi : ExternAbi ) -> bool {
1556- matches ! (
1557- abi,
1558- ExternAbi :: Rust | ExternAbi :: RustCall | ExternAbi :: RustCold | ExternAbi :: RustIntrinsic
1559- )
1560- }
1561-
15621555 /// Find any fn-ptr types with external ABIs in `ty`.
15631556 ///
15641557 /// For example, `Option<extern "C" fn()>` returns `extern "C" fn()`
@@ -1567,17 +1560,16 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
15671560 hir_ty : & hir:: Ty < ' tcx > ,
15681561 ty : Ty < ' tcx > ,
15691562 ) -> Vec < ( Ty < ' tcx > , Span ) > {
1570- struct FnPtrFinder < ' a , ' b , ' tcx > {
1571- visitor : & ' a ImproperCTypesVisitor < ' b , ' tcx > ,
1563+ struct FnPtrFinder < ' tcx > {
15721564 spans : Vec < Span > ,
15731565 tys : Vec < Ty < ' tcx > > ,
15741566 }
15751567
1576- impl < ' a , ' b , ' tcx > hir:: intravisit:: Visitor < ' _ > for FnPtrFinder < ' a , ' b , ' tcx > {
1568+ impl < ' tcx > hir:: intravisit:: Visitor < ' _ > for FnPtrFinder < ' tcx > {
15771569 fn visit_ty ( & mut self , ty : & ' _ hir:: Ty < ' _ , AmbigArg > ) {
15781570 debug ! ( ?ty) ;
15791571 if let hir:: TyKind :: BareFn ( hir:: BareFnTy { abi, .. } ) = ty. kind
1580- && !self . visitor . is_internal_abi ( * abi )
1572+ && !abi . is_rustic_abi ( )
15811573 {
15821574 self . spans . push ( ty. span ) ;
15831575 }
@@ -1586,12 +1578,12 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
15861578 }
15871579 }
15881580
1589- impl < ' a , ' b , ' tcx > ty:: visit:: TypeVisitor < TyCtxt < ' tcx > > for FnPtrFinder < ' a , ' b , ' tcx > {
1581+ impl < ' tcx > ty:: visit:: TypeVisitor < TyCtxt < ' tcx > > for FnPtrFinder < ' tcx > {
15901582 type Result = ( ) ;
15911583
15921584 fn visit_ty ( & mut self , ty : Ty < ' tcx > ) -> Self :: Result {
15931585 if let ty:: FnPtr ( _, hdr) = ty. kind ( )
1594- && !self . visitor . is_internal_abi ( hdr. abi )
1586+ && !hdr. abi . is_rustic_abi ( )
15951587 {
15961588 self . tys . push ( ty) ;
15971589 }
@@ -1600,7 +1592,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
16001592 }
16011593 }
16021594
1603- let mut visitor = FnPtrFinder { visitor : self , spans : Vec :: new ( ) , tys : Vec :: new ( ) } ;
1595+ let mut visitor = FnPtrFinder { spans : Vec :: new ( ) , tys : Vec :: new ( ) } ;
16041596 ty. visit_with ( & mut visitor) ;
16051597 visitor. visit_ty_unambig ( hir_ty) ;
16061598
@@ -1615,13 +1607,13 @@ impl<'tcx> LateLintPass<'tcx> for ImproperCTypesDeclarations {
16151607
16161608 match it. kind {
16171609 hir:: ForeignItemKind :: Fn ( sig, _, _) => {
1618- if vis . is_internal_abi ( abi ) {
1610+ if abi . is_rustic_abi ( ) {
16191611 vis. check_fn ( it. owner_id . def_id , sig. decl )
16201612 } else {
16211613 vis. check_foreign_fn ( it. owner_id . def_id , sig. decl ) ;
16221614 }
16231615 }
1624- hir:: ForeignItemKind :: Static ( ty, _, _) if !vis . is_internal_abi ( abi ) => {
1616+ hir:: ForeignItemKind :: Static ( ty, _, _) if !abi . is_rustic_abi ( ) => {
16251617 vis. check_foreign_static ( it. owner_id , ty. span ) ;
16261618 }
16271619 hir:: ForeignItemKind :: Static ( ..) | hir:: ForeignItemKind :: Type => ( ) ,
@@ -1775,7 +1767,7 @@ impl<'tcx> LateLintPass<'tcx> for ImproperCTypesDefinitions {
17751767 } ;
17761768
17771769 let mut vis = ImproperCTypesVisitor { cx, mode : CItemKind :: Definition } ;
1778- if vis . is_internal_abi ( abi ) {
1770+ if abi . is_rustic_abi ( ) {
17791771 vis. check_fn ( id, decl) ;
17801772 } else {
17811773 vis. check_foreign_fn ( id, decl) ;
0 commit comments