@@ -16,35 +16,29 @@ pub(super) fn check<'tcx>(
1616 to_ty : Ty < ' tcx > ,
1717 arg : & ' tcx Expr < ' _ > ,
1818) -> bool {
19- let tcx = cx. tcx ;
20-
21- let ( ty:: Int ( _) | ty:: Uint ( _) , ty:: Adt ( adt, substs) ) = ( & from_ty. kind ( ) , to_ty. kind ( ) ) else {
22- return false ;
23- } ;
24-
25- if !tcx. is_diagnostic_item ( sym:: NonZero , adt. did ( ) ) {
26- return false ;
19+ if let ty:: Int ( _) | ty:: Uint ( _) = from_ty. kind ( )
20+ && let ty:: Adt ( adt, substs) = to_ty. kind ( )
21+ && cx. tcx . is_diagnostic_item ( sym:: NonZero , adt. did ( ) )
22+ && let int_ty = substs. type_at ( 0 )
23+ && from_ty == int_ty
24+ {
25+ span_lint_and_then (
26+ cx,
27+ TRANSMUTE_INT_TO_NON_ZERO ,
28+ e. span ,
29+ format ! ( "transmute from a `{from_ty}` to a `{}<{int_ty}>`" , sym:: NonZero ) ,
30+ |diag| {
31+ let arg = sugg:: Sugg :: hir ( cx, arg, ".." ) ;
32+ diag. span_suggestion (
33+ e. span ,
34+ "consider using" ,
35+ format ! ( "{}::{}({arg})" , sym:: NonZero , sym:: new_unchecked) ,
36+ Applicability :: Unspecified ,
37+ ) ;
38+ } ,
39+ ) ;
40+ true
41+ } else {
42+ false
2743 }
28-
29- let int_ty = substs. type_at ( 0 ) ;
30- if from_ty != int_ty {
31- return false ;
32- }
33-
34- span_lint_and_then (
35- cx,
36- TRANSMUTE_INT_TO_NON_ZERO ,
37- e. span ,
38- format ! ( "transmute from a `{from_ty}` to a `{}<{int_ty}>`" , sym:: NonZero ) ,
39- |diag| {
40- let arg = sugg:: Sugg :: hir ( cx, arg, ".." ) ;
41- diag. span_suggestion (
42- e. span ,
43- "consider using" ,
44- format ! ( "{}::{}({arg})" , sym:: NonZero , sym:: new_unchecked) ,
45- Applicability :: Unspecified ,
46- ) ;
47- } ,
48- ) ;
49- true
5044}
0 commit comments