@@ -1876,4 +1876,52 @@ impl<'tcx> LateLintPass<'tcx> for ImproperCTypesLint {
18761876 self . check_foreign_fn ( cx, CItemKind :: ExportedFunction , id, decl) ;
18771877 }
18781878 }
1879+
1880+ fn check_trait_item ( & mut self , cx : & LateContext < ' tcx > , tr_it : & hir:: TraitItem < ' tcx > ) {
1881+ match tr_it. kind {
1882+ hir:: TraitItemKind :: Const ( hir_ty, _) => {
1883+ let ty = cx. tcx . type_of ( hir_ty. hir_id . owner . def_id ) . instantiate_identity ( ) ;
1884+ self . check_type_for_external_abi_fnptr ( cx, hir_ty, ty) ;
1885+ }
1886+ hir:: TraitItemKind :: Fn ( sig, trait_fn) => {
1887+ match trait_fn {
1888+ // if the method is defined here,
1889+ // there is a matching ``LateLintPass::check_fn`` call,
1890+ // let's not redo that work
1891+ hir:: TraitFn :: Provided ( _) => return ,
1892+ hir:: TraitFn :: Required ( _) => ( ) ,
1893+ }
1894+ let local_id = tr_it. owner_id . def_id ;
1895+ if sig. header . abi . is_rustic_abi ( ) {
1896+ self . check_fn_for_external_abi_fnptr ( cx, local_id, sig. decl ) ;
1897+ } else {
1898+ self . check_foreign_fn ( cx, CItemKind :: ExportedFunction , local_id, sig. decl ) ;
1899+ }
1900+ }
1901+ hir:: TraitItemKind :: Type ( _, ty_maybe) => {
1902+ if let Some ( hir_ty) = ty_maybe {
1903+ let ty = cx. tcx . type_of ( hir_ty. hir_id . owner . def_id ) . instantiate_identity ( ) ;
1904+ self . check_type_for_external_abi_fnptr ( cx, hir_ty, ty) ;
1905+ }
1906+ }
1907+ }
1908+ }
1909+ fn check_impl_item ( & mut self , cx : & LateContext < ' tcx > , im_it : & hir:: ImplItem < ' tcx > ) {
1910+ // note: we do not skip these checks eventhough they might generate dupe warnings because:
1911+ // - the corresponding trait might be in another crate
1912+ // - the corresponding trait might have some templating involved, so only the impl has the full type information
1913+ match im_it. kind {
1914+ hir:: ImplItemKind :: Type ( hir_ty) => {
1915+ let ty = cx. tcx . type_of ( hir_ty. hir_id . owner . def_id ) . instantiate_identity ( ) ;
1916+ self . check_type_for_external_abi_fnptr ( cx, hir_ty, ty) ;
1917+ }
1918+ hir:: ImplItemKind :: Fn ( _sig, _) => {
1919+ // see ``LateLintPass::check_fn``
1920+ }
1921+ hir:: ImplItemKind :: Const ( hir_ty, _) => {
1922+ let ty = cx. tcx . type_of ( hir_ty. hir_id . owner . def_id ) . instantiate_identity ( ) ;
1923+ self . check_type_for_external_abi_fnptr ( cx, hir_ty, ty) ;
1924+ }
1925+ }
1926+ }
18791927}
0 commit comments