rust/tests/ui/default_numeric_fallback.rs

59 lines
1015 B
Rust
Raw Normal View History

2021-02-02 03:26:20 +00:00
#![warn(clippy::default_numeric_fallback)]
#![allow(unused)]
#![allow(clippy::never_loop)]
#![allow(clippy::no_effect)]
#![allow(clippy::unnecessary_operation)]
fn concrete_arg(x: i32) {}
fn generic_arg<T>(t: T) {}
struct ConcreteStruct {
x: i32,
}
struct StructForMethodCallTest {
x: i32,
}
impl StructForMethodCallTest {
fn concrete_arg(&self, x: i32) {}
fn generic_arg<T>(&self, t: T) {}
}
2021-02-02 03:26:20 +00:00
fn main() {
let s = StructForMethodCallTest { x: 10_i32 };
2021-02-02 03:26:20 +00:00
// Bad.
2021-02-07 09:00:08 +00:00
let x = 1;
let x = 0.1;
2021-02-07 09:00:08 +00:00
let x = if true { 1 } else { 2 };
2021-02-02 03:26:20 +00:00
let x: _ = {
let y = 1;
1
};
generic_arg(10);
s.generic_arg(10);
let x: _ = generic_arg(10);
let x: _ = s.generic_arg(10);
2021-02-02 03:26:20 +00:00
// Good.
2021-02-07 09:00:08 +00:00
let x = 1_i32;
let x: i32 = 1;
let x: _ = 1;
let x = 0.1_f64;
let x: f64 = 0.1;
let x: _ = 0.1;
2021-02-07 09:00:08 +00:00
let x: _ = if true { 1 } else { 2 };
concrete_arg(10);
s.concrete_arg(10);
let x = concrete_arg(10);
let x = s.concrete_arg(10);
2021-02-02 03:26:20 +00:00
}