clippy: explicit lifetimes

With Rust 1.89.0, there was introduction to the mismatched lifetime
syntax lint[^1].

The suggestion is to use implicit lifetimes via `<'_>`, however, to
maintain the MSRV, the lifetimes are made explicit here by introducing
an (or using the existing) `'a` lifetime.

[^1]: https://blog.rust-lang.org/2025/08/07/Rust-1.89.0/#mismatched-lifetime-syntaxes-lint
This commit is contained in:
Fintan Halpenny
2025-12-08 15:11:21 +00:00
parent 320f316674
commit 68d6fa879f
10 changed files with 52 additions and 37 deletions
@@ -73,7 +73,7 @@ impl<'a> Qualified<'a> {
Qualified(self.0.join(other).into())
}
pub fn to_pattern<P>(&self, pattern: P) -> QualifiedPattern
pub fn to_pattern<P>(&'a self, pattern: P) -> QualifiedPattern<'a>
where
P: AsRef<PatternStr>,
{
@@ -81,7 +81,7 @@ impl<'a> Qualified<'a> {
}
#[inline]
pub fn to_namespaced(&self) -> Option<Namespaced> {
pub fn to_namespaced(&'a self) -> Option<Namespaced<'a>> {
self.0.as_ref().into()
}
@@ -98,7 +98,7 @@ impl<'a> Qualified<'a> {
}
/// Like [`Self::non_empty_components`], but with string slices.
pub fn non_empty_iter(&self) -> (&str, &str, &str, name::Iter) {
pub fn non_empty_iter(&'a self) -> (&'a str, &'a str, &'a str, name::Iter<'a>) {
let mut iter = self.iter();
(
iter.next().unwrap(),
@@ -114,7 +114,14 @@ impl<'a> Qualified<'a> {
/// A qualified ref is guaranteed to have at least three components, which
/// this method provides a witness of. This is useful eg. for pattern
/// matching on the prefix.
pub fn non_empty_components(&self) -> (Component, Component, Component, name::Components) {
pub fn non_empty_components(
&'a self,
) -> (
Component<'a>,
Component<'a>,
Component<'a>,
name::Components<'a>,
) {
let mut cs = self.components();
(
cs.next().unwrap(),
@@ -287,7 +294,7 @@ impl Display for Qualified<'_> {
pub struct Namespaced<'a>(Cow<'a, RefStr>);
impl<'a> Namespaced<'a> {
pub fn namespace(&self) -> Component {
pub fn namespace(&'a self) -> Component<'a> {
self.components().nth(2).unwrap()
}
@@ -130,24 +130,24 @@ impl RefStr {
}
#[inline]
pub fn qualified(&self) -> Option<Qualified> {
pub fn qualified<'a>(&'a self) -> Option<Qualified<'a>> {
Qualified::from_refstr(self)
}
#[inline]
pub fn to_namespaced(&self) -> Option<Namespaced> {
pub fn to_namespaced<'a>(&'a self) -> Option<Namespaced<'a>> {
self.into()
}
pub fn iter(&self) -> Iter {
pub fn iter<'a>(&'a self) -> Iter<'a> {
self.0.split('/')
}
pub fn components(&self) -> Components {
pub fn components<'a>(&'a self) -> Components<'a> {
Components::from(self)
}
pub fn head(&self) -> Component {
pub fn head<'a>(&'a self) -> Component<'a> {
self.components().next().expect("`RefStr` cannot be empty")
}
@@ -49,22 +49,22 @@ impl PatternStr {
}
#[inline]
pub fn qualified(&self) -> Option<QualifiedPattern> {
pub fn qualified<'a>(&'a self) -> Option<QualifiedPattern<'a>> {
QualifiedPattern::from_patternstr(self)
}
#[inline]
pub fn to_namespaced(&self) -> Option<NamespacedPattern> {
pub fn to_namespaced<'a>(&'a self) -> Option<NamespacedPattern<'a>> {
self.into()
}
#[inline]
pub fn iter(&self) -> Iter {
pub fn iter<'a>(&'a self) -> Iter<'a> {
self.0.split('/')
}
#[inline]
pub fn components(&self) -> Components {
pub fn components<'a>(&'a self) -> Components<'a> {
Components::from(self)
}
@@ -333,7 +333,7 @@ impl<'a> QualifiedPattern<'a> {
}
#[inline]
pub fn to_namespaced(&self) -> Option<NamespacedPattern> {
pub fn to_namespaced(&'a self) -> Option<NamespacedPattern<'a>> {
self.0.as_ref().into()
}
@@ -353,7 +353,7 @@ impl<'a> QualifiedPattern<'a> {
}
/// Like [`Self::non_empty_components`], but with string slices.
pub fn non_empty_iter(&self) -> (&str, &str, &str, Iter) {
pub fn non_empty_iter(&'a self) -> (&'a str, &'a str, &'a str, Iter<'a>) {
let mut iter = self.iter();
(
iter.next().unwrap(),
@@ -369,7 +369,9 @@ impl<'a> QualifiedPattern<'a> {
/// A qualified ref is guaranteed to have at least three components, which
/// this method provides a witness of. This is useful eg. for pattern
/// matching on the prefix.
pub fn non_empty_components(&self) -> (Component, Component, Component, Components) {
pub fn non_empty_components(
&'a self,
) -> (Component<'a>, Component<'a>, Component<'a>, Components<'a>) {
let mut cs = self.components();
(
cs.next().unwrap(),
@@ -480,7 +482,7 @@ impl From<QualifiedPattern<'_>> for PatternString {
pub struct NamespacedPattern<'a>(Cow<'a, PatternStr>);
impl<'a> NamespacedPattern<'a> {
pub fn namespace(&self) -> Component {
pub fn namespace(&'a self) -> Component<'a> {
self.components().nth(2).unwrap()
}