Resolve invalid_utf8_in_unchecked clippy lint in ancient test code

error: non UTF-8 literal in `std::str::from_utf8_unchecked`
       --> test_suite/tests/test_ser.rs:803:25
        |
    803 |     let path = unsafe { str::from_utf8_unchecked(b"Hello \xF0\x90\x80World") };
        |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = note: `-D clippy::invalid-utf8-in-unchecked` implied by `-D clippy::all`
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#invalid_utf8_in_unchecked
This commit is contained in:
David Tolnay 2022-07-18 21:27:20 -07:00
parent 7cc6f7fbb0
commit a0eb83a5d4
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -800,17 +800,14 @@ fn test_never_result() {
#[test] #[test]
#[cfg(unix)] #[cfg(unix)]
fn test_cannot_serialize_paths() { fn test_cannot_serialize_paths() {
let path = unsafe { str::from_utf8_unchecked(b"Hello \xF0\x90\x80World") }; use std::ffi::OsStr;
use std::os::unix::ffi::OsStrExt;
assert_ser_tokens_error( assert_ser_tokens_error(
&Path::new(path), &Path::new(OsStr::from_bytes(b"Hello \xF0\x90\x80World")),
&[], &[],
"path contains invalid UTF-8 characters", "path contains invalid UTF-8 characters",
); );
let mut path_buf = PathBuf::new();
path_buf.push(path);
assert_ser_tokens_error(&path_buf, &[], "path contains invalid UTF-8 characters");
} }
#[test] #[test]