2023-12-10 22:46:25 +00:00
|
|
|
#![warn(clippy::zero_repeat_side_effects)]
|
|
|
|
#![allow(clippy::unnecessary_operation)]
|
|
|
|
#![allow(clippy::useless_vec)]
|
|
|
|
#![allow(clippy::needless_late_init)]
|
|
|
|
|
|
|
|
fn f() -> i32 {
|
|
|
|
println!("side effect");
|
|
|
|
10
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
const N: usize = 0;
|
|
|
|
const M: usize = 1;
|
|
|
|
|
|
|
|
// should trigger
|
|
|
|
|
|
|
|
// on arrays
|
|
|
|
f(); let a: [i32; 0] = [];
|
|
|
|
let mut b;
|
|
|
|
f(); b = [] as [i32; 0];
|
|
|
|
|
|
|
|
// on vecs
|
2024-07-20 05:50:36 +00:00
|
|
|
// vecs dont support inferring value of consts
|
2023-12-10 22:46:25 +00:00
|
|
|
f(); let c: std::vec::Vec<i32> = vec![];
|
|
|
|
let d;
|
|
|
|
f(); d = vec![] as std::vec::Vec<i32>;
|
|
|
|
|
|
|
|
// for macros
|
|
|
|
println!("side effect"); let e: [(); 0] = [];
|
|
|
|
|
|
|
|
// for nested calls
|
|
|
|
{ f() }; let g: [i32; 0] = [];
|
|
|
|
|
|
|
|
// as function param
|
|
|
|
drop({ f(); vec![] as std::vec::Vec<i32> });
|
|
|
|
|
|
|
|
// when singled out/not part of assignment/local
|
|
|
|
{ f(); vec![] as std::vec::Vec<i32> };
|
|
|
|
{ f(); [] as [i32; 0] };
|
|
|
|
|
|
|
|
// should not trigger
|
2024-07-18 05:22:08 +00:00
|
|
|
let a = [f(); N];
|
|
|
|
b = [f(); N];
|
|
|
|
[f(); N];
|
2023-12-10 22:46:25 +00:00
|
|
|
|
|
|
|
// on arrays with > 0 repeat
|
|
|
|
let a = [f(); 1];
|
|
|
|
let a = [f(); M];
|
|
|
|
let mut b;
|
|
|
|
b = [f(); 1];
|
|
|
|
b = [f(); M];
|
|
|
|
|
|
|
|
// on vecs with > 0 repeat
|
|
|
|
let c = vec![f(); 1];
|
|
|
|
let d;
|
|
|
|
d = vec![f(); 1];
|
|
|
|
|
|
|
|
// as function param
|
|
|
|
drop(vec![f(); 1]);
|
|
|
|
}
|
2024-07-17 11:23:40 +00:00
|
|
|
|
|
|
|
macro_rules! LEN {
|
2024-07-17 11:27:42 +00:00
|
|
|
() => {
|
|
|
|
0
|
|
|
|
};
|
2024-07-17 11:23:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn issue_13110() {
|
2024-07-17 11:27:42 +00:00
|
|
|
let _data = [f(); LEN!()];
|
2024-07-17 11:23:40 +00:00
|
|
|
const LENGTH: usize = LEN!();
|
2024-07-17 11:27:42 +00:00
|
|
|
let _data = [f(); LENGTH];
|
2024-07-17 11:23:40 +00:00
|
|
|
}
|