2018-10-06 11:18:06 -05:00
|
|
|
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
|
2018-10-05 00:49:08 -05:00
|
|
|
// only-64bit
|
2018-10-03 05:02:06 -05:00
|
|
|
#![feature(tool_lints)]
|
|
|
|
|
2018-10-05 00:49:08 -05:00
|
|
|
#![warn(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)]
|
2018-10-03 05:02:06 -05:00
|
|
|
|
|
|
|
fn foo() -> String { String::new() }
|
|
|
|
|
|
|
|
fn test_function_to_numeric_cast() {
|
|
|
|
let _ = foo as i8;
|
|
|
|
let _ = foo as i16;
|
|
|
|
let _ = foo as i32;
|
|
|
|
let _ = foo as i64;
|
|
|
|
let _ = foo as i128;
|
|
|
|
let _ = foo as isize;
|
|
|
|
|
|
|
|
let _ = foo as u8;
|
|
|
|
let _ = foo as u16;
|
|
|
|
let _ = foo as u32;
|
|
|
|
let _ = foo as u64;
|
|
|
|
let _ = foo as u128;
|
|
|
|
|
|
|
|
// Casting to usize is OK and should not warn
|
|
|
|
let _ = foo as usize;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_function_var_to_numeric_cast() {
|
|
|
|
let abc: fn() -> String = foo;
|
|
|
|
|
|
|
|
let _ = abc as i8;
|
|
|
|
let _ = abc as i16;
|
|
|
|
let _ = abc as i32;
|
|
|
|
let _ = abc as i64;
|
|
|
|
let _ = abc as i128;
|
|
|
|
let _ = abc as isize;
|
|
|
|
|
|
|
|
let _ = abc as u8;
|
|
|
|
let _ = abc as u16;
|
|
|
|
let _ = abc as u32;
|
|
|
|
let _ = abc as u64;
|
|
|
|
let _ = abc as u128;
|
|
|
|
|
|
|
|
// Casting to usize is OK and should not warn
|
|
|
|
let _ = abc as usize;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn fn_with_fn_args(f: fn(i32) -> i32) -> i32 {
|
|
|
|
f as i32
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|