diff options
| author | Oli Scherer <github333195615777966@oli-obk.de> | 2025-07-11 08:37:09 +0000 |
|---|---|---|
| committer | Oli Scherer <github333195615777966@oli-obk.de> | 2025-07-15 07:58:29 +0000 |
| commit | cb7d52f6430922b5ffd29073f6605b19b80e7f36 (patch) | |
| tree | fdf2a27e0f7af1859fe8fc6085be439856cb171e /tests | |
| parent | b5230e53604f1227a087397e561e1cd2329f59b6 (diff) | |
| download | rust-cb7d52f6430922b5ffd29073f6605b19b80e7f36.tar.gz rust-cb7d52f6430922b5ffd29073f6605b19b80e7f36.zip | |
constify some methods using `SliceIndex`
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/consts/const-eval/ub-slice-get-unchecked.rs | 3 | ||||
| -rw-r--r-- | tests/ui/consts/const-eval/ub-slice-get-unchecked.stderr | 12 |
2 files changed, 8 insertions, 7 deletions
diff --git a/tests/ui/consts/const-eval/ub-slice-get-unchecked.rs b/tests/ui/consts/const-eval/ub-slice-get-unchecked.rs index e805ac01c9d..ad2b49e6049 100644 --- a/tests/ui/consts/const-eval/ub-slice-get-unchecked.rs +++ b/tests/ui/consts/const-eval/ub-slice-get-unchecked.rs @@ -1,9 +1,10 @@ -//@ known-bug: #110395 +#![feature(const_index, const_trait_impl)] const A: [(); 5] = [(), (), (), (), ()]; // Since the indexing is on a ZST, the addresses are all fine, // but we should still catch the bad range. const B: &[()] = unsafe { A.get_unchecked(3..1) }; +//~^ ERROR: slice::get_unchecked requires that the range is within the slice fn main() {} diff --git a/tests/ui/consts/const-eval/ub-slice-get-unchecked.stderr b/tests/ui/consts/const-eval/ub-slice-get-unchecked.stderr index 6e428079afe..88ea310f19c 100644 --- a/tests/ui/consts/const-eval/ub-slice-get-unchecked.stderr +++ b/tests/ui/consts/const-eval/ub-slice-get-unchecked.stderr @@ -1,11 +1,11 @@ -error[E0015]: cannot call non-const method `core::slice::<impl [()]>::get_unchecked::<std::ops::Range<usize>>` in constants - --> $DIR/ub-slice-get-unchecked.rs:7:29 +error[E0080]: evaluation panicked: unsafe precondition(s) violated: slice::get_unchecked requires that the range is within the slice + + This indicates a bug in the program. This Undefined Behavior check is optional, and cannot be relied on for safety. + --> $DIR/ub-slice-get-unchecked.rs:7:27 | LL | const B: &[()] = unsafe { A.get_unchecked(3..1) }; - | ^^^^^^^^^^^^^^^^^^^ - | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants + | ^^^^^^^^^^^^^^^^^^^^^ evaluation of `B` failed here error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0015`. +For more information about this error, try `rustc --explain E0080`. |
