2023-07-27 08:23:04 -05:00
|
|
|
//@aux-build:proc_macros.rs
|
2023-04-17 13:43:16 -05:00
|
|
|
#![allow(unused)]
|
|
|
|
#![warn(clippy::manual_slice_size_calculation)]
|
|
|
|
|
2023-04-18 12:54:26 -05:00
|
|
|
extern crate proc_macros;
|
|
|
|
|
2023-04-17 13:43:16 -05:00
|
|
|
use core::mem::{align_of, size_of};
|
2023-04-18 12:54:26 -05:00
|
|
|
use proc_macros::external;
|
2023-04-17 13:43:16 -05:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let v_i32 = Vec::<i32>::new();
|
|
|
|
let s_i32 = v_i32.as_slice();
|
2024-10-02 10:51:52 -05:00
|
|
|
let s_i32_ref = &s_i32;
|
|
|
|
let s_i32_ref_ref = &s_i32_ref;
|
2023-04-17 13:43:16 -05:00
|
|
|
|
|
|
|
// True positives:
|
|
|
|
let _ = std::mem::size_of_val(s_i32); // WARNING
|
|
|
|
let _ = std::mem::size_of_val(s_i32); // WARNING
|
|
|
|
let _ = std::mem::size_of_val(s_i32) * 5; // WARNING
|
2024-10-02 10:51:52 -05:00
|
|
|
let _ = std::mem::size_of_val(*s_i32_ref); // WARNING
|
|
|
|
let _ = std::mem::size_of_val(**s_i32_ref_ref); // WARNING
|
2023-04-17 13:43:16 -05:00
|
|
|
|
|
|
|
let len = s_i32.len();
|
|
|
|
let size = size_of::<i32>();
|
|
|
|
let _ = std::mem::size_of_val(s_i32); // WARNING
|
|
|
|
let _ = std::mem::size_of_val(s_i32); // WARNING
|
|
|
|
let _ = std::mem::size_of_val(s_i32); // WARNING
|
|
|
|
|
2023-04-18 12:54:26 -05:00
|
|
|
let _ = std::mem::size_of_val(external!(&[1u64][..]));
|
|
|
|
|
2023-04-17 13:43:16 -05:00
|
|
|
// True negatives:
|
|
|
|
let _ = size_of::<i32>() + s_i32.len(); // Ok, not a multiplication
|
|
|
|
let _ = size_of::<i32>() * s_i32.partition_point(|_| true); // Ok, not len()
|
|
|
|
let _ = size_of::<i32>() * v_i32.len(); // Ok, not a slice
|
|
|
|
let _ = align_of::<i32>() * s_i32.len(); // Ok, not size_of()
|
|
|
|
let _ = size_of::<u32>() * s_i32.len(); // Ok, different types
|
|
|
|
|
2023-04-18 12:54:26 -05:00
|
|
|
let _ = external!($s_i32.len() * size_of::<i32>());
|
|
|
|
let _ = external!($s_i32.len()) * size_of::<i32>();
|
|
|
|
|
2023-04-17 13:43:16 -05:00
|
|
|
// False negatives:
|
|
|
|
let _ = 5 * size_of::<i32>() * s_i32.len(); // Ok (MISSED OPPORTUNITY)
|
|
|
|
let _ = size_of::<i32>() * 5 * s_i32.len(); // Ok (MISSED OPPORTUNITY)
|
|
|
|
}
|
|
|
|
|
|
|
|
const fn _const(s_i32: &[i32]) {
|
|
|
|
// True negative:
|
|
|
|
let _ = s_i32.len() * size_of::<i32>(); // Ok, can't use size_of_val in const
|
|
|
|
}
|