]> git.lizzy.rs Git - rust.git/blob - tests/ui/fn_to_numeric_cast.rs
Add license header to Rust files
[rust.git] / tests / ui / fn_to_numeric_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 // only-64bit
12 #![feature(tool_lints)]
13
14 #![warn(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)]
15
16 fn foo() -> String { String::new() }
17
18 fn test_function_to_numeric_cast() {
19     let _ = foo as i8;
20     let _ = foo as i16;
21     let _ = foo as i32;
22     let _ = foo as i64;
23     let _ = foo as i128;
24     let _ = foo as isize;
25
26     let _ = foo as u8;
27     let _ = foo as u16;
28     let _ = foo as u32;
29     let _ = foo as u64;
30     let _ = foo as u128;
31
32     // Casting to usize is OK and should not warn
33     let _ = foo as usize;
34 }
35
36 fn test_function_var_to_numeric_cast() {
37     let abc: fn() -> String = foo;
38
39     let _ = abc as i8;
40     let _ = abc as i16;
41     let _ = abc as i32;
42     let _ = abc as i64;
43     let _ = abc as i128;
44     let _ = abc as isize;
45
46     let _ = abc as u8;
47     let _ = abc as u16;
48     let _ = abc as u32;
49     let _ = abc as u64;
50     let _ = abc as u128;
51
52     // Casting to usize is OK and should not warn
53     let _ = abc as usize;
54 }
55
56 fn fn_with_fn_args(f: fn(i32) -> i32) -> i32 {
57     f as i32
58 }
59
60 fn main() {}