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

fn main() {
    unsafe {
        let s = "💅";
        #[cfg(range)]
        s.get_unchecked(4..5);
        #[cfg(range_to)]
        s.get_unchecked(..5);
        #[cfg(range_from)]
        s.get_unchecked(5..);
        #[cfg(backwards_range)]
        s.get_unchecked(1..0);
    }
}