1
1
use std:: iter;
2
2
use std:: ops:: ControlFlow ;
3
3
4
- use rustc_abi:: { BackendRepr , ExternAbi , TagEncoding , VariantIdx , Variants , WrappingRange } ;
4
+ use rustc_abi:: { BackendRepr , TagEncoding , VariantIdx , Variants , WrappingRange } ;
5
5
use rustc_data_structures:: fx:: FxHashSet ;
6
6
use rustc_errors:: DiagMessage ;
7
7
use rustc_hir:: intravisit:: VisitorExt ;
@@ -1349,7 +1349,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
1349
1349
1350
1350
ty:: FnPtr ( sig_tys, hdr) => {
1351
1351
let sig = sig_tys. with ( hdr) ;
1352
- if self . is_internal_abi ( sig. abi ( ) ) {
1352
+ if sig. abi ( ) . is_rustic_abi ( ) {
1353
1353
return FfiUnsafe {
1354
1354
ty,
1355
1355
reason : fluent:: lint_improper_ctypes_fnptr_reason,
@@ -1552,13 +1552,6 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
1552
1552
self . check_type_for_ffi_and_report_errors ( span, ty, true , false ) ;
1553
1553
}
1554
1554
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
-
1562
1555
/// Find any fn-ptr types with external ABIs in `ty`.
1563
1556
///
1564
1557
/// For example, `Option<extern "C" fn()>` returns `extern "C" fn()`
@@ -1567,17 +1560,16 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
1567
1560
hir_ty : & hir:: Ty < ' tcx > ,
1568
1561
ty : Ty < ' tcx > ,
1569
1562
) -> Vec < ( Ty < ' tcx > , Span ) > {
1570
- struct FnPtrFinder < ' a , ' b , ' tcx > {
1571
- visitor : & ' a ImproperCTypesVisitor < ' b , ' tcx > ,
1563
+ struct FnPtrFinder < ' tcx > {
1572
1564
spans : Vec < Span > ,
1573
1565
tys : Vec < Ty < ' tcx > > ,
1574
1566
}
1575
1567
1576
- impl < ' a , ' b , ' tcx > hir:: intravisit:: Visitor < ' _ > for FnPtrFinder < ' a , ' b , ' tcx > {
1568
+ impl < ' tcx > hir:: intravisit:: Visitor < ' _ > for FnPtrFinder < ' tcx > {
1577
1569
fn visit_ty ( & mut self , ty : & ' _ hir:: Ty < ' _ , AmbigArg > ) {
1578
1570
debug ! ( ?ty) ;
1579
1571
if let hir:: TyKind :: BareFn ( hir:: BareFnTy { abi, .. } ) = ty. kind
1580
- && !self . visitor . is_internal_abi ( * abi )
1572
+ && !abi . is_rustic_abi ( )
1581
1573
{
1582
1574
self . spans . push ( ty. span ) ;
1583
1575
}
@@ -1586,12 +1578,12 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
1586
1578
}
1587
1579
}
1588
1580
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 > {
1590
1582
type Result = ( ) ;
1591
1583
1592
1584
fn visit_ty ( & mut self , ty : Ty < ' tcx > ) -> Self :: Result {
1593
1585
if let ty:: FnPtr ( _, hdr) = ty. kind ( )
1594
- && !self . visitor . is_internal_abi ( hdr. abi )
1586
+ && !hdr. abi . is_rustic_abi ( )
1595
1587
{
1596
1588
self . tys . push ( ty) ;
1597
1589
}
@@ -1600,7 +1592,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
1600
1592
}
1601
1593
}
1602
1594
1603
- let mut visitor = FnPtrFinder { visitor : self , spans : Vec :: new ( ) , tys : Vec :: new ( ) } ;
1595
+ let mut visitor = FnPtrFinder { spans : Vec :: new ( ) , tys : Vec :: new ( ) } ;
1604
1596
ty. visit_with ( & mut visitor) ;
1605
1597
visitor. visit_ty_unambig ( hir_ty) ;
1606
1598
@@ -1615,13 +1607,13 @@ impl<'tcx> LateLintPass<'tcx> for ImproperCTypesDeclarations {
1615
1607
1616
1608
match it. kind {
1617
1609
hir:: ForeignItemKind :: Fn ( sig, _, _) => {
1618
- if vis . is_internal_abi ( abi ) {
1610
+ if abi . is_rustic_abi ( ) {
1619
1611
vis. check_fn ( it. owner_id . def_id , sig. decl )
1620
1612
} else {
1621
1613
vis. check_foreign_fn ( it. owner_id . def_id , sig. decl ) ;
1622
1614
}
1623
1615
}
1624
- hir:: ForeignItemKind :: Static ( ty, _, _) if !vis . is_internal_abi ( abi ) => {
1616
+ hir:: ForeignItemKind :: Static ( ty, _, _) if !abi . is_rustic_abi ( ) => {
1625
1617
vis. check_foreign_static ( it. owner_id , ty. span ) ;
1626
1618
}
1627
1619
hir:: ForeignItemKind :: Static ( ..) | hir:: ForeignItemKind :: Type => ( ) ,
@@ -1775,7 +1767,7 @@ impl<'tcx> LateLintPass<'tcx> for ImproperCTypesDefinitions {
1775
1767
} ;
1776
1768
1777
1769
let mut vis = ImproperCTypesVisitor { cx, mode : CItemKind :: Definition } ;
1778
- if vis . is_internal_abi ( abi ) {
1770
+ if abi . is_rustic_abi ( ) {
1779
1771
vis. check_fn ( id, decl) ;
1780
1772
} else {
1781
1773
vis. check_foreign_fn ( id, decl) ;
0 commit comments