diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2025-05-14 23:29:17 +0200 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2025-05-14 23:38:37 +0200 |
| commit | fe4b4e832941b554b802b5ea2bbbe95806c093fe (patch) | |
| tree | b1ff73aa1446fde367eddd27165953c9edaf982a /tests | |
| parent | 4ec219393a48eff84c8c08b854d50a454b8f422c (diff) | |
| download | rust-fe4b4e832941b554b802b5ea2bbbe95806c093fe.tar.gz rust-fe4b4e832941b554b802b5ea2bbbe95806c093fe.zip | |
`mem::size_of_val` is const-stable since Rust 1.85
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/manual_slice_size_calculation.fixed | 12 | ||||
| -rw-r--r-- | tests/ui/manual_slice_size_calculation.rs | 12 | ||||
| -rw-r--r-- | tests/ui/manual_slice_size_calculation.stderr | 10 |
3 files changed, 26 insertions, 8 deletions
diff --git a/tests/ui/manual_slice_size_calculation.fixed b/tests/ui/manual_slice_size_calculation.fixed index 9df5a2ac5cd..090f0fd30c5 100644 --- a/tests/ui/manual_slice_size_calculation.fixed +++ b/tests/ui/manual_slice_size_calculation.fixed @@ -60,9 +60,15 @@ fn main() { 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 +#[clippy::msrv = "1.85"] +const fn const_ok(s_i32: &[i32]) { + let _ = std::mem::size_of_val(s_i32); + //~^ manual_slice_size_calculation +} + +#[clippy::msrv = "1.84"] +const fn const_before_msrv(s_i32: &[i32]) { + let _ = s_i32.len() * size_of::<i32>(); } fn issue_14802() { diff --git a/tests/ui/manual_slice_size_calculation.rs b/tests/ui/manual_slice_size_calculation.rs index db14d891c80..3c19a0eb5ce 100644 --- a/tests/ui/manual_slice_size_calculation.rs +++ b/tests/ui/manual_slice_size_calculation.rs @@ -60,9 +60,15 @@ fn main() { 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 +#[clippy::msrv = "1.85"] +const fn const_ok(s_i32: &[i32]) { + let _ = s_i32.len() * size_of::<i32>(); + //~^ manual_slice_size_calculation +} + +#[clippy::msrv = "1.84"] +const fn const_before_msrv(s_i32: &[i32]) { + let _ = s_i32.len() * size_of::<i32>(); } fn issue_14802() { diff --git a/tests/ui/manual_slice_size_calculation.stderr b/tests/ui/manual_slice_size_calculation.stderr index 00eb32b3e1c..8e9b49e4bf2 100644 --- a/tests/ui/manual_slice_size_calculation.stderr +++ b/tests/ui/manual_slice_size_calculation.stderr @@ -56,10 +56,16 @@ LL | let _ = external!(&[1u64][..]).len() * size_of::<u64>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(external!(&[1u64][..]))` error: manual slice size calculation - --> tests/ui/manual_slice_size_calculation.rs:75:13 + --> tests/ui/manual_slice_size_calculation.rs:65:13 + | +LL | let _ = s_i32.len() * size_of::<i32>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` + +error: manual slice size calculation + --> tests/ui/manual_slice_size_calculation.rs:81:13 | LL | self.dst.len() * size_of::<u8>() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(&self.dst)` -error: aborting due to 10 previous errors +error: aborting due to 11 previous errors |
