Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Nov 24, 2021
1 parent 2dca698 commit 74563fd
Show file tree
Hide file tree
Showing 28 changed files with 193 additions and 224 deletions.
2 changes: 1 addition & 1 deletion cargo-crev/src/crates_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Client {
}

fn store_in_cache<T: Cacheable + Serialize>(&self, path: &Path, resp: &T) -> Result<()> {
crev_common::store_to_file_with(&path, |file| serde_json::to_writer(file, &resp))??;
crev_common::store_to_file_with(path, |file| serde_json::to_writer(file, &resp))??;
Ok(())
}

Expand Down
6 changes: 3 additions & 3 deletions cargo-crev/src/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl std::ops::Add<OwnerSetSet> for OwnerSetSet {
type Output = Self;

fn add(self, other: Self) -> Self {
let mut set = self.0.clone();
let mut set = self.0;
for (k, v) in other.0 {
set.insert(k, v);
}
Expand Down Expand Up @@ -411,9 +411,9 @@ fn write_out_distrusted_ids_details(
) -> Result<()> {
for (distrusted_id, details) in &trust_set.distrusted {
for reported_by in &details.reported_by {
write!(
writeln!(
stderr,
"Note: {} was ignored as distrusted by {}\n",
"Note: {} was ignored as distrusted by {}",
distrusted_id, reported_by
)?;
}
Expand Down
32 changes: 14 additions & 18 deletions cargo-crev/src/deps/print_term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use crate::term::{self, *};

fn pad_left_manually(s: String, width: usize) -> String {
if s.len() <= width {
let padding = std::iter::repeat(" ")
.take(width - s.len())
.collect::<String>();
let padding = " ".repeat(width - s.len());
format!("{}{}", s, padding)
} else {
s
Expand Down Expand Up @@ -119,20 +117,18 @@ pub fn print_details(
),
None,
)?;
} else if let Some(known_owners) = &cdep.known_owners {
term.print(
format_args!("{:>2} ", known_owners.count),
term::known_owners_count_color(known_owners.count),
)?;
term.print(format_args!("{:>2} ", known_owners.total), None)?;
} else {
if let Some(known_owners) = &cdep.known_owners {
term.print(
format_args!("{:>2} ", known_owners.count),
term::known_owners_count_color(known_owners.count),
)?;
term.print(format_args!("{:>2} ", known_owners.total), None)?;
} else {
term.print(
format_args!("{:>2} ", "?"),
term::known_owners_count_color(0),
)?;
term.print(format_args!("{:>2} ", "?"), None)?;
}
term.print(
format_args!("{:>2} ", "?"),
term::known_owners_count_color(0),
)?;
term.print(format_args!("{:>2} ", "?"), None)?;
}
}

Expand Down Expand Up @@ -197,7 +193,7 @@ pub fn print_dep(
) -> Result<()> {
let details = stats.details();

print_details(&details, term, columns, recursive_mode)?;
print_details(details, term, columns, recursive_mode)?;
if columns.show_geiger() {
match details.accumulative.geiger_count {
Some(geiger_count) => print!("{:>6} ", geiger_count),
Expand Down Expand Up @@ -226,7 +222,7 @@ pub fn print_dep(
print!(
"{:<12}",
latest_trusted_version_string(
&stats.info.id.version(),
stats.info.id.version(),
&details.latest_trusted_version
)
);
Expand Down
12 changes: 6 additions & 6 deletions cargo-crev/src/deps/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,10 @@ impl Scanner {
};
let unclean_digest = digest
.as_ref()
.map(|digest| !is_digest_clean(&self.db, &pkg_name, &pkg_version, &digest))
.map(|digest| !is_digest_clean(&self.db, &pkg_name, pkg_version, digest))
.unwrap_or(false);
let verification_result = if let Some(digest) = digest.as_ref() {
crev_lib::verify_package_digest(&digest, &self.trust_set, &self.requirements, &self.db)
crev_lib::verify_package_digest(digest, &self.trust_set, &self.requirements, &self.db)
} else {
VerificationStatus::Local
};
Expand All @@ -290,7 +290,7 @@ impl Scanner {
.get_package_reviews_for_package(
PROJECT_SOURCE_CRATES_IO,
Some(&pkg_name),
Some(&info.id.version()),
Some(info.id.version()),
)
.collect();

Expand All @@ -304,7 +304,7 @@ impl Scanner {
};

let crates_io = self.crates_io()?;
let downloads = if required_details.downloads { crates_io.get_downloads_count(&pkg_name, &pkg_version).ok() } else { None };
let downloads = if required_details.downloads { crates_io.get_downloads_count(&pkg_name, pkg_version).ok() } else { None };

let owner_list = if required_details.owners { crates_io.get_owners(&pkg_name).ok() } else { None };
let known_owners = owner_list.as_ref().map(|owner_list| {
Expand All @@ -322,15 +322,15 @@ impl Scanner {
let issues_from_trusted = self.db.get_open_issues_for_version(
PROJECT_SOURCE_CRATES_IO,
&pkg_name,
&pkg_version,
pkg_version,
&self.trust_set,
self.requirements.trust_level.into(),
);

let issues_from_all = self.db.get_open_issues_for_version(
PROJECT_SOURCE_CRATES_IO,
&pkg_name,
&pkg_version,
pkg_version,
&self.trust_set,
crev_data::Level::None.into(),
);
Expand Down
15 changes: 7 additions & 8 deletions cargo-crev/src/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use anyhow::{bail, Result};
use crev_common::{run_with_shell_cmd, CancelledError};
use crev_data::{proof, proof::content::ContentExt};
use crev_lib::{local::Local, util::get_documentation_for};
use rprompt;
use std::{
env, ffi,
fmt::Write,
Expand Down Expand Up @@ -94,25 +93,25 @@ pub fn edit_proof_content_iteractively<C: proof::ContentWithDraft>(
) -> Result<C> {
let mut text = String::new();
if let Some(date) = previous_date {
write!(
writeln!(
&mut text,
"# Overwriting existing proof created on {}\n",
"# Overwriting existing proof created on {}",
date.to_rfc3339()
)?;
}
let draft = content.to_draft();

write!(&mut text, "# {}\n", draft.title())?;
writeln!(&mut text, "# {}", draft.title())?;
if let Some(extra_comment) = extra_comment {
write!(&mut text, "# {}\n", extra_comment)?;
writeln!(&mut text, "# {}", extra_comment)?;
}
if let Some(base_version) = base_version {
write!(&mut text, "# Diff base version: {}\n", base_version)?;
writeln!(&mut text, "# Diff base version: {}", base_version)?;
}
text.write_str(&draft.body())?;
text.write_str(draft.body())?;
text.write_str("\n\n")?;
for line in get_documentation_for(content).lines() {
write!(&mut text, "# {}\n", line)?;
writeln!(&mut text, "# {}", line)?;
}
loop {
text = edit_text_iteractively_until_writen_to(&text)?;
Expand Down
12 changes: 6 additions & 6 deletions cargo-crev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ fn run_command(command: opts::Command) -> Result<CommandExitStatus> {

// Fetch the URLs
for url in &urls {
local.fetch_url_into(&url, &mut db)?;
local.fetch_url_into(url, &mut db)?;
}

// Make reverse lookup for Ids based on their URLs
Expand Down Expand Up @@ -598,9 +598,9 @@ fn run_command(command: opts::Command) -> Result<CommandExitStatus> {
if args.reset_date {
content.set_date(&now);
}
content.set_author(&id.as_public_id());
content.set_author(id.as_public_id());
let proof = content.sign_by(&id)?;
maybe_store(&local, &proof, &commit_msg, &args.common)?;
maybe_store(&local, &proof, commit_msg, &args.common)?;
}
Err(e) => {
eprintln!("Ignoried unknwon proof - {}", e);
Expand Down Expand Up @@ -646,7 +646,7 @@ fn validate_public_repo_url(url: &str) -> Result<()> {
fn current_id_set_url(url: &str, use_https_push: bool) -> Result<(), crev_lib::Error> {
let local = Local::auto_open()?;
let mut locked_id = local.read_current_locked_id()?;
let pub_id = locked_id.to_public_id().id.clone();
let pub_id = locked_id.to_public_id().id;
local.change_locked_id_url(&mut locked_id, url, use_https_push)?;
local.save_current_id(&pub_id)?;
local.fetch_trusted(opts::TrustDistanceParams::default().into(), None)?;
Expand Down Expand Up @@ -809,7 +809,7 @@ fn ensure_crev_id_exists_or_make_one() -> Result<Local> {
fn ids_from_string(id_strings: &[String]) -> Result<Vec<Id>> {
id_strings
.iter()
.map(|s| match Id::crevid_from_str(&s) {
.map(|s| match Id::crevid_from_str(s) {
Ok(s) => Ok(s),
Err(e) => bail!("'{}' is not a valid crev Id: {}", s, e),
})
Expand Down Expand Up @@ -860,7 +860,7 @@ fn change_passphrase(
unlocked_id: &UnlockedId,
passphrase: &str,
) -> Result<LockedId> {
let locked_id = LockedId::from_unlocked_id(&unlocked_id, passphrase)?;
let locked_id = LockedId::from_unlocked_id(unlocked_id, passphrase)?;

local.save_locked_id(&locked_id)?;
local.save_current_id(unlocked_id.as_ref())?;
Expand Down
24 changes: 9 additions & 15 deletions cargo-crev/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ impl Repo {
.unwrap_or_else(String::new)
.split(',')
.map(String::from)
.filter(|s| s != "")
.filter(|s| !s.is_empty())
.collect();

Ok(Repo {
Expand Down Expand Up @@ -362,11 +362,7 @@ impl Repo {
let rustc = self.config.load_global_rustc(Some(&workspace))?;
let host = rustc.host.to_string();

let target = if let Some(ref target) = self.cargo_opts.target {
Some(target.as_ref().unwrap_or(&host).as_str())
} else {
None
};
let target = self.cargo_opts.target.as_ref().map(|target| target.as_ref().unwrap_or(&host).as_str());

let cfgs = get_cfgs(&rustc, target)?;
let graph = build_graph(&resolve, &packages, roots.into_iter(), target, &cfgs)?;
Expand All @@ -386,7 +382,7 @@ impl Repo {
let crates_io = crates_io::Client::new(&local)?;

self.for_every_non_local_dep_crate(|crate_| {
let _ = crates_io.get_downloads_count(&crate_.name(), &crate_.version());
let _ = crates_io.get_downloads_count(&crate_.name(), crate_.version());
Ok(())
})?;

Expand Down Expand Up @@ -449,7 +445,7 @@ impl Repo {
source.download(pkg.package_id())?;
}

f(&pkg)?;
f(pkg)?;
}

Ok(())
Expand Down Expand Up @@ -510,14 +506,14 @@ impl Repo {

let mut registry = self.registry(vec![].into_iter())?;

Ok(our_resolve(
our_resolve(
&mut registry,
&workspace,
&self.features_list,
self.cargo_opts.all_features,
self.cargo_opts.no_default_features,
self.cargo_opts.no_dev_dependencies,
)?)
)
}

pub fn find_dependency_pkg_id_by_selector(
Expand All @@ -529,7 +525,7 @@ impl Repo {

self.for_every_non_local_dep_crate_id(|pkg_id| {
if name == pkg_id.name().as_str()
&& (version.is_none() || version == Some(&pkg_id.version()))
&& (version.is_none() || version == Some(pkg_id.version()))
{
ret.push(pkg_id.to_owned());
}
Expand Down Expand Up @@ -582,9 +578,7 @@ impl Repo {
let dependency_request =
Dependency::parse(name, version_str.as_deref(), source.source_id())?;
let _lock = self.config.acquire_package_cache_lock()?;
source.query(&dependency_request, &mut |summary| {
summaries.push(summary.clone())
})?;
source.query(&dependency_request, &mut |summary| summaries.push(summary))?;
let summary = if let Some(version) = version {
summaries.iter().find(|s| s.version() == version)
} else {
Expand All @@ -606,7 +600,7 @@ impl Repo {
.ok_or_else(|| format_err!("Could not find requested crate. Try updating cargo's registry index cache?"))?
)
} else {
Ok(self.find_dependency_pkg_id_by_selector(&name, version)?
Ok(self.find_dependency_pkg_id_by_selector(name, version)?
.ok_or_else(|| format_err!("Could not find requested crate. Try `-u` if the crate is not a dependency."))?
)
}
Expand Down
12 changes: 6 additions & 6 deletions cargo-crev/src/review.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ pub fn create_review_proof(
let diff_base_version = match crate_review_activity_check(
&local,
&pkg_id.name(),
&effective_crate_version,
&diff_version,
effective_crate_version,
diff_version,
skip_activity_check,
) {
Ok(res) => res,
Expand Down Expand Up @@ -76,15 +76,15 @@ pub fn create_review_proof(
};

let (digest_clean, vcs) =
check_package_clean_state(&repo, &crate_root, &crate_.name(), &effective_crate_version)?;
check_package_clean_state(&repo, crate_root, &crate_.name(), effective_crate_version)?;

let diff_base = if let Some(ref diff_base_version) = diff_base_version {
let crate_id = repo.find_pkgid(&crate_.name(), Some(diff_base_version), true)?;
let crate_ = repo.get_crate(&crate_id)?;
let crate_root = crate_.root();

let (digest, vcs) =
check_package_clean_state(&repo, &crate_root, &crate_.name(), &diff_base_version)?;
check_package_clean_state(&repo, crate_root, &crate_.name(), diff_base_version)?;

Some(proof::PackageInfo {
id: proof::PackageVersionId::new(
Expand Down Expand Up @@ -208,7 +208,7 @@ pub fn find_previous_review_data(
));
} else if let Some(diff_base_version) = diff_base_version {
if let Some(base_review) =
db.get_pkg_review(PROJECT_SOURCE_CRATES_IO, name, &diff_base_version, &id.id)
db.get_pkg_review(PROJECT_SOURCE_CRATES_IO, name, diff_base_version, &id.id)
{
return Some((
None,
Expand All @@ -228,7 +228,7 @@ pub fn find_reviews(crate_: &opts::CrateSelector) -> Result<Vec<proof::review::P
Ok(db
.get_package_reviews_for_package(
PROJECT_SOURCE_CRATES_IO,
crate_.name.as_ref().map(String::as_str),
crate_.name.as_deref(),
crate_.version()?,
)
.cloned()
Expand Down
Loading

0 comments on commit 74563fd

Please sign in to comment.