]> git.lizzy.rs Git - rust.git/blob - tests/ui/cast.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / cast.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 #[warn(
11     clippy::cast_precision_loss,
12     clippy::cast_possible_truncation,
13     clippy::cast_sign_loss,
14     clippy::cast_possible_wrap,
15     clippy::cast_lossless
16 )]
17 #[allow(clippy::no_effect, clippy::unnecessary_operation)]
18 fn main() {
19     // Test clippy::cast_precision_loss
20     1i32 as f32;
21     1i64 as f32;
22     1i64 as f64;
23     1u32 as f32;
24     1u64 as f32;
25     1u64 as f64;
26     // Test clippy::cast_possible_truncation
27     1f32 as i32;
28     1f32 as u32;
29     1f64 as f32;
30     1i32 as i8;
31     1i32 as u8;
32     1f64 as isize;
33     1f64 as usize;
34     // Test clippy::cast_possible_wrap
35     1u8 as i8;
36     1u16 as i16;
37     1u32 as i32;
38     1u64 as i64;
39     1usize as isize;
40     // Test clippy::cast_lossless with casts from floating-point types
41     1.0f32 as f64;
42     // Test clippy::cast_lossless with an expression wrapped in parens
43     (1u8 + 1u8) as u16;
44     // Test clippy::cast_sign_loss
45     1i32 as u32;
46     1isize as usize;
47     // Extra checks for *size
48     // Test cast_unnecessary
49     1i32 as i32;
50     1f32 as f32;
51     false as bool;
52     &1i32 as &i32;
53     // Should not trigger
54     #[rustfmt::skip]
55     let v = vec!(1);
56     &v as &[i32];
57     1.0 as f64;
58     1 as u64;
59 }