@@ -34,7 +34,7 @@ pub(super) fn check<'tcx>(
34
34
let cast_str = snippet_opt ( cx, cast_expr. span ) . unwrap_or_default ( ) ;
35
35
36
36
if let Some ( lit) = get_numeric_literal ( cast_expr) {
37
- let literal_str = cast_str;
37
+ let literal_str = & cast_str;
38
38
39
39
if_chain ! {
40
40
if let LitKind :: Int ( n, _) = lit. node;
@@ -52,10 +52,12 @@ pub(super) fn check<'tcx>(
52
52
53
53
match lit. node {
54
54
LitKind :: Int ( _, LitIntType :: Unsuffixed ) if cast_to. is_integral ( ) => {
55
- lint_unnecessary_cast ( cx, expr, & literal_str, cast_from, cast_to) ;
55
+ lint_unnecessary_cast ( cx, expr, literal_str, cast_from, cast_to) ;
56
+ return true ;
56
57
} ,
57
58
LitKind :: Float ( _, LitFloatType :: Unsuffixed ) if cast_to. is_floating_point ( ) => {
58
- lint_unnecessary_cast ( cx, expr, & literal_str, cast_from, cast_to) ;
59
+ lint_unnecessary_cast ( cx, expr, literal_str, cast_from, cast_to) ;
60
+ return true ;
59
61
} ,
60
62
LitKind :: Int ( _, LitIntType :: Unsuffixed ) | LitKind :: Float ( _, LitFloatType :: Unsuffixed ) => { } ,
61
63
LitKind :: Int ( _, LitIntType :: Signed ( _) | LitIntType :: Unsigned ( _) )
@@ -65,25 +67,15 @@ pub(super) fn check<'tcx>(
65
67
if let Some ( src) = snippet_opt ( cx, cast_expr. span ) {
66
68
if let Some ( num_lit) = NumericLiteral :: from_lit_kind ( & src, & lit. node ) {
67
69
lint_unnecessary_cast ( cx, expr, num_lit. integer , cast_from, cast_to) ;
70
+ return true ;
68
71
}
69
72
}
70
73
} ,
71
- _ => {
72
- if cast_from. kind ( ) == cast_to. kind ( ) && !in_external_macro ( cx. sess ( ) , expr. span ) {
73
- span_lint_and_sugg (
74
- cx,
75
- UNNECESSARY_CAST ,
76
- expr. span ,
77
- & format ! ( "casting to the same type is unnecessary (`{cast_from}` -> `{cast_to}`)" ) ,
78
- "try" ,
79
- literal_str,
80
- Applicability :: MachineApplicable ,
81
- ) ;
82
- return true ;
83
- }
84
- } ,
74
+ _ => { } ,
85
75
}
86
- } else if cast_from. kind ( ) == cast_to. kind ( ) && !in_external_macro ( cx. sess ( ) , expr. span ) {
76
+ }
77
+
78
+ if cast_from. kind ( ) == cast_to. kind ( ) && !in_external_macro ( cx. sess ( ) , expr. span ) {
87
79
span_lint_and_sugg (
88
80
cx,
89
81
UNNECESSARY_CAST ,
0 commit comments