Skip to content

Commit 96066cb

Browse files
Rollup merge of #143575 - GrigorenkoPV:unused_lifetimes, r=Mark-Simulacrum
Remove named lifetimes in some `PartialOrd` & `PartialEq` `impl`s Makes [the docs](https://doc.rust-lang.org/1.88.0/std/cmp/trait.PartialOrd.html#impl-PartialOrd%3CPathBuf%3E-for-Cow%3C'a,+Path%3E) way easier to look at, gets rid of a few `#[allow(unused_lifetimes)]`, and AFAICT is completely equivalent.
2 parents 16da3ab + cd314de commit 96066cb

6 files changed

Lines changed: 57 additions & 66 deletions

File tree

library/alloc/src/bstr.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -477,39 +477,35 @@ impl PartialEq for ByteString {
477477

478478
macro_rules! impl_partial_eq_ord_cow {
479479
($lhs:ty, $rhs:ty) => {
480-
#[allow(unused_lifetimes)]
481480
#[unstable(feature = "bstr", issue = "134915")]
482-
impl<'a> PartialEq<$rhs> for $lhs {
481+
impl PartialEq<$rhs> for $lhs {
483482
#[inline]
484483
fn eq(&self, other: &$rhs) -> bool {
485484
let other: &[u8] = (&**other).as_ref();
486485
PartialEq::eq(self.as_bytes(), other)
487486
}
488487
}
489488

490-
#[allow(unused_lifetimes)]
491489
#[unstable(feature = "bstr", issue = "134915")]
492-
impl<'a> PartialEq<$lhs> for $rhs {
490+
impl PartialEq<$lhs> for $rhs {
493491
#[inline]
494492
fn eq(&self, other: &$lhs) -> bool {
495493
let this: &[u8] = (&**self).as_ref();
496494
PartialEq::eq(this, other.as_bytes())
497495
}
498496
}
499497

500-
#[allow(unused_lifetimes)]
501498
#[unstable(feature = "bstr", issue = "134915")]
502-
impl<'a> PartialOrd<$rhs> for $lhs {
499+
impl PartialOrd<$rhs> for $lhs {
503500
#[inline]
504501
fn partial_cmp(&self, other: &$rhs) -> Option<Ordering> {
505502
let other: &[u8] = (&**other).as_ref();
506503
PartialOrd::partial_cmp(self.as_bytes(), other)
507504
}
508505
}
509506

510-
#[allow(unused_lifetimes)]
511507
#[unstable(feature = "bstr", issue = "134915")]
512-
impl<'a> PartialOrd<$lhs> for $rhs {
508+
impl PartialOrd<$lhs> for $rhs {
513509
#[inline]
514510
fn partial_cmp(&self, other: &$lhs) -> Option<Ordering> {
515511
let this: &[u8] = (&**self).as_ref();
@@ -667,9 +663,9 @@ impl From<Arc<ByteStr>> for Arc<[u8]> {
667663
impl_partial_eq!(ByteStr, Vec<u8>);
668664
// PartialOrd with `String` omitted to avoid inference failures
669665
impl_partial_eq!(ByteStr, String);
670-
impl_partial_eq_ord_cow!(&'a ByteStr, Cow<'a, ByteStr>);
671-
impl_partial_eq_ord_cow!(&'a ByteStr, Cow<'a, str>);
672-
impl_partial_eq_ord_cow!(&'a ByteStr, Cow<'a, [u8]>);
666+
impl_partial_eq_ord_cow!(&ByteStr, Cow<'_, ByteStr>);
667+
impl_partial_eq_ord_cow!(&ByteStr, Cow<'_, str>);
668+
impl_partial_eq_ord_cow!(&ByteStr, Cow<'_, [u8]>);
673669

674670
#[unstable(feature = "bstr", issue = "134915")]
675671
impl<'a> TryFrom<&'a ByteStr> for String {

library/alloc/src/string.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2661,8 +2661,7 @@ impl<'b> Pattern for &'b String {
26612661
macro_rules! impl_eq {
26622662
($lhs:ty, $rhs: ty) => {
26632663
#[stable(feature = "rust1", since = "1.0.0")]
2664-
#[allow(unused_lifetimes)]
2665-
impl<'a, 'b> PartialEq<$rhs> for $lhs {
2664+
impl PartialEq<$rhs> for $lhs {
26662665
#[inline]
26672666
fn eq(&self, other: &$rhs) -> bool {
26682667
PartialEq::eq(&self[..], &other[..])
@@ -2674,8 +2673,7 @@ macro_rules! impl_eq {
26742673
}
26752674

26762675
#[stable(feature = "rust1", since = "1.0.0")]
2677-
#[allow(unused_lifetimes)]
2678-
impl<'a, 'b> PartialEq<$lhs> for $rhs {
2676+
impl PartialEq<$lhs> for $rhs {
26792677
#[inline]
26802678
fn eq(&self, other: &$lhs) -> bool {
26812679
PartialEq::eq(&self[..], &other[..])
@@ -2689,13 +2687,13 @@ macro_rules! impl_eq {
26892687
}
26902688

26912689
impl_eq! { String, str }
2692-
impl_eq! { String, &'a str }
2690+
impl_eq! { String, &str }
26932691
#[cfg(not(no_global_oom_handling))]
2694-
impl_eq! { Cow<'a, str>, str }
2692+
impl_eq! { Cow<'_, str>, str }
26952693
#[cfg(not(no_global_oom_handling))]
2696-
impl_eq! { Cow<'a, str>, &'b str }
2694+
impl_eq! { Cow<'_, str>, &'_ str }
26972695
#[cfg(not(no_global_oom_handling))]
2698-
impl_eq! { Cow<'a, str>, String }
2696+
impl_eq! { Cow<'_, str>, String }
26992697

27002698
#[stable(feature = "rust1", since = "1.0.0")]
27012699
#[rustc_const_unstable(feature = "const_default", issue = "143894")]

library/core/src/bstr/traits.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,15 @@ impl hash::Hash for ByteStr {
4545
#[unstable(feature = "bstr_internals", issue = "none")]
4646
macro_rules! impl_partial_eq {
4747
($lhs:ty, $rhs:ty) => {
48-
#[allow(unused_lifetimes)]
49-
impl<'a> PartialEq<$rhs> for $lhs {
48+
impl PartialEq<$rhs> for $lhs {
5049
#[inline]
5150
fn eq(&self, other: &$rhs) -> bool {
5251
let other: &[u8] = other.as_ref();
5352
PartialEq::eq(self.as_bytes(), other)
5453
}
5554
}
5655

57-
#[allow(unused_lifetimes)]
58-
impl<'a> PartialEq<$lhs> for $rhs {
56+
impl PartialEq<$lhs> for $rhs {
5957
#[inline]
6058
fn eq(&self, other: &$lhs) -> bool {
6159
let this: &[u8] = self.as_ref();
@@ -76,19 +74,17 @@ macro_rules! impl_partial_eq_ord {
7674
($lhs:ty, $rhs:ty) => {
7775
$crate::bstr::impl_partial_eq!($lhs, $rhs);
7876

79-
#[allow(unused_lifetimes)]
8077
#[unstable(feature = "bstr", issue = "134915")]
81-
impl<'a> PartialOrd<$rhs> for $lhs {
78+
impl PartialOrd<$rhs> for $lhs {
8279
#[inline]
8380
fn partial_cmp(&self, other: &$rhs) -> Option<Ordering> {
8481
let other: &[u8] = other.as_ref();
8582
PartialOrd::partial_cmp(self.as_bytes(), other)
8683
}
8784
}
8885

89-
#[allow(unused_lifetimes)]
9086
#[unstable(feature = "bstr", issue = "134915")]
91-
impl<'a> PartialOrd<$lhs> for $rhs {
87+
impl PartialOrd<$lhs> for $rhs {
9288
#[inline]
9389
fn partial_cmp(&self, other: &$lhs) -> Option<Ordering> {
9490
let this: &[u8] = self.as_ref();
@@ -107,7 +103,6 @@ pub use impl_partial_eq_ord;
107103
#[unstable(feature = "bstr_internals", issue = "none")]
108104
macro_rules! impl_partial_eq_n {
109105
($lhs:ty, $rhs:ty) => {
110-
#[allow(unused_lifetimes)]
111106
#[unstable(feature = "bstr", issue = "134915")]
112107
impl<const N: usize> PartialEq<$rhs> for $lhs {
113108
#[inline]
@@ -117,7 +112,6 @@ macro_rules! impl_partial_eq_n {
117112
}
118113
}
119114

120-
#[allow(unused_lifetimes)]
121115
#[unstable(feature = "bstr", issue = "134915")]
122116
impl<const N: usize> PartialEq<$lhs> for $rhs {
123117
#[inline]

library/std/src/ffi/os_str.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,31 +1565,31 @@ impl Ord for OsStr {
15651565
macro_rules! impl_cmp {
15661566
($lhs:ty, $rhs: ty) => {
15671567
#[stable(feature = "cmp_os_str", since = "1.8.0")]
1568-
impl<'a, 'b> PartialEq<$rhs> for $lhs {
1568+
impl PartialEq<$rhs> for $lhs {
15691569
#[inline]
15701570
fn eq(&self, other: &$rhs) -> bool {
15711571
<OsStr as PartialEq>::eq(self, other)
15721572
}
15731573
}
15741574

15751575
#[stable(feature = "cmp_os_str", since = "1.8.0")]
1576-
impl<'a, 'b> PartialEq<$lhs> for $rhs {
1576+
impl PartialEq<$lhs> for $rhs {
15771577
#[inline]
15781578
fn eq(&self, other: &$lhs) -> bool {
15791579
<OsStr as PartialEq>::eq(self, other)
15801580
}
15811581
}
15821582

15831583
#[stable(feature = "cmp_os_str", since = "1.8.0")]
1584-
impl<'a, 'b> PartialOrd<$rhs> for $lhs {
1584+
impl PartialOrd<$rhs> for $lhs {
15851585
#[inline]
15861586
fn partial_cmp(&self, other: &$rhs) -> Option<cmp::Ordering> {
15871587
<OsStr as PartialOrd>::partial_cmp(self, other)
15881588
}
15891589
}
15901590

15911591
#[stable(feature = "cmp_os_str", since = "1.8.0")]
1592-
impl<'a, 'b> PartialOrd<$lhs> for $rhs {
1592+
impl PartialOrd<$lhs> for $rhs {
15931593
#[inline]
15941594
fn partial_cmp(&self, other: &$lhs) -> Option<cmp::Ordering> {
15951595
<OsStr as PartialOrd>::partial_cmp(self, other)
@@ -1599,10 +1599,10 @@ macro_rules! impl_cmp {
15991599
}
16001600

16011601
impl_cmp!(OsString, OsStr);
1602-
impl_cmp!(OsString, &'a OsStr);
1603-
impl_cmp!(Cow<'a, OsStr>, OsStr);
1604-
impl_cmp!(Cow<'a, OsStr>, &'b OsStr);
1605-
impl_cmp!(Cow<'a, OsStr>, OsString);
1602+
impl_cmp!(OsString, &OsStr);
1603+
impl_cmp!(Cow<'_, OsStr>, OsStr);
1604+
impl_cmp!(Cow<'_, OsStr>, &OsStr);
1605+
impl_cmp!(Cow<'_, OsStr>, OsString);
16061606

16071607
#[stable(feature = "rust1", since = "1.0.0")]
16081608
impl Hash for OsStr {

library/std/src/path.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3841,33 +3841,33 @@ impl<'a> IntoIterator for &'a Path {
38413841
}
38423842

38433843
macro_rules! impl_cmp {
3844-
(<$($life:lifetime),*> $lhs:ty, $rhs: ty) => {
3844+
($lhs:ty, $rhs: ty) => {
38453845
#[stable(feature = "partialeq_path", since = "1.6.0")]
3846-
impl<$($life),*> PartialEq<$rhs> for $lhs {
3846+
impl PartialEq<$rhs> for $lhs {
38473847
#[inline]
38483848
fn eq(&self, other: &$rhs) -> bool {
38493849
<Path as PartialEq>::eq(self, other)
38503850
}
38513851
}
38523852

38533853
#[stable(feature = "partialeq_path", since = "1.6.0")]
3854-
impl<$($life),*> PartialEq<$lhs> for $rhs {
3854+
impl PartialEq<$lhs> for $rhs {
38553855
#[inline]
38563856
fn eq(&self, other: &$lhs) -> bool {
38573857
<Path as PartialEq>::eq(self, other)
38583858
}
38593859
}
38603860

38613861
#[stable(feature = "cmp_path", since = "1.8.0")]
3862-
impl<$($life),*> PartialOrd<$rhs> for $lhs {
3862+
impl PartialOrd<$rhs> for $lhs {
38633863
#[inline]
38643864
fn partial_cmp(&self, other: &$rhs) -> Option<cmp::Ordering> {
38653865
<Path as PartialOrd>::partial_cmp(self, other)
38663866
}
38673867
}
38683868

38693869
#[stable(feature = "cmp_path", since = "1.8.0")]
3870-
impl<$($life),*> PartialOrd<$lhs> for $rhs {
3870+
impl PartialOrd<$lhs> for $rhs {
38713871
#[inline]
38723872
fn partial_cmp(&self, other: &$lhs) -> Option<cmp::Ordering> {
38733873
<Path as PartialOrd>::partial_cmp(self, other)
@@ -3876,40 +3876,40 @@ macro_rules! impl_cmp {
38763876
};
38773877
}
38783878

3879-
impl_cmp!(<> PathBuf, Path);
3880-
impl_cmp!(<'a> PathBuf, &'a Path);
3881-
impl_cmp!(<'a> Cow<'a, Path>, Path);
3882-
impl_cmp!(<'a, 'b> Cow<'a, Path>, &'b Path);
3883-
impl_cmp!(<'a> Cow<'a, Path>, PathBuf);
3879+
impl_cmp!(PathBuf, Path);
3880+
impl_cmp!(PathBuf, &Path);
3881+
impl_cmp!(Cow<'_, Path>, Path);
3882+
impl_cmp!(Cow<'_, Path>, &Path);
3883+
impl_cmp!(Cow<'_, Path>, PathBuf);
38843884

38853885
macro_rules! impl_cmp_os_str {
3886-
(<$($life:lifetime),*> $lhs:ty, $rhs: ty) => {
3886+
($lhs:ty, $rhs: ty) => {
38873887
#[stable(feature = "cmp_path", since = "1.8.0")]
3888-
impl<$($life),*> PartialEq<$rhs> for $lhs {
3888+
impl PartialEq<$rhs> for $lhs {
38893889
#[inline]
38903890
fn eq(&self, other: &$rhs) -> bool {
38913891
<Path as PartialEq>::eq(self, other.as_ref())
38923892
}
38933893
}
38943894

38953895
#[stable(feature = "cmp_path", since = "1.8.0")]
3896-
impl<$($life),*> PartialEq<$lhs> for $rhs {
3896+
impl PartialEq<$lhs> for $rhs {
38973897
#[inline]
38983898
fn eq(&self, other: &$lhs) -> bool {
38993899
<Path as PartialEq>::eq(self.as_ref(), other)
39003900
}
39013901
}
39023902

39033903
#[stable(feature = "cmp_path", since = "1.8.0")]
3904-
impl<$($life),*> PartialOrd<$rhs> for $lhs {
3904+
impl PartialOrd<$rhs> for $lhs {
39053905
#[inline]
39063906
fn partial_cmp(&self, other: &$rhs) -> Option<cmp::Ordering> {
39073907
<Path as PartialOrd>::partial_cmp(self, other.as_ref())
39083908
}
39093909
}
39103910

39113911
#[stable(feature = "cmp_path", since = "1.8.0")]
3912-
impl<$($life),*> PartialOrd<$lhs> for $rhs {
3912+
impl PartialOrd<$lhs> for $rhs {
39133913
#[inline]
39143914
fn partial_cmp(&self, other: &$lhs) -> Option<cmp::Ordering> {
39153915
<Path as PartialOrd>::partial_cmp(self.as_ref(), other)
@@ -3918,20 +3918,20 @@ macro_rules! impl_cmp_os_str {
39183918
};
39193919
}
39203920

3921-
impl_cmp_os_str!(<> PathBuf, OsStr);
3922-
impl_cmp_os_str!(<'a> PathBuf, &'a OsStr);
3923-
impl_cmp_os_str!(<'a> PathBuf, Cow<'a, OsStr>);
3924-
impl_cmp_os_str!(<> PathBuf, OsString);
3925-
impl_cmp_os_str!(<> Path, OsStr);
3926-
impl_cmp_os_str!(<'a> Path, &'a OsStr);
3927-
impl_cmp_os_str!(<'a> Path, Cow<'a, OsStr>);
3928-
impl_cmp_os_str!(<> Path, OsString);
3929-
impl_cmp_os_str!(<'a> &'a Path, OsStr);
3930-
impl_cmp_os_str!(<'a, 'b> &'a Path, Cow<'b, OsStr>);
3931-
impl_cmp_os_str!(<'a> &'a Path, OsString);
3932-
impl_cmp_os_str!(<'a> Cow<'a, Path>, OsStr);
3933-
impl_cmp_os_str!(<'a, 'b> Cow<'a, Path>, &'b OsStr);
3934-
impl_cmp_os_str!(<'a> Cow<'a, Path>, OsString);
3921+
impl_cmp_os_str!(PathBuf, OsStr);
3922+
impl_cmp_os_str!(PathBuf, &OsStr);
3923+
impl_cmp_os_str!(PathBuf, Cow<'_, OsStr>);
3924+
impl_cmp_os_str!(PathBuf, OsString);
3925+
impl_cmp_os_str!(Path, OsStr);
3926+
impl_cmp_os_str!(Path, &OsStr);
3927+
impl_cmp_os_str!(Path, Cow<'_, OsStr>);
3928+
impl_cmp_os_str!(Path, OsString);
3929+
impl_cmp_os_str!(&Path, OsStr);
3930+
impl_cmp_os_str!(&Path, Cow<'_, OsStr>);
3931+
impl_cmp_os_str!(&Path, OsString);
3932+
impl_cmp_os_str!(Cow<'_, Path>, OsStr);
3933+
impl_cmp_os_str!(Cow<'_, Path>, &OsStr);
3934+
impl_cmp_os_str!(Cow<'_, Path>, OsString);
39353935

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

tests/ui/inference/issue-72616.stderr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ LL | if String::from("a") == "a".try_into().unwrap() {}
88
|
99
= note: multiple `impl`s satisfying `String: PartialEq<_>` found in the following crates: `alloc`, `std`:
1010
- impl PartialEq for String;
11+
- impl PartialEq<ByteStr> for String;
12+
- impl PartialEq<ByteString> for String;
1113
- impl PartialEq<Path> for String;
1214
- impl PartialEq<PathBuf> for String;
15+
- impl PartialEq<str> for String;
1316
help: try using a fully qualified path to specify the expected types
1417
|
1518
LL - if String::from("a") == "a".try_into().unwrap() {}

0 commit comments

Comments
 (0)