File tree Expand file tree Collapse file tree 7 files changed +102
-67
lines changed Expand file tree Collapse file tree 7 files changed +102
-67
lines changed Original file line number Diff line number Diff line change @@ -42,32 +42,4 @@ fn main() {
4242 i32:: max_value ( ) as u32 ;
4343 i64:: max_value ( ) as u64 ;
4444 i128:: max_value ( ) as u128 ;
45- // Extra checks for *size
46- // Test cast_unnecessary
47- 1i32 as i32 ;
48- 1f32 as f32 ;
49- false as bool ;
50- & 1i32 as & i32 ;
51- // macro version
52- macro_rules! foo {
53- ( $a: ident, $b: ident) => {
54- pub fn $a( ) -> $b {
55- 1 as $b
56- }
57- } ;
58- }
59- foo ! ( a, i32 ) ;
60- foo ! ( b, f32 ) ;
61- foo ! ( c, f64 ) ;
62-
63- // casting integer literal to float is unnecessary
64- 100 as f32 ;
65- 100 as f64 ;
66- 100_i32 as f64 ;
67- // Should not trigger
68- #[ rustfmt:: skip]
69- let v = vec ! ( 1 ) ;
70- & v as & [ i32 ] ;
71- 1.0 as f64 ;
72- 1 as u64 ;
7345}
Original file line number Diff line number Diff line change @@ -138,43 +138,5 @@ error: casting isize to usize may lose the sign of the value
138138LL | -1isize as usize;
139139 | ^^^^^^^^^^^^^^^^
140140
141- error: casting to the same type is unnecessary (`i32` -> `i32`)
142- --> $DIR/cast.rs:47:5
143- |
144- LL | 1i32 as i32;
145- | ^^^^^^^^^^^
146- |
147- = note: `-D clippy::unnecessary-cast` implied by `-D warnings`
148-
149- error: casting to the same type is unnecessary (`f32` -> `f32`)
150- --> $DIR/cast.rs:48:5
151- |
152- LL | 1f32 as f32;
153- | ^^^^^^^^^^^
154-
155- error: casting to the same type is unnecessary (`bool` -> `bool`)
156- --> $DIR/cast.rs:49:5
157- |
158- LL | false as bool;
159- | ^^^^^^^^^^^^^
160-
161- error: casting integer literal to f32 is unnecessary
162- --> $DIR/cast.rs:64:5
163- |
164- LL | 100 as f32;
165- | ^^^^^^^^^^ help: try: `100_f32`
166-
167- error: casting integer literal to f64 is unnecessary
168- --> $DIR/cast.rs:65:5
169- |
170- LL | 100 as f64;
171- | ^^^^^^^^^^ help: try: `100_f64`
172-
173- error: casting integer literal to f64 is unnecessary
174- --> $DIR/cast.rs:66:5
175- |
176- LL | 100_i32 as f64;
177- | ^^^^^^^^^^^^^^ help: try: `100_f64`
178-
179- error: aborting due to 28 previous errors
141+ error: aborting due to 22 previous errors
180142
Original file line number Diff line number Diff line change 1+ #![ warn( clippy:: unnecessary_cast) ]
2+ #![ allow( clippy:: no_effect) ]
3+
4+ fn main ( ) {
5+ // Test cast_unnecessary
6+ 1i32 as i32 ;
7+ 1f32 as f32 ;
8+ false as bool ;
9+ & 1i32 as & i32 ;
10+
11+ // macro version
12+ macro_rules! foo {
13+ ( $a: ident, $b: ident) => {
14+ #[ allow( unused) ]
15+ pub fn $a( ) -> $b {
16+ 1 as $b
17+ }
18+ } ;
19+ }
20+ foo ! ( a, i32 ) ;
21+ foo ! ( b, f32 ) ;
22+ foo ! ( c, f64 ) ;
23+ }
Original file line number Diff line number Diff line change 1+ error: casting to the same type is unnecessary (`i32` -> `i32`)
2+ --> $DIR/unnecessary_cast.rs:6:5
3+ |
4+ LL | 1i32 as i32;
5+ | ^^^^^^^^^^^
6+ |
7+ = note: `-D clippy::unnecessary-cast` implied by `-D warnings`
8+
9+ error: casting to the same type is unnecessary (`f32` -> `f32`)
10+ --> $DIR/unnecessary_cast.rs:7:5
11+ |
12+ LL | 1f32 as f32;
13+ | ^^^^^^^^^^^
14+
15+ error: casting to the same type is unnecessary (`bool` -> `bool`)
16+ --> $DIR/unnecessary_cast.rs:8:5
17+ |
18+ LL | false as bool;
19+ | ^^^^^^^^^^^^^
20+
21+ error: aborting due to 3 previous errors
22+
Original file line number Diff line number Diff line change 1+ // run-rustfix
2+
3+ #![warn(clippy::unnecessary_cast)]
4+ #![allow(clippy::no_effect, clippy::unnecessary_operation)]
5+
6+ fn main() {
7+ // casting integer literal to float is unnecessary
8+ 100_f32;
9+ 100_f64;
10+ 100_f64;
11+ // Should not trigger
12+ #[rustfmt::skip]
13+ let v = vec!(1);
14+ &v as &[i32];
15+ 1.0 as f64;
16+ 1 as u64;
17+ }
Original file line number Diff line number Diff line change 1+ // run-rustfix
2+
3+ #![ warn( clippy:: unnecessary_cast) ]
4+ #![ allow( clippy:: no_effect, clippy:: unnecessary_operation) ]
5+
6+ fn main ( ) {
7+ // casting integer literal to float is unnecessary
8+ 100 as f32 ;
9+ 100 as f64 ;
10+ 100_i32 as f64 ;
11+ // Should not trigger
12+ #[ rustfmt:: skip]
13+ let v = vec ! ( 1 ) ;
14+ & v as & [ i32 ] ;
15+ 1.0 as f64 ;
16+ 1 as u64 ;
17+ }
Original file line number Diff line number Diff line change 1+ error: casting integer literal to f32 is unnecessary
2+ --> $DIR/unnecessary_cast_fixable.rs:8:5
3+ |
4+ LL | 100 as f32;
5+ | ^^^^^^^^^^ help: try: `100_f32`
6+ |
7+ = note: `-D clippy::unnecessary-cast` implied by `-D warnings`
8+
9+ error: casting integer literal to f64 is unnecessary
10+ --> $DIR/unnecessary_cast_fixable.rs:9:5
11+ |
12+ LL | 100 as f64;
13+ | ^^^^^^^^^^ help: try: `100_f64`
14+
15+ error: casting integer literal to f64 is unnecessary
16+ --> $DIR/unnecessary_cast_fixable.rs:10:5
17+ |
18+ LL | 100_i32 as f64;
19+ | ^^^^^^^^^^^^^^ help: try: `100_f64`
20+
21+ error: aborting due to 3 previous errors
22+
You can’t perform that action at this time.
0 commit comments