diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:43 +0000 |
commit | 3e3e70d529d8c7d7c4d7bc4fefc9f109393b9245 (patch) | |
tree | daf049b282ab10e8c3d03e409b3cd84ff3f7690c /vendor/camino/src | |
parent | Adding debian version 1.68.2+dfsg1-1. (diff) | |
download | rustc-3e3e70d529d8c7d7c4d7bc4fefc9f109393b9245.tar.xz rustc-3e3e70d529d8c7d7c4d7bc4fefc9f109393b9245.zip |
Merging upstream version 1.69.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/camino/src')
-rw-r--r-- | vendor/camino/src/lib.rs | 42 | ||||
-rw-r--r-- | vendor/camino/src/proptest_impls.rs | 3 |
2 files changed, 32 insertions, 13 deletions
diff --git a/vendor/camino/src/lib.rs b/vendor/camino/src/lib.rs index fcfba3805..44684b096 100644 --- a/vendor/camino/src/lib.rs +++ b/vendor/camino/src/lib.rs @@ -222,7 +222,7 @@ impl Utf8PathBuf { #[must_use] pub fn as_path(&self) -> &Utf8Path { // SAFETY: every Utf8PathBuf constructor ensures that self is valid UTF-8 - unsafe { Utf8Path::assume_utf8(&*self.0) } + unsafe { Utf8Path::assume_utf8(&self.0) } } /// Extends `self` with `path`. @@ -1175,10 +1175,8 @@ impl Utf8Path { /// assert_eq!(path.canonicalize_utf8().unwrap(), Utf8PathBuf::from("/foo/test/bar.rs")); /// ``` pub fn canonicalize_utf8(&self) -> io::Result<Utf8PathBuf> { - self.canonicalize().and_then(|path| { - path.try_into() - .map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err)) - }) + self.canonicalize() + .and_then(|path| path.try_into().map_err(FromPathBufError::into_io_error)) } /// Reads a symbolic link, returning the file that the link points to. @@ -1224,10 +1222,8 @@ impl Utf8Path { /// let path_link = path.read_link_utf8().expect("read_link call failed"); /// ``` pub fn read_link_utf8(&self) -> io::Result<Utf8PathBuf> { - self.read_link().and_then(|path| { - path.try_into() - .map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err)) - }) + self.read_link() + .and_then(|path| path.try_into().map_err(FromPathBufError::into_io_error)) } /// Returns an iterator over the entries within a directory. @@ -2488,13 +2484,24 @@ impl FromPathBufError { self.path } - /// Fetch a [`FromPathError`] for more about the conversion failure. + /// Fetches a [`FromPathError`] for more about the conversion failure. /// /// At the moment this struct does not contain any additional information, but is provided for /// completeness. pub fn from_path_error(&self) -> FromPathError { self.error } + + /// Converts self into a [`std::io::Error`] with kind + /// [`InvalidData`](io::ErrorKind::InvalidData). + /// + /// Many users of `FromPathBufError` will want to convert it into an `io::Error`. This is a + /// convenience method to do that. + pub fn into_io_error(self) -> io::Error { + // NOTE: we don't currently implement `From<FromPathBufError> for io::Error` because we want + // to ensure the user actually desires that conversion. + io::Error::new(io::ErrorKind::InvalidData, self) + } } impl fmt::Display for FromPathBufError { @@ -2539,6 +2546,19 @@ impl error::Error for FromPathBufError { #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct FromPathError(()); +impl FromPathError { + /// Converts self into a [`std::io::Error`] with kind + /// [`InvalidData`](io::ErrorKind::InvalidData). + /// + /// Many users of `FromPathError` will want to convert it into an `io::Error`. This is a + /// convenience method to do that. + pub fn into_io_error(self) -> io::Error { + // NOTE: we don't currently implement `From<FromPathBufError> for io::Error` because we want + // to ensure the user actually desires that conversion. + io::Error::new(io::ErrorKind::InvalidData, self) + } +} + impl fmt::Display for FromPathError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Path contains invalid UTF-8") @@ -2587,7 +2607,7 @@ impl AsRef<Path> for Utf8Path { impl AsRef<Path> for Utf8PathBuf { fn as_ref(&self) -> &Path { - &*self.0 + &self.0 } } diff --git a/vendor/camino/src/proptest_impls.rs b/vendor/camino/src/proptest_impls.rs index 997c88c8c..81776f226 100644 --- a/vendor/camino/src/proptest_impls.rs +++ b/vendor/camino/src/proptest_impls.rs @@ -8,9 +8,8 @@ // NOTE: #[cfg(feature = "proptest1")] is specified here to work with `doc_cfg`. -use proptest::{arbitrary::StrategyFor, prelude::*, strategy::MapInto}; - use crate::{Utf8Path, Utf8PathBuf}; +use proptest::{arbitrary::StrategyFor, prelude::*, strategy::MapInto}; /// The [`Arbitrary`] impl for `Utf8PathBuf` returns a path with between 0 and 8 components, /// joined by the [`MAIN_SEPARATOR`](std::path::MAIN_SEPARATOR) for the platform. (Each component is |