Skip to content

Commit ccad544

Browse files
committed
Add mutual PartialOrd impls for Path and PathBuf
1 parent 27be433 commit ccad544

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/libstd/path.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,7 +2051,7 @@ impl<'a> IntoIterator for &'a Path {
20512051
fn into_iter(self) -> Iter<'a> { self.iter() }
20522052
}
20532053

2054-
macro_rules! impl_eq {
2054+
macro_rules! impl_cmp {
20552055
($lhs:ty, $rhs: ty) => {
20562056
#[stable(feature = "partialeq_path", since = "1.6.0")]
20572057
impl<'a, 'b> PartialEq<$rhs> for $lhs {
@@ -2065,14 +2065,29 @@ macro_rules! impl_eq {
20652065
fn eq(&self, other: &$lhs) -> bool { <Path as PartialEq>::eq(self, other) }
20662066
}
20672067

2068+
#[stable(feature = "cmp_path", since = "1.8.0")]
2069+
impl<'a, 'b> PartialOrd<$rhs> for $lhs {
2070+
#[inline]
2071+
fn partial_cmp(&self, other: &$rhs) -> Option<cmp::Ordering> {
2072+
<Path as PartialOrd>::partial_cmp(self, other)
2073+
}
2074+
}
2075+
2076+
#[stable(feature = "cmp_path", since = "1.8.0")]
2077+
impl<'a, 'b> PartialOrd<$lhs> for $rhs {
2078+
#[inline]
2079+
fn partial_cmp(&self, other: &$lhs) -> Option<cmp::Ordering> {
2080+
<Path as PartialOrd>::partial_cmp(self, other)
2081+
}
2082+
}
20682083
}
20692084
}
20702085

2071-
impl_eq!(PathBuf, Path);
2072-
impl_eq!(PathBuf, &'a Path);
2073-
impl_eq!(Cow<'a, Path>, Path);
2074-
impl_eq!(Cow<'a, Path>, &'b Path);
2075-
impl_eq!(Cow<'a, Path>, PathBuf);
2086+
impl_cmp!(PathBuf, Path);
2087+
impl_cmp!(PathBuf, &'a Path);
2088+
impl_cmp!(Cow<'a, Path>, Path);
2089+
impl_cmp!(Cow<'a, Path>, &'b Path);
2090+
impl_cmp!(Cow<'a, Path>, PathBuf);
20762091

20772092
#[stable(since = "1.7.0", feature = "strip_prefix")]
20782093
impl fmt::Display for StripPrefixError {

0 commit comments

Comments
 (0)