summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/invalid_utf8_in_unchecked.rs
blob: 3dc096d3197fbe5eba20a5ca73b5a65d72739c7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#![warn(clippy::invalid_utf8_in_unchecked)]

fn main() {
    // Valid
    unsafe {
        std::str::from_utf8_unchecked(&[99, 108, 105, 112, 112, 121]);
        std::str::from_utf8_unchecked(&[b'c', b'l', b'i', b'p', b'p', b'y']);
        std::str::from_utf8_unchecked(b"clippy");

        let x = 0xA0;
        std::str::from_utf8_unchecked(&[0xC0, x]);
    }

    // Invalid
    unsafe {
        std::str::from_utf8_unchecked(&[99, 108, 130, 105, 112, 112, 121]);
        std::str::from_utf8_unchecked(&[b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']);
        std::str::from_utf8_unchecked(b"cl\x82ippy");
    }
}