@@ -4,7 +4,7 @@ use clippy_utils::ty::is_c_void;
44use rustc_hir:: Expr ;
55use rustc_lint:: LateContext ;
66use rustc_middle:: ty:: subst:: Subst ;
7- use rustc_middle:: ty:: { self , Ty , TypeAndMut } ;
7+ use rustc_middle:: ty:: { self , IntTy , Ty , TypeAndMut , UintTy } ;
88use rustc_span:: Span ;
99
1010#[ allow( clippy:: too_many_lines) ]
@@ -24,6 +24,7 @@ pub(super) fn check<'tcx>(
2424 to_ty : to_sub_ty,
2525 } => match reduce_ty ( cx, to_sub_ty) {
2626 ReducedTy :: IntArray | ReducedTy :: TypeErasure => break ,
27+ ReducedTy :: UnorderedFields ( ty) if is_size_pair ( ty) => break ,
2728 ReducedTy :: Ref ( to_sub_ty) => {
2829 from_ty = unsized_ty;
2930 to_ty = to_sub_ty;
@@ -49,6 +50,7 @@ pub(super) fn check<'tcx>(
4950 from_ty : from_sub_ty,
5051 } => match reduce_ty ( cx, from_sub_ty) {
5152 ReducedTy :: IntArray | ReducedTy :: TypeErasure => break ,
53+ ReducedTy :: UnorderedFields ( ty) if is_size_pair ( ty) => break ,
5254 ReducedTy :: Ref ( from_sub_ty) => {
5355 from_ty = from_sub_ty;
5456 to_ty = unsized_ty;
@@ -333,3 +335,14 @@ fn is_zero_sized_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
333335 }
334336 }
335337}
338+
339+ fn is_size_pair ( ty : Ty < ' _ > ) -> bool {
340+ if let ty:: Tuple ( tys) = * ty. kind ( )
341+ && let [ ty1, ty2] = & * * tys
342+ {
343+ matches ! ( ty1. kind( ) , ty:: Int ( IntTy :: Isize ) | ty:: Uint ( UintTy :: Usize ) )
344+ && matches ! ( ty2. kind( ) , ty:: Int ( IntTy :: Isize ) | ty:: Uint ( UintTy :: Usize ) )
345+ } else {
346+ false
347+ }
348+ }
0 commit comments