chore: update rust toolchain 1.84

Fixed clippy warnings for lifetime elision and preferring `Display`
implementations over `ToString`.
This commit is contained in:
Fintan Halpenny
2025-02-10 14:11:28 +00:00
parent 41e3f30ffc
commit 527fddfd4d
20 changed files with 64 additions and 69 deletions
@@ -24,7 +24,7 @@ impl<'de: 'a, 'a> Decode<'de> for &'a RefStr {
}
}
impl<'a> Encode for &'a RefStr {
impl Encode for &RefStr {
#[inline]
fn encode<W: Write>(&self, e: &mut Encoder<W>) -> Result<(), encode::Error<W::Error>> {
e.str(self.as_str())?;
@@ -54,7 +54,7 @@ impl<'de: 'a, 'a> Decode<'de> for &'a PatternStr {
}
}
impl<'a> Encode for &'a PatternStr {
impl Encode for &PatternStr {
#[inline]
fn encode<W: Write>(&self, e: &mut Encoder<W>) -> Result<(), encode::Error<W::Error>> {
e.str(self.as_str())?;
@@ -86,7 +86,7 @@ impl<'de: 'a, 'a> Decode<'de> for Qualified<'a> {
}
}
impl<'a> Encode for Qualified<'a> {
impl Encode for Qualified<'_> {
#[inline]
fn encode<W: Write>(&self, e: &mut Encoder<W>) -> Result<(), encode::Error<W::Error>> {
self.as_str().encode(e)
@@ -103,7 +103,7 @@ impl<'de: 'a, 'a> Decode<'de> for Namespaced<'a> {
}
}
impl<'a> Encode for Namespaced<'a> {
impl Encode for Namespaced<'_> {
#[inline]
fn encode<W: Write>(&self, e: &mut Encoder<W>) -> Result<(), encode::Error<W::Error>> {
self.as_str().encode(e)
@@ -213,7 +213,7 @@ impl AsRef<bstr::BStr> for RefStr {
}
}
impl<'a> AsRef<RefStr> for &'a RefStr {
impl AsRef<RefStr> for &RefStr {
#[inline]
fn as_ref(&self) -> &RefStr {
self
@@ -34,7 +34,7 @@ impl<'a> Iterator for Components<'a> {
}
}
impl<'a> DoubleEndedIterator for Components<'a> {
impl DoubleEndedIterator for Components<'_> {
#[inline]
fn next_back(&mut self) -> Option<Self::Item> {
self.inner
@@ -83,7 +83,7 @@ impl<'a> Component<'a> {
}
}
impl<'a> Deref for Component<'a> {
impl Deref for Component<'_> {
type Target = RefStr;
#[inline]
@@ -66,7 +66,7 @@ impl<'a> Iterator for Components<'a> {
}
}
impl<'a> DoubleEndedIterator for Components<'a> {
impl DoubleEndedIterator for Components<'_> {
#[inline]
fn next_back(&mut self) -> Option<Self::Item> {
self.inner.next_back().map(|next| match next {
@@ -23,7 +23,7 @@ impl<'de: 'a, 'a> Deserialize<'de> for &'a RefStr {
}
}
impl<'a> Serialize for &'a RefStr {
impl Serialize for &RefStr {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -65,7 +65,7 @@ impl<'de: 'a, 'a> Deserialize<'de> for &'a PatternStr {
}
}
impl<'a> Serialize for &'a PatternStr {
impl Serialize for &PatternStr {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
+1 -1
View File
@@ -47,7 +47,7 @@ impl<'a> From<&'a str> for Branch<'a> {
}
}
impl<'a> From<String> for Branch<'a> {
impl From<String> for Branch<'_> {
fn from(s: String) -> Self {
Self::Name(Cow::Owned(s))
}
+16 -22
View File
@@ -14,10 +14,8 @@
pub mod headers;
pub mod trailers;
use std::{
fmt::Write as _,
str::{self, FromStr},
};
use core::fmt;
use std::str::{self, FromStr};
use git2::{ObjectType, Oid};
@@ -139,7 +137,7 @@ impl<Tree, Parent> CommitData<Tree, Parent> {
}
/// Iterate over the [`Headers`] values that match the provided `name`.
pub fn values<'a>(&'a self, name: &'a str) -> impl Iterator<Item = &'a str> + '_ {
pub fn values<'a>(&'a self, name: &'a str) -> impl Iterator<Item = &'a str> + 'a {
self.headers.values(name)
}
@@ -367,32 +365,28 @@ impl FromStr for Commit {
}
}
impl ToString for Commit {
fn to_string(&self) -> String {
let mut buf = String::new();
writeln!(buf, "tree {}", self.tree).ok();
impl fmt::Display for Commit {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "tree {}", self.tree)?;
for parent in self.parents() {
writeln!(buf, "parent {parent}").ok();
writeln!(f, "parent {parent}")?;
}
writeln!(buf, "author {}", self.author).ok();
writeln!(buf, "committer {}", self.committer).ok();
writeln!(f, "author {}", self.author)?;
writeln!(f, "committer {}", self.committer)?;
for (name, value) in self.headers.iter() {
writeln!(buf, "{name} {}", value.replace('\n', "\n ")).ok();
writeln!(f, "{name} {}", value.replace('\n', "\n "))?;
}
writeln!(buf).ok();
write!(buf, "{}", self.message.trim()).ok();
writeln!(buf).ok();
writeln!(f)?;
write!(f, "{}", self.message.trim())?;
writeln!(f)?;
if !self.trailers.is_empty() {
writeln!(buf).ok();
writeln!(f)?;
}
for trailer in self.trailers.iter() {
writeln!(buf, "{}", Trailer::from(trailer).display(": ")).ok();
writeln!(f, "{}", Trailer::from(trailer).display(": "))?;
}
buf
Ok(())
}
}
+8 -7
View File
@@ -1,3 +1,4 @@
use core::fmt;
use std::borrow::Cow;
const BEGIN_SSH: &str = "-----BEGIN SSH SIGNATURE-----\n";
@@ -30,17 +31,17 @@ impl<'a> Signature<'a> {
}
}
pub struct UnknownScheme;
impl<'a> ToString for Signature<'a> {
fn to_string(&self) -> String {
impl fmt::Display for Signature<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Signature::Pgp(pgp) => pgp.to_string(),
Signature::Ssh(ssh) => ssh.to_string(),
Signature::Pgp(pgp) => f.write_str(pgp.as_ref()),
Signature::Ssh(ssh) => f.write_str(ssh.as_ref()),
}
}
}
pub struct UnknownScheme;
impl Headers {
pub fn new() -> Self {
Headers(Vec::new())
@@ -50,7 +51,7 @@ impl Headers {
self.0.iter().map(|(k, v)| (k.as_str(), v.as_str()))
}
pub fn values<'a>(&'a self, name: &'a str) -> impl Iterator<Item = &'a str> + '_ {
pub fn values<'a>(&'a self, name: &'a str) -> impl Iterator<Item = &'a str> + 'a {
self.iter()
.filter_map(move |(k, v)| (k == name).then_some(v))
}
+1 -1
View File
@@ -148,7 +148,7 @@ pub struct Display<'a> {
separator: &'a str,
}
impl<'a> fmt::Display for Display<'a> {
impl fmt::Display for Display<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
+1 -1
View File
@@ -35,7 +35,7 @@ mod serde_impls {
{
struct OidVisitor;
impl<'de> Visitor<'de> for OidVisitor {
impl Visitor<'_> for OidVisitor {
type Value = Oid;
fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result {
+2 -2
View File
@@ -99,7 +99,7 @@ pub struct BlobRef<'a> {
pub(crate) inner: git2::Blob<'a>,
}
impl<'a> BlobRef<'a> {
impl BlobRef<'_> {
pub fn id(&self) -> Oid {
self.inner.id().into()
}
@@ -149,7 +149,7 @@ where
}
#[cfg(feature = "serde")]
impl<'a> Serialize for BlobRef<'a> {
impl Serialize for BlobRef<'_> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
+2 -2
View File
@@ -113,7 +113,7 @@ impl std::fmt::Debug for Author {
}
}
impl<'repo> TryFrom<git2::Signature<'repo>> for Author {
impl TryFrom<git2::Signature<'_>> for Author {
type Error = str::Utf8Error;
fn try_from(signature: git2::Signature) -> Result<Self, Self::Error> {
@@ -182,7 +182,7 @@ impl Serialize for Commit {
}
}
impl<'repo> TryFrom<git2::Commit<'repo>> for Commit {
impl TryFrom<git2::Commit<'_>> for Commit {
type Error = Error;
fn try_from(commit: git2::Commit) -> Result<Self, Self::Error> {
+3 -3
View File
@@ -99,7 +99,7 @@ pub mod error {
}
}
impl<'a> TryFrom<git2::DiffFile<'a>> for DiffFile {
impl TryFrom<git2::DiffFile<'_>> for DiffFile {
type Error = error::FileMode;
fn try_from(value: git2::DiffFile) -> Result<Self, Self::Error> {
@@ -205,7 +205,7 @@ impl TryFrom<git2::Patch<'_>> for DiffContent {
}
}
impl<'a> TryFrom<git2::DiffLine<'a>> for Modification {
impl TryFrom<git2::DiffLine<'_>> for Modification {
type Error = error::Modification;
fn try_from(line: git2::DiffLine) -> Result<Self, Self::Error> {
@@ -228,7 +228,7 @@ impl From<git2::DiffStats> for Stats {
}
}
impl<'a> TryFrom<git2::Diff<'a>> for Diff {
impl TryFrom<git2::Diff<'_>> for Diff {
type Error = error::Diff;
fn try_from(git_diff: git2::Diff) -> Result<Diff, Self::Error> {
+2 -2
View File
@@ -74,7 +74,7 @@ impl<'a> History<'a> {
}
}
impl<'a> Iterator for History<'a> {
impl Iterator for History<'_> {
type Item = Result<Commit, Error>;
fn next(&mut self) -> Option<Self::Item> {
@@ -108,7 +108,7 @@ impl<'a> Iterator for History<'a> {
}
}
impl<'a> std::fmt::Debug for History<'a> {
impl std::fmt::Debug for History<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "History of {}", self.head.id)
}
+5 -5
View File
@@ -32,7 +32,7 @@ impl<'a> Tags<'a> {
}
}
impl<'a> Iterator for Tags<'a> {
impl Iterator for Tags<'_> {
type Item = Result<Tag, error::Tag>;
fn next(&mut self) -> Option<Self::Item> {
@@ -54,7 +54,7 @@ impl<'a> Iterator for Tags<'a> {
}
}
impl<'a> Iterator for TagNames<'a> {
impl Iterator for TagNames<'_> {
type Item = Result<Qualified<'static>, error::Tag>;
fn next(&mut self) -> Option<Self::Item> {
@@ -99,7 +99,7 @@ impl<'a> Branches<'a> {
}
}
impl<'a> Iterator for Branches<'a> {
impl Iterator for Branches<'_> {
type Item = Result<Branch, error::Branch>;
fn next(&mut self) -> Option<Self::Item> {
@@ -121,7 +121,7 @@ impl<'a> Iterator for Branches<'a> {
}
}
impl<'a> Iterator for BranchNames<'a> {
impl Iterator for BranchNames<'_> {
type Item = Result<Qualified<'static>, error::Branch>;
fn next(&mut self) -> Option<Self::Item> {
@@ -177,7 +177,7 @@ impl<'a> Categories<'a> {
}
}
impl<'a> Iterator for Categories<'a> {
impl Iterator for Categories<'_> {
type Item = Result<(RefString, RefString), error::Category>;
fn next(&mut self) -> Option<Self::Item> {
+1 -1
View File
@@ -58,7 +58,7 @@ fn browse_repo_lazily() {
#[test]
fn test_file_history() {
let repo = Repository::open(GIT_PLATINUM).unwrap();
let history = repo.history(&Branch::local(refname!("dev"))).unwrap();
let history = repo.history(Branch::local(refname!("dev"))).unwrap();
let path = Path::new("README.md");
let mut file_history = history.by_path(&path);
let commit = file_history.next().unwrap().unwrap();
+2 -2
View File
@@ -101,7 +101,7 @@ fn root() {
.map(|commit| commit.id);
let expected_oid = repo
.history(&Branch::local(refname!("master")))
.history(Branch::local(refname!("master")))
.unwrap()
.head()
.id;
@@ -112,7 +112,7 @@ fn root() {
fn binary_file() {
let repo = Repository::open(GIT_PLATINUM)
.expect("Could not retrieve ./data/git-platinum as git repository");
let history = repo.history(&Branch::local(refname!("dev"))).unwrap();
let history = repo.history(Branch::local(refname!("dev"))).unwrap();
let file_commit = history.by_path(&"bin/cat").next();
assert!(file_commit.is_some());
println!("file commit: {:?}", &file_commit);
+8 -8
View File
@@ -7,9 +7,9 @@ use super::GIT_PLATINUM;
#[test]
fn switch_to_banana() -> Result<(), Error> {
let repo = Repository::open(GIT_PLATINUM)?;
let history_master = repo.history(&Branch::local(refname!("master")))?;
let history_master = repo.history(Branch::local(refname!("master")))?;
repo.switch_namespace(&refname!("golden"))?;
let history_banana = repo.history(&Branch::local(refname!("banana")))?;
let history_banana = repo.history(Branch::local(refname!("banana")))?;
assert_ne!(history_master.head(), history_banana.head());
@@ -19,14 +19,14 @@ fn switch_to_banana() -> Result<(), Error> {
#[test]
fn me_namespace() -> Result<(), Error> {
let repo = Repository::open(GIT_PLATINUM)?;
let history = repo.history(&Branch::local(refname!("master")))?;
let history = repo.history(Branch::local(refname!("master")))?;
assert_eq!(repo.which_namespace().unwrap(), None);
repo.switch_namespace(&refname!("me"))?;
assert_eq!(repo.which_namespace().unwrap(), Some("me".parse()?));
let history_feature = repo.history(&Branch::local(refname!("feature/#1194")))?;
let history_feature = repo.history(Branch::local(refname!("feature/#1194")))?;
assert_eq!(history.head(), history_feature.head());
let expected_branches: Vec<Branch> = vec![Branch::local(refname!("feature/#1194"))];
@@ -54,7 +54,7 @@ fn me_namespace() -> Result<(), Error> {
#[test]
fn golden_namespace() -> Result<(), Error> {
let repo = Repository::open(GIT_PLATINUM)?;
let history = repo.history(&Branch::local(refname!("master")))?;
let history = repo.history(Branch::local(refname!("master")))?;
assert_eq!(repo.which_namespace().unwrap(), None);
@@ -62,7 +62,7 @@ fn golden_namespace() -> Result<(), Error> {
assert_eq!(repo.which_namespace().unwrap(), Some("golden".parse()?));
let golden_history = repo.history(&Branch::local(refname!("master")))?;
let golden_history = repo.history(Branch::local(refname!("master")))?;
assert_eq!(history.head(), golden_history.head());
let expected_branches: Vec<Branch> = vec![
@@ -97,7 +97,7 @@ fn golden_namespace() -> Result<(), Error> {
#[test]
fn silver_namespace() -> Result<(), Error> {
let repo = Repository::open(GIT_PLATINUM)?;
let history = repo.history(&Branch::local(refname!("master")))?;
let history = repo.history(Branch::local(refname!("master")))?;
assert_eq!(repo.which_namespace().unwrap(), None);
@@ -106,7 +106,7 @@ fn silver_namespace() -> Result<(), Error> {
repo.which_namespace().unwrap(),
Some("golden/silver".parse()?)
);
let silver_history = repo.history(&Branch::local(refname!("master")))?;
let silver_history = repo.history(Branch::local(refname!("master")))?;
assert_ne!(history.head(), silver_history.head());
let expected_branches: Vec<Branch> = vec![Branch::local(refname!("master"))];
+1 -1
View File
@@ -19,7 +19,7 @@ use super::GIT_PLATINUM;
#[test]
fn _master() -> Result<(), Error> {
let repo = Repository::open(GIT_PLATINUM)?;
let mut history = repo.history(&Branch::remote(component!("origin"), refname!("master")))?;
let mut history = repo.history(Branch::remote(component!("origin"), refname!("master")))?;
let commit1 = Oid::from_str("3873745c8f6ffb45c990eb23b491d4b4b6182f95")?;
assert!(
+1 -1
View File
@@ -1 +1 @@
1.76
1.84