nightly clippy fixes

This commit is contained in:
extrawurst 2022-09-02 09:09:29 +02:00
parent f308bddb77
commit 4249a278b6
13 changed files with 68 additions and 78 deletions

View file

@ -96,11 +96,7 @@ impl<J: 'static + AsyncJob> AsyncSingleJob<J> {
/// take out last finished job
pub fn take_last(&self) -> Option<J> {
if let Ok(mut last) = self.last.lock() {
last.take()
} else {
None
}
self.last.lock().map_or(None, |mut last| last.take())
}
/// spawns `task` if nothing is running currently,
@ -164,11 +160,7 @@ impl<J: 'static + AsyncJob> AsyncSingleJob<J> {
}
fn take_next(&self) -> Option<J> {
if let Ok(mut next) = self.next.lock() {
next.take()
} else {
None
}
self.next.lock().map_or(None, |mut next| next.take())
}
}

View file

@ -131,12 +131,12 @@ pub fn blame_file(
return (
Some(hunk),
line.unwrap_or_else(|_| "".into()),
line.unwrap_or_else(|_| String::new()),
);
}
}
(None, line.unwrap_or_else(|_| "".into()))
(None, line.unwrap_or_else(|_| String::new()))
})
.collect();

View file

@ -73,18 +73,19 @@ pub fn extract_username_password(
/// extract credentials from url
pub fn extract_cred_from_url(url: &str) -> BasicAuthCredential {
if let Ok(url) = url::Url::parse(url) {
BasicAuthCredential::new(
if url.username() == "" {
None
} else {
Some(url.username().to_owned())
},
url.password().map(std::borrow::ToOwned::to_owned),
)
} else {
BasicAuthCredential::new(None, None)
}
url::Url::parse(url).map_or_else(
|_| BasicAuthCredential::new(None, None),
|url| {
BasicAuthCredential::new(
if url.username() == "" {
None
} else {
Some(url.username().to_owned())
},
url.password().map(std::borrow::ToOwned::to_owned),
)
},
)
}
#[cfg(test)]

View file

@ -202,16 +202,15 @@ impl Callbacks {
}
match &self.basic_credential {
_ if allowed_types.is_ssh_key() => {
match username_from_url {
Some(username) => {
Cred::ssh_key_from_agent(username)
}
None => Err(GitError::from_str(
" Couldn't extract username from url.",
)),
}
}
_ if allowed_types.is_ssh_key() => username_from_url
.map_or_else(
|| {
Err(GitError::from_str(
" Couldn't extract username from url.",
))
},
Cred::ssh_key_from_agent,
),
Some(BasicAuthCredential {
username: Some(user),
password: Some(pwd),

View file

@ -13,9 +13,9 @@ pub fn reset_stage(repo_path: &RepoPath, path: &str) -> Result<()> {
let obj =
repo.find_object(id.into(), Some(ObjectType::Commit))?;
repo.reset_default(Some(&obj), &[path])?;
repo.reset_default(Some(&obj), [path])?;
} else {
repo.reset_default(None, &[path])?;
repo.reset_default(None, [path])?;
}
Ok(())

View file

@ -75,17 +75,20 @@ pub fn get_tags(repo_path: &RepoPath) -> Result<Tags> {
// works on annotated tags lightweight tags `id` already
// points to the target commit
// see https://github.com/libgit2/libgit2/issues/5586
let commit = if let Ok(commit) = repo
let commit = repo
.find_tag(id)
.and_then(|tag| tag.target())
.and_then(|target| target.peel_to_commit())
{
Some(CommitId::new(commit.id()))
} else if repo.find_commit(id).is_ok() {
Some(CommitId::new(id))
} else {
None
};
.map_or_else(
|_| {
if repo.find_commit(id).is_ok() {
Some(CommitId::new(id))
} else {
None
}
},
|commit| Some(CommitId::new(commit.id())),
);
let annotation = repo
.find_tag(id)

View file

@ -488,10 +488,9 @@ impl BlameFileComponent {
truncated_author,
author_width = MAX_AUTHOR_WIDTH
);
let time = blame_hunk.map_or_else(
|| "".into(),
|hunk| utils::time_to_string(hunk.time, true),
);
let time = blame_hunk.map_or_else(String::new, |hunk| {
utils::time_to_string(hunk.time, true)
});
let is_blamed_commit = self
.file_blame

View file

@ -292,10 +292,9 @@ impl CommitList {
// commit tags
txt.push(Span::styled(
Cow::from(tags.map_or_else(
|| String::from(""),
|tags| format!(" {}", tags),
)),
Cow::from(tags.map_or_else(String::new, |tags| {
format!(" {}", tags)
})),
theme.tags(selected),
));

View file

@ -126,7 +126,7 @@ impl RevisionFilesComponent {
let indent = item.info().indent();
let indent_str = if indent == 0 {
String::from("")
String::new()
} else {
format!("{:w$}", " ", w = (indent as usize) * 2)
};

View file

@ -159,7 +159,7 @@ impl StatusTreeComponent {
theme: &'b SharedTheme,
) -> Option<Span<'b>> {
let indent_str = if indent == 0 {
String::from("")
String::new()
} else {
format!("{:w$}", " ", w = (indent as usize) * 2)
};

View file

@ -96,7 +96,7 @@ impl KeyConfig {
KeyCode::Null => {
self.get_modifier_hint(ev.modifiers).into()
}
_ => "".into(),
_ => String::new(),
}
}

View file

@ -264,21 +264,21 @@ impl Status {
.join(",")
)
}
RepoState::Rebase => {
if let Ok(p) = sync::rebase_progress(repo) {
format!(
"Step: {}/{} Current Commit: {}",
p.current + 1,
p.steps,
p.current_commit
.as_ref()
.map(CommitId::get_short_string)
.unwrap_or_default(),
)
} else {
String::new()
}
}
RepoState::Rebase => sync::rebase_progress(repo)
.map_or_else(
|_| String::new(),
|p| {
format!(
"Step: {}/{} Current Commit: {}",
p.current + 1,
p.steps,
p.current_commit
.as_ref()
.map(CommitId::get_short_string)
.unwrap_or_default(),
)
},
),
RepoState::Revert => {
format!(
"Revert {}",

View file

@ -121,14 +121,11 @@ impl<'a> StatefulWidget for StatefulParagraph<'a> {
state: &mut Self::State,
) {
buf.set_style(area, self.style);
let text_area = match self.block.take() {
Some(b) => {
let inner_area = b.inner(area);
b.render(area, buf);
inner_area
}
None => area,
};
let text_area = self.block.take().map_or(area, |b| {
let inner_area = b.inner(area);
b.render(area, buf);
inner_area
});
if text_area.height < 1 {
return;