Closed
Description
rust/library/std/src/sys_common/wtf8.rs
Lines 136 to 146 in ebcb862
rust/library/std/src/sys_common/wtf8.rs
Lines 479 to 481 in ebcb862
I tried this code:
use std::{ffi::OsString, os::windows::ffi::OsStringExt, path::PathBuf};
fn f() -> Result<String, OsString> {
let mut utf8 = PathBuf::from(OsString::from("utf8".to_owned()));
let non_utf8: OsString = OsStringExt::from_wide(&[0x6e, 0x6f, 0x6e, 0xd800, 0x75, 0x74, 0x66, 0x38]);
utf8.set_extension(&non_utf8);
utf8.into_os_string().into_string()
}
fn main() {
dbg!(f());
}
I expected to see this happen:
[1.rs:11:5] f() = Err(
"utf8.non\xED\xA0\x80utf8",
)
Instead, this happened:
[1.rs:11:5] f() = Ok(
"utf8.non\u{d800}utf8",
)
(Obviously, String
s can't contain \u{d800}
.)

Meta
rustc --version --verbose
:
rustc 1.81.0-nightly (d0227c6a1 2024-06-11)
binary: rustc
commit-hash: d0227c6a19c2d6e8dceb87c7a2776dc2b10d2a04
commit-date: 2024-06-11
host: x86_64-pc-windows-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7