]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/invalid_utf8_in_unchecked.rs
Rollup merge of #102764 - compiler-errors:issue-102762, r=jackh726
[rust.git] / src / tools / clippy / tests / ui / invalid_utf8_in_unchecked.rs
1 #![warn(clippy::invalid_utf8_in_unchecked)]
2
3 fn main() {
4     // Valid
5     unsafe {
6         std::str::from_utf8_unchecked(&[99, 108, 105, 112, 112, 121]);
7         std::str::from_utf8_unchecked(&[b'c', b'l', b'i', b'p', b'p', b'y']);
8         std::str::from_utf8_unchecked(b"clippy");
9
10         let x = 0xA0;
11         std::str::from_utf8_unchecked(&[0xC0, x]);
12     }
13
14     // Invalid
15     unsafe {
16         std::str::from_utf8_unchecked(&[99, 108, 130, 105, 112, 112, 121]);
17         std::str::from_utf8_unchecked(&[b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']);
18         std::str::from_utf8_unchecked(b"cl\x82ippy");
19     }
20 }