summaryrefslogtreecommitdiffstats
path: root/vendor/camino
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:06:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:06:31 +0000
commit2ff14448863ac1a1dd9533461708e29aae170c2d (patch)
tree85b9fea2bbfe3f06473cfa381eed11f273b57c5c /vendor/camino
parentAdding debian version 1.64.0+dfsg1-1. (diff)
downloadrustc-2ff14448863ac1a1dd9533461708e29aae170c2d.tar.xz
rustc-2ff14448863ac1a1dd9533461708e29aae170c2d.zip
Adding debian version 1.65.0+dfsg1-2.debian/1.65.0+dfsg1-2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/camino')
-rw-r--r--vendor/camino/.cargo-checksum.json2
-rw-r--r--vendor/camino/CHANGELOG.md22
-rw-r--r--vendor/camino/Cargo.toml2
-rw-r--r--vendor/camino/build.rs27
-rw-r--r--vendor/camino/src/lib.rs137
5 files changed, 186 insertions, 4 deletions
diff --git a/vendor/camino/.cargo-checksum.json b/vendor/camino/.cargo-checksum.json
index 1de1f0c97..81a1f0f60 100644
--- a/vendor/camino/.cargo-checksum.json
+++ b/vendor/camino/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"CHANGELOG.md":"886087c5abaa1078e179e173b997fd4bffd93e47b2914defd8148f3f396e98f0","CODE_OF_CONDUCT.md":"f51e207c2961ec061cac5c8aa9dd3098c3437de2c106d740c2aae90771bc0f86","Cargo.toml":"17bc7f765ef82a295aff4292261d23dc0c6c75b44e6c3016631cc087d5fe20f6","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"84762d717d0f2358c56f54ee46a6ca5f1582b7d3843f7a4d6e553ea04a57ca1b","build.rs":"4e46d73efd79ec269ddc1b2578cad051c66195225bfdf012e4ed430f9f98a3ab","clippy.toml":"818cba7332cc56b019d59e09805a3498f523da788f51454742905f1987c0b563","rustfmt.toml":"bf9776adb152b3fdc0d75c0929ede148c3e28c58f909a7d052865bc332e8958f","src/lib.rs":"a59a425a4bf1e2ae8f16bc0349fadf0fe3f7ec2effa44137bd59e17c3ff15456","src/proptest_impls.rs":"aa17bad810abe4a7b6c7a2c3163ae9749b03dd8bcef5043b0c4b9d00977f981c","src/serde_impls.rs":"eb7f00d1ceb7135506047dbefd7e6acee0364b5a9194111f49dbf2d1eb3661ac","src/tests.rs":"d6108c540dc93446b17d297b50372f799ef777c2cb0280fd37824a102ec24533","tests/integration_tests.rs":"b664a7555d2e5ac9ab71384e3ccfb73c01abe4c401f8de32e234c03b4d19d0f8"},"package":"869119e97797867fd90f5e22af7d0bd274bd4635ebb9eb68c04f3f513ae6c412"} \ No newline at end of file
+{"files":{"CHANGELOG.md":"2530b12d7ddf3395bbc4c10557e57531498039ba28528b91ffc3f3deefc76f77","CODE_OF_CONDUCT.md":"f51e207c2961ec061cac5c8aa9dd3098c3437de2c106d740c2aae90771bc0f86","Cargo.toml":"7bf7de17ab10cd95aadf102f37c0b8a58f0c31f90cfeee81126ead8ad3cb0a26","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"84762d717d0f2358c56f54ee46a6ca5f1582b7d3843f7a4d6e553ea04a57ca1b","build.rs":"ca6914ad35e69842b6fba6e436d0417f39dbe6ee18694d4dd89b372d31cbf715","clippy.toml":"818cba7332cc56b019d59e09805a3498f523da788f51454742905f1987c0b563","rustfmt.toml":"bf9776adb152b3fdc0d75c0929ede148c3e28c58f909a7d052865bc332e8958f","src/lib.rs":"3a744ca7df473bb8bd97e1f4a961d517cb7379b8756e38893dd9d53a169c41e1","src/proptest_impls.rs":"aa17bad810abe4a7b6c7a2c3163ae9749b03dd8bcef5043b0c4b9d00977f981c","src/serde_impls.rs":"eb7f00d1ceb7135506047dbefd7e6acee0364b5a9194111f49dbf2d1eb3661ac","src/tests.rs":"d6108c540dc93446b17d297b50372f799ef777c2cb0280fd37824a102ec24533","tests/integration_tests.rs":"b664a7555d2e5ac9ab71384e3ccfb73c01abe4c401f8de32e234c03b4d19d0f8"},"package":"88ad0e1e3e88dd237a156ab9f571021b8a158caa0ae44b1968a241efb5144c1e"} \ No newline at end of file
diff --git a/vendor/camino/CHANGELOG.md b/vendor/camino/CHANGELOG.md
index b9a04de7a..67c2ea8d3 100644
--- a/vendor/camino/CHANGELOG.md
+++ b/vendor/camino/CHANGELOG.md
@@ -3,6 +3,24 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [1.1.1] - 2022-08-12
+
+### Fixed
+
+- Fixed a build regression on older nightlies in the 1.63 series
+ ([#22](https://github.com/camino-rs/camino/issues/22)).
+- Documentation fixes.
+
+## [1.1.0] - 2022-08-11
+
+### Added
+
+- New methods, mirroring those in recent versions of Rust:
+ - `Utf8Path::try_exists` checks whether a path exists. Note that while `std::path::Path` only provides this method for Rust 1.58 and above, `camino` backfills the method for all Rust versions it supports.
+ - `Utf8PathBuf::shrink_to` shrinks a `Utf8PathBuf` to a given size. This was added in, and is gated on, Rust 1.56+.
+ - `Utf8PathBuf::try_reserve` and `Utf8PathBuf::try_reserve_exact` implement fallible allocations. These were added in, and are gated on, Rust 1.63+.
+- A number of `#[must_use]` annotations to APIs, mirroring those added to `Path` and `PathBuf` in recent versions of Rust. The minor version bump is due to this change.
+
## [1.0.9] - 2022-05-19
### Fixed
@@ -24,7 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- `Utf8Path::is_symlink` checks whether a path is a symlink. Note that while `std::path::Path` only
- provides this method for version 1.58 and above, `camino` polyfills the method for all Rust versions
+ provides this method for version 1.58 and above, `camino` backfills the method for all Rust versions
it supports.
### Changed
@@ -83,6 +101,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Initial release.
+[1.1.1]: https://github.com/camino-rs/camino/releases/tag/camino-1.1.1
+[1.1.0]: https://github.com/camino-rs/camino/releases/tag/camino-1.1.0
[1.0.9]: https://github.com/camino-rs/camino/releases/tag/camino-1.0.9
[1.0.8]: https://github.com/camino-rs/camino/releases/tag/camino-1.0.8
[1.0.7]: https://github.com/camino-rs/camino/releases/tag/camino-1.0.7
diff --git a/vendor/camino/Cargo.toml b/vendor/camino/Cargo.toml
index cd2bd9fea..28c007855 100644
--- a/vendor/camino/Cargo.toml
+++ b/vendor/camino/Cargo.toml
@@ -12,7 +12,7 @@
[package]
edition = "2018"
name = "camino"
-version = "1.0.9"
+version = "1.1.1"
authors = [
"Without Boats <saoirse@without.boats>",
"Ashley Williams <ashley666ashley@gmail.com>",
diff --git a/vendor/camino/build.rs b/vendor/camino/build.rs
index bc3e4480d..7f5cbdf9b 100644
--- a/vendor/camino/build.rs
+++ b/vendor/camino/build.rs
@@ -21,10 +21,28 @@ fn main() {
if compiler.minor >= 44 {
println!("cargo:rustc-cfg=path_buf_capacity");
}
+ if compiler.minor >= 56 {
+ println!("cargo:rustc-cfg=shrink_to");
+ }
+ // Stable and beta 1.63 have a stable try_reserve_2.
+ if (compiler.minor >= 63
+ && (compiler.channel == ReleaseChannel::Stable || compiler.channel == ReleaseChannel::Beta))
+ || compiler.minor >= 64
+ {
+ println!("cargo:rustc-cfg=try_reserve_2");
+ }
}
struct Compiler {
minor: u32,
+ channel: ReleaseChannel,
+}
+
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+enum ReleaseChannel {
+ Stable,
+ Beta,
+ Nightly,
}
fn rustc_version() -> Option<Compiler> {
@@ -36,5 +54,12 @@ fn rustc_version() -> Option<Compiler> {
return None;
}
let minor = pieces.next()?.parse().ok()?;
- Some(Compiler { minor })
+ let channel = if version.contains("nightly") {
+ ReleaseChannel::Nightly
+ } else if version.contains("beta") {
+ ReleaseChannel::Beta
+ } else {
+ ReleaseChannel::Stable
+ };
+ Some(Compiler { minor, channel })
}
diff --git a/vendor/camino/src/lib.rs b/vendor/camino/src/lib.rs
index 4a1b6dfd7..fcfba3805 100644
--- a/vendor/camino/src/lib.rs
+++ b/vendor/camino/src/lib.rs
@@ -120,6 +120,7 @@ impl Utf8PathBuf {
///
/// let path = Utf8PathBuf::new();
/// ```
+ #[must_use]
pub fn new() -> Utf8PathBuf {
Utf8PathBuf(PathBuf::new())
}
@@ -177,6 +178,7 @@ impl Utf8PathBuf {
/// let new_utf8_path_buf = Utf8PathBuf::from_path_buf(std_path_buf).unwrap();
/// assert_eq!(new_utf8_path_buf, "foo.txt");
/// ```
+ #[must_use = "`self` will be dropped if the result is not used"]
pub fn into_std_path_buf(self) -> PathBuf {
self.into()
}
@@ -202,6 +204,7 @@ impl Utf8PathBuf {
///
/// [`with_capacity`]: PathBuf::with_capacity
#[cfg(path_buf_capacity)]
+ #[must_use]
pub fn with_capacity(capacity: usize) -> Utf8PathBuf {
Utf8PathBuf(PathBuf::with_capacity(capacity))
}
@@ -216,6 +219,7 @@ impl Utf8PathBuf {
/// let p = Utf8PathBuf::from("/test");
/// assert_eq!(Utf8Path::new("/test"), p.as_path());
/// ```
+ #[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) }
@@ -347,6 +351,7 @@ impl Utf8PathBuf {
/// let s = p.into_string();
/// assert_eq!(s, "/the/head");
/// ```
+ #[must_use = "`self` will be dropped if the result is not used"]
pub fn into_string(self) -> String {
self.into_os_string().into_string().unwrap()
}
@@ -363,11 +368,13 @@ impl Utf8PathBuf {
/// let s = p.into_os_string();
/// assert_eq!(s, OsStr::new("/the/head"));
/// ```
+ #[must_use = "`self` will be dropped if the result is not used"]
pub fn into_os_string(self) -> OsString {
self.0.into_os_string()
}
/// Converts this `Utf8PathBuf` into a [boxed](Box) [`Utf8Path`].
+ #[must_use = "`self` will be dropped if the result is not used"]
pub fn into_boxed_path(self) -> Box<Utf8Path> {
let ptr = Box::into_raw(self.0.into_boxed_path()) as *mut Utf8Path;
// SAFETY:
@@ -384,6 +391,7 @@ impl Utf8PathBuf {
///
/// [`capacity`]: PathBuf::capacity
#[cfg(path_buf_capacity)]
+ #[must_use]
pub fn capacity(&self) -> usize {
self.0.capacity()
}
@@ -408,6 +416,20 @@ impl Utf8PathBuf {
self.0.reserve(additional)
}
+ /// Invokes [`try_reserve`] on the underlying instance of [`PathBuf`].
+ ///
+ /// *Requires Rust 1.63 or newer.*
+ ///
+ /// [`try_reserve`]: PathBuf::try_reserve
+ #[cfg(try_reserve_2)]
+ #[inline]
+ pub fn try_reserve(
+ &mut self,
+ additional: usize,
+ ) -> Result<(), std::collections::TryReserveError> {
+ self.0.try_reserve(additional)
+ }
+
/// Invokes [`reserve_exact`] on the underlying instance of [`PathBuf`].
///
/// *Requires Rust 1.44 or newer.*
@@ -418,6 +440,20 @@ impl Utf8PathBuf {
self.0.reserve_exact(additional)
}
+ /// Invokes [`try_reserve_exact`] on the underlying instance of [`PathBuf`].
+ ///
+ /// *Requires Rust 1.63 or newer.*
+ ///
+ /// [`try_reserve_exact`]: PathBuf::try_reserve_exact
+ #[cfg(try_reserve_2)]
+ #[inline]
+ pub fn try_reserve_exact(
+ &mut self,
+ additional: usize,
+ ) -> Result<(), std::collections::TryReserveError> {
+ self.0.try_reserve_exact(additional)
+ }
+
/// Invokes [`shrink_to_fit`] on the underlying instance of [`PathBuf`].
///
/// *Requires Rust 1.44 or newer.*
@@ -427,6 +463,17 @@ impl Utf8PathBuf {
pub fn shrink_to_fit(&mut self) {
self.0.shrink_to_fit()
}
+
+ /// Invokes [`shrink_to`] on the underlying instance of [`PathBuf`].
+ ///
+ /// *Requires Rust 1.56 or newer.*
+ ///
+ /// [`shrink_to`]: PathBuf::shrink_to
+ #[cfg(shrink_to)]
+ #[inline]
+ pub fn shrink_to(&mut self, min_capacity: usize) {
+ self.0.shrink_to(min_capacity)
+ }
}
impl Deref for Utf8PathBuf {
@@ -586,6 +633,7 @@ impl Utf8Path {
/// ```
///
/// [`str`]: str
+ #[must_use]
pub fn as_str(&self) -> &str {
// SAFETY: every Utf8Path constructor ensures that self is valid UTF-8
unsafe { assume_utf8(self.as_os_str()) }
@@ -601,6 +649,7 @@ impl Utf8Path {
/// let os_str = Utf8Path::new("foo.txt").as_os_str();
/// assert_eq!(os_str, std::ffi::OsStr::new("foo.txt"));
/// ```
+ #[must_use]
pub fn as_os_str(&self) -> &OsStr {
self.0.as_os_str()
}
@@ -615,6 +664,8 @@ impl Utf8Path {
/// let path_buf = Utf8Path::new("foo.txt").to_path_buf();
/// assert_eq!(path_buf, Utf8PathBuf::from("foo.txt"));
/// ```
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
pub fn to_path_buf(&self) -> Utf8PathBuf {
Utf8PathBuf(self.0.to_path_buf())
}
@@ -637,6 +688,7 @@ impl Utf8Path {
/// ```
///
/// [`has_root`]: Utf8Path::has_root
+ #[must_use]
pub fn is_absolute(&self) -> bool {
self.0.is_absolute()
}
@@ -654,6 +706,7 @@ impl Utf8Path {
/// ```
///
/// [`is_absolute`]: Utf8Path::is_absolute
+ #[must_use]
pub fn is_relative(&self) -> bool {
self.0.is_relative()
}
@@ -674,6 +727,7 @@ impl Utf8Path {
///
/// assert!(Utf8Path::new("/etc/passwd").has_root());
/// ```
+ #[must_use]
pub fn has_root(&self) -> bool {
self.0.has_root()
}
@@ -695,6 +749,7 @@ impl Utf8Path {
/// assert_eq!(grand_parent, Utf8Path::new("/"));
/// assert_eq!(grand_parent.parent(), None);
/// ```
+ #[must_use]
pub fn parent(&self) -> Option<&Utf8Path> {
self.0.parent().map(|path| {
// SAFETY: self is valid UTF-8, so parent is valid UTF-8 as well
@@ -753,6 +808,7 @@ impl Utf8Path {
/// assert_eq!(None, Utf8Path::new("foo.txt/..").file_name());
/// assert_eq!(None, Utf8Path::new("/").file_name());
/// ```
+ #[must_use]
pub fn file_name(&self) -> Option<&str> {
self.0.file_name().map(|s| {
// SAFETY: self is valid UTF-8, so file_name is valid UTF-8 as well
@@ -818,6 +874,7 @@ impl Utf8Path {
///
/// assert!(!Utf8Path::new("/etc/foo.rs").starts_with("/etc/foo"));
/// ```
+ #[must_use]
pub fn starts_with(&self, base: impl AsRef<Path>) -> bool {
self.0.starts_with(base)
}
@@ -840,6 +897,7 @@ impl Utf8Path {
/// assert!(!path.ends_with("/resolv.conf"));
/// assert!(!path.ends_with("conf")); // use .extension() instead
/// ```
+ #[must_use]
pub fn ends_with(&self, base: impl AsRef<Path>) -> bool {
self.0.ends_with(base)
}
@@ -863,6 +921,7 @@ impl Utf8Path {
/// assert_eq!("foo", Utf8Path::new("foo.rs").file_stem().unwrap());
/// assert_eq!("foo.tar", Utf8Path::new("foo.tar.gz").file_stem().unwrap());
/// ```
+ #[must_use]
pub fn file_stem(&self) -> Option<&str> {
self.0.file_stem().map(|s| {
// SAFETY: self is valid UTF-8, so file_stem is valid UTF-8 as well
@@ -889,6 +948,7 @@ impl Utf8Path {
/// assert_eq!("rs", Utf8Path::new("foo.rs").extension().unwrap());
/// assert_eq!("gz", Utf8Path::new("foo.tar.gz").extension().unwrap());
/// ```
+ #[must_use]
pub fn extension(&self) -> Option<&str> {
self.0.extension().map(|s| {
// SAFETY: self is valid UTF-8, so extension is valid UTF-8 as well
@@ -907,6 +967,7 @@ impl Utf8Path {
///
/// assert_eq!(Utf8Path::new("/etc").join("passwd"), Utf8PathBuf::from("/etc/passwd"));
/// ```
+ #[must_use]
pub fn join(&self, path: impl AsRef<Utf8Path>) -> Utf8PathBuf {
Utf8PathBuf(self.0.join(&path.as_ref().0))
}
@@ -923,6 +984,7 @@ impl Utf8Path {
///
/// assert_eq!(Utf8Path::new("/etc").join_os("passwd"), PathBuf::from("/etc/passwd"));
/// ```
+ #[must_use]
pub fn join_os(&self, path: impl AsRef<Path>) -> PathBuf {
self.0.join(path)
}
@@ -942,6 +1004,7 @@ impl Utf8Path {
/// let path = Utf8Path::new("/tmp");
/// assert_eq!(path.with_file_name("var"), Utf8PathBuf::from("/var"));
/// ```
+ #[must_use]
pub fn with_file_name(&self, file_name: impl AsRef<str>) -> Utf8PathBuf {
Utf8PathBuf(self.0.with_file_name(file_name.as_ref()))
}
@@ -1223,6 +1286,9 @@ impl Utf8Path {
/// Returns `true` if the path points at an existing entity.
///
+ /// Warning: this method may be error-prone, consider using [`try_exists()`] instead!
+ /// It also has a risk of introducing time-of-check to time-of-use (TOCTOU) bugs.
+ ///
/// This function will traverse symbolic links to query information about the
/// destination file. In case of broken symbolic links this will return `false`.
///
@@ -1240,10 +1306,51 @@ impl Utf8Path {
///
/// This is a convenience function that coerces errors to false. If you want to
/// check errors, call [`fs::metadata`].
+ ///
+ /// [`try_exists()`]: Self::try_exists
+ #[must_use]
pub fn exists(&self) -> bool {
self.0.exists()
}
+ /// Returns `Ok(true)` if the path points at an existing entity.
+ ///
+ /// This function will traverse symbolic links to query information about the
+ /// destination file. In case of broken symbolic links this will return `Ok(false)`.
+ ///
+ /// As opposed to the [`exists()`] method, this one doesn't silently ignore errors
+ /// unrelated to the path not existing. (E.g. it will return `Err(_)` in case of permission
+ /// denied on some of the parent directories.)
+ ///
+ /// Note that while this avoids some pitfalls of the `exists()` method, it still can not
+ /// prevent time-of-check to time-of-use (TOCTOU) bugs. You should only use it in scenarios
+ /// where those bugs are not an issue.
+ ///
+ /// # Examples
+ ///
+ /// ```no_run
+ /// use camino::Utf8Path;
+ /// assert!(!Utf8Path::new("does_not_exist.txt").try_exists().expect("Can't check existence of file does_not_exist.txt"));
+ /// assert!(Utf8Path::new("/root/secret_file.txt").try_exists().is_err());
+ /// ```
+ ///
+ /// [`exists()`]: Self::exists
+ #[inline]
+ pub fn try_exists(&self) -> io::Result<bool> {
+ // Note: this block is written this way rather than with a pattern guard to appease Rust
+ // 1.34.
+ match fs::metadata(self) {
+ Ok(_) => Ok(true),
+ Err(error) => {
+ if error.kind() == io::ErrorKind::NotFound {
+ Ok(false)
+ } else {
+ Err(error)
+ }
+ }
+ }
+ }
+
/// Returns `true` if the path exists on disk and is pointing at a regular file.
///
/// This function will traverse symbolic links to query information about the
@@ -1271,6 +1378,7 @@ impl Utf8Path {
/// it. Only using `is_file` can break workflows like `diff <( prog_a )` on
/// a Unix-like system for example. See [`fs::File::open`] or
/// [`fs::OpenOptions::open`] for more information.
+ #[must_use]
pub fn is_file(&self) -> bool {
self.0.is_file()
}
@@ -1296,6 +1404,7 @@ impl Utf8Path {
/// This is a convenience function that coerces errors to false. If you want to
/// check errors, call [`fs::metadata`] and handle its [`Result`]. Then call
/// [`fs::Metadata::is_dir`] if it was [`Ok`].
+ #[must_use]
pub fn is_dir(&self) -> bool {
self.0.is_dir()
}
@@ -1334,6 +1443,7 @@ impl Utf8Path {
}
/// Converts a `Box<Utf8Path>` into a [`Utf8PathBuf`] without copying or allocating.
+ #[must_use = "`self` will be dropped if the result is not used"]
pub fn into_path_buf(self: Box<Utf8Path>) -> Utf8PathBuf {
let ptr = Box::into_raw(self) as *mut Path;
// SAFETY:
@@ -1397,6 +1507,7 @@ impl fmt::Debug for Utf8Path {
///
/// [`ancestors`]: Utf8Path::ancestors
#[derive(Copy, Clone)]
+#[must_use = "iterators are lazy and do nothing unless consumed"]
#[repr(transparent)]
pub struct Utf8Ancestors<'a>(Ancestors<'a>);
@@ -1439,6 +1550,7 @@ impl<'a> FusedIterator for Utf8Ancestors<'a> {}
///
/// [`components`]: Utf8Path::components
#[derive(Clone, Eq, Ord, PartialEq, PartialOrd)]
+#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct Utf8Components<'a>(Components<'a>);
impl<'a> Utf8Components<'a> {
@@ -1455,6 +1567,7 @@ impl<'a> Utf8Components<'a> {
///
/// assert_eq!(Utf8Path::new("foo/bar.txt"), components.as_path());
/// ```
+ #[must_use]
pub fn as_path(&self) -> &'a Utf8Path {
// SAFETY: Utf8Components was constructed from a Utf8Path, so it is guaranteed to be valid
// UTF-8
@@ -1523,6 +1636,7 @@ impl AsRef<OsStr> for Utf8Components<'_> {
///
/// [`iter`]: Utf8Path::iter
#[derive(Clone)]
+#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct Iter<'a> {
inner: Utf8Components<'a>,
}
@@ -1557,6 +1671,7 @@ impl<'a> Iter<'a> {
///
/// assert_eq!(Utf8Path::new("foo/bar.txt"), iter.as_path());
/// ```
+ #[must_use]
pub fn as_path(&self) -> &'a Utf8Path {
self.inner.as_path()
}
@@ -1674,6 +1789,7 @@ impl<'a> Utf8Component<'a> {
/// let components: Vec<_> = path.components().map(|comp| comp.as_str()).collect();
/// assert_eq!(&components, &[".", "tmp", "foo", "bar.txt"]);
/// ```
+ #[must_use]
pub fn as_str(&self) -> &'a str {
// SAFETY: Utf8Component was constructed from a Utf8Path, so it is guaranteed to be
// valid UTF-8
@@ -1691,6 +1807,7 @@ impl<'a> Utf8Component<'a> {
/// let components: Vec<_> = path.components().map(|comp| comp.as_os_str()).collect();
/// assert_eq!(&components, &[".", "tmp", "foo", "bar.txt"]);
/// ```
+ #[must_use]
pub fn as_os_str(&self) -> &'a OsStr {
match *self {
Utf8Component::Prefix(prefix) => prefix.as_os_str(),
@@ -1821,6 +1938,7 @@ impl<'a> Utf8Prefix<'a> {
/// assert!(!UNC("server", "share").is_verbatim());
/// assert!(!Disk(b'C').is_verbatim());
/// ```
+ #[must_use]
pub fn is_verbatim(&self) -> bool {
use Utf8Prefix::*;
match self {
@@ -1872,6 +1990,7 @@ impl<'a> Utf8PrefixComponent<'a> {
///
/// See [`Utf8Prefix`]'s documentation for more information on the different
/// kinds of prefixes.
+ #[must_use]
pub fn kind(&self) -> Utf8Prefix<'a> {
// SAFETY for all the below unsafe blocks: the path self was originally constructed from was
// UTF-8 so any parts of it are valid UTF-8
@@ -1894,6 +2013,7 @@ impl<'a> Utf8PrefixComponent<'a> {
}
/// Returns the [`str`] slice for this prefix.
+ #[must_use]
pub fn as_str(&self) -> &'a str {
// SAFETY: Utf8PrefixComponent was constructed from a Utf8Path, so it is guaranteed to be
// valid UTF-8
@@ -1901,6 +2021,7 @@ impl<'a> Utf8PrefixComponent<'a> {
}
/// Returns the raw [`OsStr`] slice for this prefix.
+ #[must_use]
pub fn as_os_str(&self) -> &'a OsStr {
self.0.as_os_str()
}
@@ -2596,6 +2717,7 @@ impl<'a> IntoIterator for &'a Utf8Path {
macro_rules! impl_cmp {
($lhs:ty, $rhs: ty) => {
+ #[allow(clippy::extra_unused_lifetimes)]
impl<'a, 'b> PartialEq<$rhs> for $lhs {
#[inline]
fn eq(&self, other: &$rhs) -> bool {
@@ -2603,6 +2725,7 @@ macro_rules! impl_cmp {
}
}
+ #[allow(clippy::extra_unused_lifetimes)]
impl<'a, 'b> PartialEq<$lhs> for $rhs {
#[inline]
fn eq(&self, other: &$lhs) -> bool {
@@ -2610,6 +2733,7 @@ macro_rules! impl_cmp {
}
}
+ #[allow(clippy::extra_unused_lifetimes)]
impl<'a, 'b> PartialOrd<$rhs> for $lhs {
#[inline]
fn partial_cmp(&self, other: &$rhs) -> Option<Ordering> {
@@ -2617,6 +2741,7 @@ macro_rules! impl_cmp {
}
}
+ #[allow(clippy::extra_unused_lifetimes)]
impl<'a, 'b> PartialOrd<$lhs> for $rhs {
#[inline]
fn partial_cmp(&self, other: &$lhs) -> Option<Ordering> {
@@ -2634,6 +2759,7 @@ impl_cmp!(Cow<'a, Utf8Path>, Utf8PathBuf);
macro_rules! impl_cmp_std_path {
($lhs:ty, $rhs: ty) => {
+ #[allow(clippy::extra_unused_lifetimes)]
impl<'a, 'b> PartialEq<$rhs> for $lhs {
#[inline]
fn eq(&self, other: &$rhs) -> bool {
@@ -2641,6 +2767,7 @@ macro_rules! impl_cmp_std_path {
}
}
+ #[allow(clippy::extra_unused_lifetimes)]
impl<'a, 'b> PartialEq<$lhs> for $rhs {
#[inline]
fn eq(&self, other: &$lhs) -> bool {
@@ -2648,6 +2775,7 @@ macro_rules! impl_cmp_std_path {
}
}
+ #[allow(clippy::extra_unused_lifetimes)]
impl<'a, 'b> PartialOrd<$rhs> for $lhs {
#[inline]
fn partial_cmp(&self, other: &$rhs) -> Option<std::cmp::Ordering> {
@@ -2655,6 +2783,7 @@ macro_rules! impl_cmp_std_path {
}
}
+ #[allow(clippy::extra_unused_lifetimes)]
impl<'a, 'b> PartialOrd<$lhs> for $rhs {
#[inline]
fn partial_cmp(&self, other: &$lhs) -> Option<std::cmp::Ordering> {
@@ -2679,6 +2808,7 @@ impl_cmp_std_path!(&'a Utf8Path, PathBuf);
macro_rules! impl_cmp_str {
($lhs:ty, $rhs: ty) => {
+ #[allow(clippy::extra_unused_lifetimes)]
impl<'a, 'b> PartialEq<$rhs> for $lhs {
#[inline]
fn eq(&self, other: &$rhs) -> bool {
@@ -2686,6 +2816,7 @@ macro_rules! impl_cmp_str {
}
}
+ #[allow(clippy::extra_unused_lifetimes)]
impl<'a, 'b> PartialEq<$lhs> for $rhs {
#[inline]
fn eq(&self, other: &$lhs) -> bool {
@@ -2693,6 +2824,7 @@ macro_rules! impl_cmp_str {
}
}
+ #[allow(clippy::extra_unused_lifetimes)]
impl<'a, 'b> PartialOrd<$rhs> for $lhs {
#[inline]
fn partial_cmp(&self, other: &$rhs) -> Option<std::cmp::Ordering> {
@@ -2700,6 +2832,7 @@ macro_rules! impl_cmp_str {
}
}
+ #[allow(clippy::extra_unused_lifetimes)]
impl<'a, 'b> PartialOrd<$lhs> for $rhs {
#[inline]
fn partial_cmp(&self, other: &$lhs) -> Option<std::cmp::Ordering> {
@@ -2724,6 +2857,7 @@ impl_cmp_str!(&'a Utf8Path, String);
macro_rules! impl_cmp_os_str {
($lhs:ty, $rhs: ty) => {
+ #[allow(clippy::extra_unused_lifetimes)]
impl<'a, 'b> PartialEq<$rhs> for $lhs {
#[inline]
fn eq(&self, other: &$rhs) -> bool {
@@ -2731,6 +2865,7 @@ macro_rules! impl_cmp_os_str {
}
}
+ #[allow(clippy::extra_unused_lifetimes)]
impl<'a, 'b> PartialEq<$lhs> for $rhs {
#[inline]
fn eq(&self, other: &$lhs) -> bool {
@@ -2738,6 +2873,7 @@ macro_rules! impl_cmp_os_str {
}
}
+ #[allow(clippy::extra_unused_lifetimes)]
impl<'a, 'b> PartialOrd<$rhs> for $lhs {
#[inline]
fn partial_cmp(&self, other: &$rhs) -> Option<std::cmp::Ordering> {
@@ -2745,6 +2881,7 @@ macro_rules! impl_cmp_os_str {
}
}
+ #[allow(clippy::extra_unused_lifetimes)]
impl<'a, 'b> PartialOrd<$lhs> for $rhs {
#[inline]
fn partial_cmp(&self, other: &$lhs) -> Option<std::cmp::Ordering> {