about summary refs log tree commit diff
path: root/tests/ui/precondition-checks/slice-get_unchecked.rs
blob: 7bcb8442540a4ceaf5e4aafcb45468cae6f01d6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//@ run-crash
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
//@ error-pattern: unsafe precondition(s) violated: slice::get_unchecked requires
//@ revisions: usize range range_to range_from backwards_range

fn main() {
    unsafe {
        let s = &[0];
        #[cfg(usize)]
        s.get_unchecked(1);
        #[cfg(range)]
        s.get_unchecked(1..2);
        #[cfg(range_to)]
        s.get_unchecked(..2);
        #[cfg(range_from)]
        s.get_unchecked(2..);
        #[cfg(backwards_range)]
        s.get_unchecked(1..0);
     }
}