]> git.lizzy.rs Git - rust.git/blob - tests/ui/cast.rs
Merge pull request #3291 from JoshMcguigan/cmp_owned-3289
[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
11
12
13
14 #[warn(clippy::cast_precision_loss, clippy::cast_possible_truncation, clippy::cast_sign_loss, clippy::cast_possible_wrap, clippy::cast_lossless)]
15 #[allow(clippy::no_effect, clippy::unnecessary_operation)]
16 fn main() {
17     // Test clippy::cast_precision_loss
18     1i32 as f32;
19     1i64 as f32;
20     1i64 as f64;
21     1u32 as f32;
22     1u64 as f32;
23     1u64 as f64;
24     // Test clippy::cast_possible_truncation
25     1f32 as i32;
26     1f32 as u32;
27     1f64 as f32;
28     1i32 as i8;
29     1i32 as u8;
30     1f64 as isize;
31     1f64 as usize;
32     // Test clippy::cast_possible_wrap
33     1u8 as i8;
34     1u16 as i16;
35     1u32 as i32;
36     1u64 as i64;
37     1usize as isize;
38     // Test clippy::cast_lossless with casts from floating-point types
39     1.0f32 as f64;
40     // Test clippy::cast_lossless with an expression wrapped in parens
41     (1u8 + 1u8) as u16;
42     // Test clippy::cast_sign_loss
43     1i32 as u32;
44     1isize as usize;
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     // Should not trigger
52     let v = vec!(1);
53     &v as &[i32];
54     1.0 as f64;
55     1 as u64;
56 }