From 4a2eeae4ce9d227866e211c360ad09a87f221b74 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 31 Jan 2023 20:55:19 +0000 Subject: [PATCH 1/2] Add `PathLike` trait Replace `AsRef` with a `PathLike` trait. --- library/std/src/env.rs | 8 ++- library/std/src/fs.rs | 102 ++++++++++++++-------------- library/std/src/os/unix/ffi/mod.rs | 19 ++++++ library/std/src/os/windows/ffi.rs | 17 +++++ library/std/src/path.rs | 61 ++++++++++++++++- library/std/src/sys/unix/fs.rs | 6 +- library/std/src/sys/unix/path.rs | 13 +++- library/std/src/sys/windows/fs.rs | 10 ++- library/std/src/sys/windows/path.rs | 16 +++++ 9 files changed, 190 insertions(+), 62 deletions(-) diff --git a/library/std/src/env.rs b/library/std/src/env.rs index 183f9ab3b08f6..7d2d592d6597e 100644 --- a/library/std/src/env.rs +++ b/library/std/src/env.rs @@ -17,7 +17,9 @@ use crate::error::Error; use crate::ffi::{OsStr, OsString}; use crate::fmt; use crate::io; -use crate::path::{Path, PathBuf}; +#[cfg(doc)] +use crate::path::Path; +use crate::path::{PathBuf, PathLike}; use crate::sys; use crate::sys::os as os_imp; @@ -80,8 +82,8 @@ pub fn current_dir() -> io::Result { /// ``` #[doc(alias = "chdir")] #[stable(feature = "env", since = "1.0.0")] -pub fn set_current_dir>(path: P) -> io::Result<()> { - os_imp::chdir(path.as_ref()) +pub fn set_current_dir(path: P) -> io::Result<()> { + path.with_path(os_imp::chdir) } /// An iterator over a snapshot of the environment variables of this process. diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index c550378e7d6b7..1cb23cc51c482 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -14,7 +14,7 @@ mod tests; use crate::ffi::OsString; use crate::fmt; use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write}; -use crate::path::{Path, PathBuf}; +use crate::path::{NativePath, Path, PathBuf, PathLike}; use crate::sys::fs as fs_imp; use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner}; use crate::time::SystemTime; @@ -246,7 +246,7 @@ pub struct DirBuilder { /// } /// ``` #[stable(feature = "fs_read_write_bytes", since = "1.26.0")] -pub fn read>(path: P) -> io::Result> { +pub fn read(path: P) -> io::Result> { fn inner(path: &Path) -> io::Result> { let mut file = File::open(path)?; let size = file.metadata().map(|m| m.len()).unwrap_or(0); @@ -254,7 +254,7 @@ pub fn read>(path: P) -> io::Result> { io::default_read_to_end(&mut file, &mut bytes)?; Ok(bytes) } - inner(path.as_ref()) + path.with_path(inner) } /// Read the entire contents of a file into a string. @@ -286,7 +286,7 @@ pub fn read>(path: P) -> io::Result> { /// } /// ``` #[stable(feature = "fs_read_write", since = "1.26.0")] -pub fn read_to_string>(path: P) -> io::Result { +pub fn read_to_string(path: P) -> io::Result { fn inner(path: &Path) -> io::Result { let mut file = File::open(path)?; let size = file.metadata().map(|m| m.len()).unwrap_or(0); @@ -294,7 +294,7 @@ pub fn read_to_string>(path: P) -> io::Result { io::default_read_to_string(&mut file, &mut string)?; Ok(string) } - inner(path.as_ref()) + path.with_path(inner) } /// Write a slice as the entire contents of a file. @@ -322,11 +322,11 @@ pub fn read_to_string>(path: P) -> io::Result { /// } /// ``` #[stable(feature = "fs_read_write_bytes", since = "1.26.0")] -pub fn write, C: AsRef<[u8]>>(path: P, contents: C) -> io::Result<()> { +pub fn write>(path: P, contents: C) -> io::Result<()> { fn inner(path: &Path, contents: &[u8]) -> io::Result<()> { File::create(path)?.write_all(contents) } - inner(path.as_ref(), contents.as_ref()) + path.with_path(|path| inner(path.as_ref(), contents.as_ref())) } impl File { @@ -357,8 +357,8 @@ impl File { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn open>(path: P) -> io::Result { - OpenOptions::new().read(true).open(path.as_ref()) + pub fn open(path: P) -> io::Result { + OpenOptions::new().read(true).open(path) } /// Opens a file in write-only mode. @@ -386,8 +386,8 @@ impl File { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn create>(path: P) -> io::Result { - OpenOptions::new().write(true).create(true).truncate(true).open(path.as_ref()) + pub fn create(path: P) -> io::Result { + OpenOptions::new().write(true).create(true).truncate(true).open(path) } /// Creates a new file in read-write mode; error if the file exists. @@ -417,8 +417,8 @@ impl File { /// } /// ``` #[unstable(feature = "file_create_new", issue = "105135")] - pub fn create_new>(path: P) -> io::Result { - OpenOptions::new().read(true).write(true).create_new(true).open(path.as_ref()) + pub fn create_new(path: P) -> io::Result { + OpenOptions::new().read(true).write(true).create_new(true).open(path) } /// Returns a new OpenOptions object. @@ -1073,12 +1073,12 @@ impl OpenOptions { /// [`NotFound`]: io::ErrorKind::NotFound /// [`PermissionDenied`]: io::ErrorKind::PermissionDenied #[stable(feature = "rust1", since = "1.0.0")] - pub fn open>(&self, path: P) -> io::Result { - self._open(path.as_ref()) + pub fn open(&self, path: P) -> io::Result { + path.with_native_path(|path| self._open(path)) } - fn _open(&self, path: &Path) -> io::Result { - fs_imp::File::open(path, &self.0).map(|inner| File { inner }) + fn _open(&self, path: &NativePath) -> io::Result { + fs_imp::File::open_native(path, &self.0).map(|inner| File { inner }) } } @@ -1805,8 +1805,8 @@ impl AsInner for DirEntry { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] -pub fn remove_file>(path: P) -> io::Result<()> { - fs_imp::unlink(path.as_ref()) +pub fn remove_file(path: P) -> io::Result<()> { + path.with_path(fs_imp::unlink) } /// Given a path, query the file system to get information about a file, @@ -1843,8 +1843,8 @@ pub fn remove_file>(path: P) -> io::Result<()> { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] -pub fn metadata>(path: P) -> io::Result { - fs_imp::stat(path.as_ref()).map(Metadata) +pub fn metadata(path: P) -> io::Result { + path.with_path(fs_imp::stat).map(Metadata) } /// Query the metadata about a file without following symlinks. @@ -1877,8 +1877,8 @@ pub fn metadata>(path: P) -> io::Result { /// } /// ``` #[stable(feature = "symlink_metadata", since = "1.1.0")] -pub fn symlink_metadata>(path: P) -> io::Result { - fs_imp::lstat(path.as_ref()).map(Metadata) +pub fn symlink_metadata(path: P) -> io::Result { + path.with_path(fs_imp::lstat).map(Metadata) } /// Rename a file or directory to a new name, replacing the original file if @@ -1920,8 +1920,8 @@ pub fn symlink_metadata>(path: P) -> io::Result { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] -pub fn rename, Q: AsRef>(from: P, to: Q) -> io::Result<()> { - fs_imp::rename(from.as_ref(), to.as_ref()) +pub fn rename(from: P, to: Q) -> io::Result<()> { + from.with_path(|from| to.with_path(|to| fs_imp::rename(from, to))) } /// Copies the contents of one file to another. This function will also @@ -1978,8 +1978,8 @@ pub fn rename, Q: AsRef>(from: P, to: Q) -> io::Result<()> /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] -pub fn copy, Q: AsRef>(from: P, to: Q) -> io::Result { - fs_imp::copy(from.as_ref(), to.as_ref()) +pub fn copy(from: P, to: Q) -> io::Result { + from.with_path(|from| to.with_path(|to| fs_imp::copy(from, to))) } /// Creates a new hard link on the filesystem. @@ -2022,8 +2022,8 @@ pub fn copy, Q: AsRef>(from: P, to: Q) -> io::Result { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] -pub fn hard_link, Q: AsRef>(original: P, link: Q) -> io::Result<()> { - fs_imp::link(original.as_ref(), link.as_ref()) +pub fn hard_link(original: P, link: Q) -> io::Result<()> { + original.with_path(|original| link.with_path(|link| fs_imp::link(original, link))) } /// Creates a new symbolic link on the filesystem. @@ -2054,8 +2054,8 @@ pub fn hard_link, Q: AsRef>(original: P, link: Q) -> io::Re note = "replaced with std::os::unix::fs::symlink and \ std::os::windows::fs::{symlink_file, symlink_dir}" )] -pub fn soft_link, Q: AsRef>(original: P, link: Q) -> io::Result<()> { - fs_imp::symlink(original.as_ref(), link.as_ref()) +pub fn soft_link(original: P, link: Q) -> io::Result<()> { + original.with_path(|original| link.with_path(|link| fs_imp::symlink(original, link))) } /// Reads a symbolic link, returning the file that the link points to. @@ -2088,8 +2088,8 @@ pub fn soft_link, Q: AsRef>(original: P, link: Q) -> io::Re /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] -pub fn read_link>(path: P) -> io::Result { - fs_imp::readlink(path.as_ref()) +pub fn read_link(path: P) -> io::Result { + path.with_path(fs_imp::readlink) } /// Returns the canonical, absolute form of a path with all intermediate @@ -2131,8 +2131,8 @@ pub fn read_link>(path: P) -> io::Result { #[doc(alias = "realpath")] #[doc(alias = "GetFinalPathNameByHandle")] #[stable(feature = "fs_canonicalize", since = "1.5.0")] -pub fn canonicalize>(path: P) -> io::Result { - fs_imp::canonicalize(path.as_ref()) +pub fn canonicalize(path: P) -> io::Result { + path.with_path(fs_imp::canonicalize) } /// Creates a new, empty directory at the provided path @@ -2172,8 +2172,8 @@ pub fn canonicalize>(path: P) -> io::Result { /// ``` #[doc(alias = "mkdir")] #[stable(feature = "rust1", since = "1.0.0")] -pub fn create_dir>(path: P) -> io::Result<()> { - DirBuilder::new().create(path.as_ref()) +pub fn create_dir(path: P) -> io::Result<()> { + DirBuilder::new().create(path) } /// Recursively create a directory and all of its parent components if they @@ -2216,8 +2216,8 @@ pub fn create_dir>(path: P) -> io::Result<()> { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] -pub fn create_dir_all>(path: P) -> io::Result<()> { - DirBuilder::new().recursive(true).create(path.as_ref()) +pub fn create_dir_all(path: P) -> io::Result<()> { + DirBuilder::new().recursive(true).create(path) } /// Removes an empty directory. @@ -2252,8 +2252,8 @@ pub fn create_dir_all>(path: P) -> io::Result<()> { /// ``` #[doc(alias = "rmdir")] #[stable(feature = "rust1", since = "1.0.0")] -pub fn remove_dir>(path: P) -> io::Result<()> { - fs_imp::rmdir(path.as_ref()) +pub fn remove_dir(path: P) -> io::Result<()> { + path.with_path(fs_imp::rmdir) } /// Removes a directory at this path, after removing all its contents. Use @@ -2294,8 +2294,8 @@ pub fn remove_dir>(path: P) -> io::Result<()> { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] -pub fn remove_dir_all>(path: P) -> io::Result<()> { - fs_imp::remove_dir_all(path.as_ref()) +pub fn remove_dir_all(path: P) -> io::Result<()> { + path.with_path(fs_imp::remove_dir_all) } /// Returns an iterator over the entries within a directory. @@ -2369,8 +2369,8 @@ pub fn remove_dir_all>(path: P) -> io::Result<()> { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] -pub fn read_dir>(path: P) -> io::Result { - fs_imp::readdir(path.as_ref()).map(ReadDir) +pub fn read_dir(path: P) -> io::Result { + path.with_path(fs_imp::readdir).map(ReadDir) } /// Changes the permissions found on a file or a directory. @@ -2404,8 +2404,8 @@ pub fn read_dir>(path: P) -> io::Result { /// } /// ``` #[stable(feature = "set_permissions", since = "1.1.0")] -pub fn set_permissions>(path: P, perm: Permissions) -> io::Result<()> { - fs_imp::set_perm(path.as_ref(), perm.0) +pub fn set_permissions(path: P, perm: Permissions) -> io::Result<()> { + path.with_path(|path| fs_imp::set_perm(path, perm.0)) } impl DirBuilder { @@ -2464,8 +2464,8 @@ impl DirBuilder { /// assert!(fs::metadata(path).unwrap().is_dir()); /// ``` #[stable(feature = "dir_builder", since = "1.6.0")] - pub fn create>(&self, path: P) -> io::Result<()> { - self._create(path.as_ref()) + pub fn create(&self, path: P) -> io::Result<()> { + path.with_path(|path| self._create(path)) } fn _create(&self, path: &Path) -> io::Result<()> { @@ -2534,6 +2534,6 @@ impl AsInnerMut for DirBuilder { // instead. #[unstable(feature = "fs_try_exists", issue = "83186")] #[inline] -pub fn try_exists>(path: P) -> io::Result { - fs_imp::try_exists(path.as_ref()) +pub fn try_exists(path: P) -> io::Result { + path.with_path(fs_imp::try_exists) } diff --git a/library/std/src/os/unix/ffi/mod.rs b/library/std/src/os/unix/ffi/mod.rs index 5b49f50763d74..ab726585c9230 100644 --- a/library/std/src/os/unix/ffi/mod.rs +++ b/library/std/src/os/unix/ffi/mod.rs @@ -38,5 +38,24 @@ mod os_str; +use crate::ffi::CStr; +use crate::path::NativePath; + #[stable(feature = "rust1", since = "1.0.0")] pub use self::os_str::{OsStrExt, OsStringExt}; + +#[unstable(feature = "pathlike", issue = "none")] +pub trait NativePathExt: crate::sealed::Sealed { + fn from_cstr(cstr: &CStr) -> &NativePath; + fn into_cstr(&self) -> &CStr; +} + +#[unstable(feature = "pathlike", issue = "none")] +impl NativePathExt for NativePath { + fn from_cstr(cstr: &CStr) -> &NativePath { + unsafe { &*(cstr as *const CStr as *const NativePath) } + } + fn into_cstr(&self) -> &CStr { + unsafe { &*(self as *const Self as *const CStr) } + } +} diff --git a/library/std/src/os/windows/ffi.rs b/library/std/src/os/windows/ffi.rs index 96bab59d3f8d7..25329c2f340b4 100644 --- a/library/std/src/os/windows/ffi.rs +++ b/library/std/src/os/windows/ffi.rs @@ -54,6 +54,7 @@ #![stable(feature = "rust1", since = "1.0.0")] use crate::ffi::{OsStr, OsString}; +use crate::path::NativePath; use crate::sealed::Sealed; use crate::sys::os_str::Buf; use crate::sys_common::wtf8::Wtf8Buf; @@ -134,3 +135,19 @@ impl OsStrExt for OsStr { self.as_inner().inner.encode_wide() } } + +#[unstable(feature = "pathlike", issue = "none")] +pub trait NativePathExt: Sealed { + fn from_wide(wide: &[u16]) -> &NativePath; + fn into_wide(&self) -> &[u16]; +} +#[unstable(feature = "pathlike", issue = "none")] +impl NativePathExt for NativePath { + fn from_wide(wide: &[u16]) -> &NativePath { + assert_eq!(wide.last(), Some(&0)); + unsafe { &*(wide as *const [u16] as *const Self) } + } + fn into_wide(&self) -> &[u16] { + unsafe { &*(self as *const Self as *const [u16]) } + } +} diff --git a/library/std/src/path.rs b/library/std/src/path.rs index cd6b393a2eaf5..f462ae9f9b685 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -86,7 +86,9 @@ use crate::sync::Arc; use crate::ffi::{OsStr, OsString}; use crate::sys; -use crate::sys::path::{is_sep_byte, is_verbatim_sep, parse_prefix, MAIN_SEP_STR}; +use crate::sys::path::{ + is_sep_byte, is_verbatim_sep, parse_prefix, NativePath as NativePathImpl, MAIN_SEP_STR, +}; //////////////////////////////////////////////////////////////////////////////// // GENERAL NOTES @@ -1109,6 +1111,63 @@ impl FusedIterator for Ancestors<'_> {} // Basic types and traits //////////////////////////////////////////////////////////////////////////////// +/// Represents a path in a form native to the OS. +#[derive(Debug)] +#[repr(transparent)] +#[unstable(feature = "path_like", issue = "none")] +pub struct NativePath(pub(crate) NativePathImpl); +impl NativePath { + fn new(native: &NativePathImpl) -> &Self { + unsafe { &*(native as *const NativePathImpl as *const Self) } + } +} + +/// # Stable use +/// +/// Any function that requires a path may take a `PathLike` type. +/// +/// These types include [`OsStr`], [`Path`] and [`str`] as well as their owned +/// counterparts [`OsString`], [`PathBuf`] and [`String`]. +/// +/// # Unstable use +/// +/// The `PathLike` trait can also be used with [`NativePath`] to pass platform +/// native paths more directly to system APIs without needing to convert them. +/// Note that this trait is unstable and highly likely to change between nightly versions. +#[unstable(feature = "path_like", issue = "none")] +pub trait PathLike: crate::sealed::Sealed { + /// Convert to a `Path` reference. + fn with_path io::Result>(&self, f: F) -> io::Result; + /// Convert to the native platform representation of a path. + fn with_native_path io::Result>(&self, f: F) -> io::Result; +} +#[unstable(feature = "path_like", issue = "none")] +impl> PathLike for P { + fn with_path io::Result>(&self, f: F) -> io::Result { + f(self.as_ref()) + } + fn with_native_path io::Result>(&self, f: F) -> io::Result { + crate::sys::path::with_native_path(self.as_ref(), |p| f(NativePath::new(p))) + } +} + +#[unstable(feature = "path_like", issue = "none")] +impl PathLike for &NativePath { + fn with_path io::Result>(&self, f: F) -> io::Result { + crate::sys::path::with_std_path(&self.0, f) + } + fn with_native_path io::Result>(&self, f: F) -> io::Result { + f(self) + } +} + +#[unstable(feature = "sealed", issue = "none")] +impl> crate::sealed::Sealed for P {} +#[unstable(feature = "sealed", issue = "none")] +impl crate::sealed::Sealed for NativePath {} +#[unstable(feature = "sealed", issue = "none")] +impl crate::sealed::Sealed for &NativePath {} + /// An owned, mutable path (akin to [`String`]). /// /// This type provides methods like [`push`] and [`set_extension`] that mutate diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs index 8e1f35d6cc920..7e1cf436b4c2e 100644 --- a/library/std/src/sys/unix/fs.rs +++ b/library/std/src/sys/unix/fs.rs @@ -17,7 +17,7 @@ use crate::mem; ))] use crate::mem::MaybeUninit; use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd}; -use crate::path::{Path, PathBuf}; +use crate::path::{NativePath, Path, PathBuf}; use crate::ptr; use crate::sync::Arc; use crate::sys::common::small_c_string::run_path_with_cstr; @@ -988,8 +988,8 @@ impl OpenOptions { } impl File { - pub fn open(path: &Path, opts: &OpenOptions) -> io::Result { - run_path_with_cstr(path, |path| File::open_c(path, opts)) + pub fn open_native(path: &NativePath, opts: &OpenOptions) -> io::Result { + File::open_c(&path.0, opts) } pub fn open_c(path: &CStr, opts: &OpenOptions) -> io::Result { diff --git a/library/std/src/sys/unix/path.rs b/library/std/src/sys/unix/path.rs index a98a69e2db8e1..1ea0682526014 100644 --- a/library/std/src/sys/unix/path.rs +++ b/library/std/src/sys/unix/path.rs @@ -1,8 +1,19 @@ use crate::env; -use crate::ffi::OsStr; +use crate::ffi::{CStr, OsStr, OsString}; use crate::io; +use crate::os::unix::ffi::OsStringExt; use crate::path::{Path, PathBuf, Prefix}; +pub type NativePath = CStr; +pub use crate::sys::common::small_c_string::run_path_with_cstr as with_native_path; +pub fn with_std_path(path: &CStr, f: F) -> io::Result +where + F: FnOnce(&Path) -> io::Result, +{ + let path = PathBuf::from(OsString::from_vec(path.to_bytes().to_vec())); + f(&path) +} + #[inline] pub fn is_sep_byte(b: u8) -> bool { b == b'/' diff --git a/library/std/src/sys/windows/fs.rs b/library/std/src/sys/windows/fs.rs index d2c597664fa78..93291c711d61a 100644 --- a/library/std/src/sys/windows/fs.rs +++ b/library/std/src/sys/windows/fs.rs @@ -5,8 +5,9 @@ use crate::ffi::OsString; use crate::fmt; use crate::io::{self, BorrowedCursor, Error, IoSlice, IoSliceMut, SeekFrom}; use crate::mem::{self, MaybeUninit}; +use crate::os::windows::ffi::NativePathExt; use crate::os::windows::io::{AsHandle, BorrowedHandle}; -use crate::path::{Path, PathBuf}; +use crate::path::{NativePath, Path, PathBuf}; use crate::ptr; use crate::slice; use crate::sync::Arc; @@ -277,11 +278,14 @@ impl OpenOptions { } impl File { - pub fn open(path: &Path, opts: &OpenOptions) -> io::Result { + pub(super) fn open(path: &Path, opts: &OpenOptions) -> io::Result { let path = maybe_verbatim(path)?; + Self::open_native(NativePath::from_wide(&path), opts) + } + pub fn open_native(path: &NativePath, opts: &OpenOptions) -> io::Result { let handle = unsafe { c::CreateFileW( - path.as_ptr(), + path.0.as_ptr(), opts.get_access_mode()?, opts.share_mode, opts.security_attributes, diff --git a/library/std/src/sys/windows/path.rs b/library/std/src/sys/windows/path.rs index beeca1917a9af..55795117be08e 100644 --- a/library/std/src/sys/windows/path.rs +++ b/library/std/src/sys/windows/path.rs @@ -11,6 +11,22 @@ mod tests; pub const MAIN_SEP_STR: &str = "\\"; pub const MAIN_SEP: char = '\\'; +pub type NativePath = [u16]; +pub fn with_native_path(path: &Path, f: F) -> io::Result +where + F: FnOnce(&[u16]) -> io::Result, +{ + let path = maybe_verbatim(path)?; + f(&path) +} +pub fn with_std_path(path: &[u16], f: F) -> io::Result +where + F: FnOnce(&Path) -> io::Result, +{ + let path = super::os2path(path); + f(&path) +} + /// # Safety /// /// `bytes` must be a valid wtf8 encoded slice From d8db0353640375e88a939a60ff44eca5c4ceb821 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 28 Feb 2023 23:35:21 +0000 Subject: [PATCH 2/2] bless you --- .../miri/tests/fail/shims/fs/isolated_file.stderr | 12 +++++++----- tests/ui/async-await/issue-72442.stderr | 2 ++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/tools/miri/tests/fail/shims/fs/isolated_file.stderr b/src/tools/miri/tests/fail/shims/fs/isolated_file.stderr index 2385439c8a5f7..6e146119d163e 100644 --- a/src/tools/miri/tests/fail/shims/fs/isolated_file.stderr +++ b/src/tools/miri/tests/fail/shims/fs/isolated_file.stderr @@ -10,12 +10,14 @@ LL | let fd = cvt_r(|| unsafe { open64(path.as_ptr(), flags, opts.mode a = note: inside closure at RUSTLIB/std/src/sys/PLATFORM/fs.rs:LL:CC = note: inside `std::sys::PLATFORM::cvt_r::` at RUSTLIB/std/src/sys/PLATFORM/mod.rs:LL:CC = note: inside `std::sys::PLATFORM::fs::File::open_c` at RUSTLIB/std/src/sys/PLATFORM/fs.rs:LL:CC - = note: inside closure at RUSTLIB/std/src/sys/PLATFORM/fs.rs:LL:CC - = note: inside `std::sys::PLATFORM::small_c_string::run_with_cstr::` at RUSTLIB/std/src/sys/PLATFORM/small_c_string.rs:LL:CC - = note: inside `std::sys::PLATFORM::small_c_string::run_path_with_cstr::` at RUSTLIB/std/src/sys/PLATFORM/small_c_string.rs:LL:CC - = note: inside `std::sys::PLATFORM::fs::File::open` at RUSTLIB/std/src/sys/PLATFORM/fs.rs:LL:CC + = note: inside `std::sys::PLATFORM::fs::File::open_native` at RUSTLIB/std/src/sys/PLATFORM/fs.rs:LL:CC = note: inside `std::fs::OpenOptions::_open` at RUSTLIB/std/src/fs.rs:LL:CC - = note: inside `std::fs::OpenOptions::open::<&std::path::Path>` at RUSTLIB/std/src/fs.rs:LL:CC + = note: inside closure at RUSTLIB/std/src/fs.rs:LL:CC + = note: inside closure at RUSTLIB/std/src/path.rs:LL:CC + = note: inside `std::sys::PLATFORM::small_c_string::run_with_cstr::::with_native_path::{closure#0}]>::{closure#0}]>` at RUSTLIB/std/src/sys/PLATFORM/small_c_string.rs:LL:CC + = note: inside `std::sys::PLATFORM::small_c_string::run_path_with_cstr::::with_native_path::{closure#0}]>::{closure#0}]>` at RUSTLIB/std/src/sys/PLATFORM/small_c_string.rs:LL:CC + = note: inside `<&str as std::path::PathLike>::with_native_path::::{closure#0}]>` at RUSTLIB/std/src/path.rs:LL:CC + = note: inside `std::fs::OpenOptions::open::<&str>` at RUSTLIB/std/src/fs.rs:LL:CC = note: inside `std::fs::File::open::<&str>` at RUSTLIB/std/src/fs.rs:LL:CC note: inside `main` --> $DIR/isolated_file.rs:LL:CC diff --git a/tests/ui/async-await/issue-72442.stderr b/tests/ui/async-await/issue-72442.stderr index 4a1705715cacc..f7a165a83bec3 100644 --- a/tests/ui/async-await/issue-72442.stderr +++ b/tests/ui/async-await/issue-72442.stderr @@ -6,6 +6,8 @@ LL | let mut f = File::open(path.to_str())?; | | | required by a bound introduced by this call | + = help: the trait `PathLike` is implemented for `&NativePath` + = note: required for `Option<&str>` to implement `PathLike` note: required by a bound in `File::open` --> $SRC_DIR/std/src/fs.rs:LL:COL