Skip to content

Commit 43ddfbd

Browse files
committed
Auto merge of #31751 - gkoz:os_str_path_cmp, r=aturon
2 parents 0de3cac + 409bffa commit 43ddfbd

File tree

2 files changed

+113
-6
lines changed

2 files changed

+113
-6
lines changed

src/libstd/ffi/os_str.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,44 @@ impl Ord for OsStr {
411411
fn cmp(&self, other: &OsStr) -> cmp::Ordering { self.bytes().cmp(other.bytes()) }
412412
}
413413

414+
macro_rules! impl_cmp {
415+
($lhs:ty, $rhs: ty) => {
416+
#[stable(feature = "cmp_os_str", since = "1.8.0")]
417+
impl<'a, 'b> PartialEq<$rhs> for $lhs {
418+
#[inline]
419+
fn eq(&self, other: &$rhs) -> bool { <OsStr as PartialEq>::eq(self, other) }
420+
}
421+
422+
#[stable(feature = "cmp_os_str", since = "1.8.0")]
423+
impl<'a, 'b> PartialEq<$lhs> for $rhs {
424+
#[inline]
425+
fn eq(&self, other: &$lhs) -> bool { <OsStr as PartialEq>::eq(self, other) }
426+
}
427+
428+
#[stable(feature = "cmp_os_str", since = "1.8.0")]
429+
impl<'a, 'b> PartialOrd<$rhs> for $lhs {
430+
#[inline]
431+
fn partial_cmp(&self, other: &$rhs) -> Option<cmp::Ordering> {
432+
<OsStr as PartialOrd>::partial_cmp(self, other)
433+
}
434+
}
435+
436+
#[stable(feature = "cmp_os_str", since = "1.8.0")]
437+
impl<'a, 'b> PartialOrd<$lhs> for $rhs {
438+
#[inline]
439+
fn partial_cmp(&self, other: &$lhs) -> Option<cmp::Ordering> {
440+
<OsStr as PartialOrd>::partial_cmp(self, other)
441+
}
442+
}
443+
}
444+
}
445+
446+
impl_cmp!(OsString, OsStr);
447+
impl_cmp!(OsString, &'a OsStr);
448+
impl_cmp!(Cow<'a, OsStr>, OsStr);
449+
impl_cmp!(Cow<'a, OsStr>, &'b OsStr);
450+
impl_cmp!(Cow<'a, OsStr>, OsString);
451+
414452
#[stable(feature = "rust1", since = "1.0.0")]
415453
impl Hash for OsStr {
416454
#[inline]

src/libstd/path.rs

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,13 @@ impl AsRef<Path> for OsStr {
20042004
}
20052005
}
20062006

2007+
#[stable(feature = "cow_os_str_as_ref_path", since = "1.8.0")]
2008+
impl<'a> AsRef<Path> for Cow<'a, OsStr> {
2009+
fn as_ref(&self) -> &Path {
2010+
Path::new(self)
2011+
}
2012+
}
2013+
20072014
#[stable(feature = "rust1", since = "1.0.0")]
20082015
impl AsRef<Path> for OsString {
20092016
fn as_ref(&self) -> &Path {
@@ -2046,7 +2053,7 @@ impl<'a> IntoIterator for &'a Path {
20462053
fn into_iter(self) -> Iter<'a> { self.iter() }
20472054
}
20482055

2049-
macro_rules! impl_eq {
2056+
macro_rules! impl_cmp {
20502057
($lhs:ty, $rhs: ty) => {
20512058
#[stable(feature = "partialeq_path", since = "1.6.0")]
20522059
impl<'a, 'b> PartialEq<$rhs> for $lhs {
@@ -2060,14 +2067,76 @@ macro_rules! impl_eq {
20602067
fn eq(&self, other: &$lhs) -> bool { <Path as PartialEq>::eq(self, other) }
20612068
}
20622069

2070+
#[stable(feature = "cmp_path", since = "1.8.0")]
2071+
impl<'a, 'b> PartialOrd<$rhs> for $lhs {
2072+
#[inline]
2073+
fn partial_cmp(&self, other: &$rhs) -> Option<cmp::Ordering> {
2074+
<Path as PartialOrd>::partial_cmp(self, other)
2075+
}
2076+
}
2077+
2078+
#[stable(feature = "cmp_path", since = "1.8.0")]
2079+
impl<'a, 'b> PartialOrd<$lhs> for $rhs {
2080+
#[inline]
2081+
fn partial_cmp(&self, other: &$lhs) -> Option<cmp::Ordering> {
2082+
<Path as PartialOrd>::partial_cmp(self, other)
2083+
}
2084+
}
2085+
}
2086+
}
2087+
2088+
impl_cmp!(PathBuf, Path);
2089+
impl_cmp!(PathBuf, &'a Path);
2090+
impl_cmp!(Cow<'a, Path>, Path);
2091+
impl_cmp!(Cow<'a, Path>, &'b Path);
2092+
impl_cmp!(Cow<'a, Path>, PathBuf);
2093+
2094+
macro_rules! impl_cmp_os_str {
2095+
($lhs:ty, $rhs: ty) => {
2096+
#[stable(feature = "cmp_path", since = "1.8.0")]
2097+
impl<'a, 'b> PartialEq<$rhs> for $lhs {
2098+
#[inline]
2099+
fn eq(&self, other: &$rhs) -> bool { <Path as PartialEq>::eq(self, other.as_ref()) }
2100+
}
2101+
2102+
#[stable(feature = "cmp_path", since = "1.8.0")]
2103+
impl<'a, 'b> PartialEq<$lhs> for $rhs {
2104+
#[inline]
2105+
fn eq(&self, other: &$lhs) -> bool { <Path as PartialEq>::eq(self.as_ref(), other) }
2106+
}
2107+
2108+
#[stable(feature = "cmp_path", since = "1.8.0")]
2109+
impl<'a, 'b> PartialOrd<$rhs> for $lhs {
2110+
#[inline]
2111+
fn partial_cmp(&self, other: &$rhs) -> Option<cmp::Ordering> {
2112+
<Path as PartialOrd>::partial_cmp(self, other.as_ref())
2113+
}
2114+
}
2115+
2116+
#[stable(feature = "cmp_path", since = "1.8.0")]
2117+
impl<'a, 'b> PartialOrd<$lhs> for $rhs {
2118+
#[inline]
2119+
fn partial_cmp(&self, other: &$lhs) -> Option<cmp::Ordering> {
2120+
<Path as PartialOrd>::partial_cmp(self.as_ref(), other)
2121+
}
2122+
}
20632123
}
20642124
}
20652125

2066-
impl_eq!(PathBuf, Path);
2067-
impl_eq!(PathBuf, &'a Path);
2068-
impl_eq!(Cow<'a, Path>, Path);
2069-
impl_eq!(Cow<'a, Path>, &'b Path);
2070-
impl_eq!(Cow<'a, Path>, PathBuf);
2126+
impl_cmp_os_str!(PathBuf, OsStr);
2127+
impl_cmp_os_str!(PathBuf, &'a OsStr);
2128+
impl_cmp_os_str!(PathBuf, Cow<'a, OsStr>);
2129+
impl_cmp_os_str!(PathBuf, OsString);
2130+
impl_cmp_os_str!(Path, OsStr);
2131+
impl_cmp_os_str!(Path, &'a OsStr);
2132+
impl_cmp_os_str!(Path, Cow<'a, OsStr>);
2133+
impl_cmp_os_str!(Path, OsString);
2134+
impl_cmp_os_str!(&'a Path, OsStr);
2135+
impl_cmp_os_str!(&'a Path, Cow<'b, OsStr>);
2136+
impl_cmp_os_str!(&'a Path, OsString);
2137+
impl_cmp_os_str!(Cow<'a, Path>, OsStr);
2138+
impl_cmp_os_str!(Cow<'a, Path>, &'b OsStr);
2139+
impl_cmp_os_str!(Cow<'a, Path>, OsString);
20712140

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

0 commit comments

Comments
 (0)