From a0eb83a5d4e0a175933e22d21df1f6ad6251e88a Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 18 Jul 2022 21:27:20 -0700 Subject: [PATCH] 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 --- test_suite/tests/test_ser.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/test_suite/tests/test_ser.rs b/test_suite/tests/test_ser.rs index 5c8ef4640..003cdb5f0 100644 --- a/test_suite/tests/test_ser.rs +++ b/test_suite/tests/test_ser.rs @@ -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]