Skip to content

Commit

Permalink
Resolve invalid_utf8_in_unchecked clippy lint in ancient test code
Browse files Browse the repository at this point in the history
    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
  • Loading branch information
dtolnay committed Jul 19, 2022
1 parent 7cc6f7f commit a0eb83a
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions test_suite/tests/test_ser.rs
Expand Up @@ -800,17 +800,14 @@ fn test_never_result() {
#[test]
#[cfg(unix)]
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(
&Path::new(path),
&Path::new(OsStr::from_bytes(b"Hello \xF0\x90\x80World")),
&[],
"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]
Expand Down

0 comments on commit a0eb83a

Please sign in to comment.