Skip to content

Commit

Permalink
Merge pull request #344 from ffranr/lint
Browse files Browse the repository at this point in the history
Apply clippy lint.
  • Loading branch information
ffranr authored May 8, 2020
2 parents 850c381 + f25380d commit dc0011d
Show file tree
Hide file tree
Showing 18 changed files with 40 additions and 71 deletions.
1 change: 0 additions & 1 deletion cargo-crev/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use cargo::{
};
use cargo_platform::Cfg;
use crev_common::convert::OptionDeref;
use crev_lib;
use failure::format_err;
use petgraph::graph::NodeIndex;
use std::{
Expand Down
1 change: 0 additions & 1 deletion cargo-crev/src/review.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::{
};
use crev_data::proof::{self, ContentExt};
use crev_lib::TrustProofType;
use crev_wot;

use crate::{repo::*, shared::*};

Expand Down
4 changes: 0 additions & 4 deletions crev-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ pub mod serde;

pub use crate::blake2b256::Blake2b256;

use blake2;
use chrono;
use failure::bail;

use blake2::{digest::FixedOutput, Digest};
use failure::format_err;
use rpassword;
use rprompt;
use std::{
collections::HashSet,
env,
Expand Down
1 change: 0 additions & 1 deletion crev-common/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use serde;
use self::serde::Deserialize;
use chrono::{self, offset::FixedOffset, prelude::*};
use hex::{self, FromHex, FromHexError};
use serde_yaml;
use std::{fmt, io};

// {{{ Serde serialization
Expand Down
2 changes: 1 addition & 1 deletion crev-data/src/proof/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Some common stuff for both Review and Trust Proofs
use chrono::{self, prelude::*};
use crev_common;

use failure::bail;
use std::{
default, fmt,
Expand Down
6 changes: 1 addition & 5 deletions crev-data/src/proof/review/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@ impl proof::CommonOps for Code {

fn kind(&self) -> &str {
// Backfill the `kind` if it is empty (legacy format)
self.common
.kind
.as_ref()
.map(|s| s.as_str())
.unwrap_or(Self::KIND)
self.common.kind.as_deref().unwrap_or(Self::KIND)
}
}

Expand Down
8 changes: 2 additions & 6 deletions crev-data/src/proof/review/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use failure::bail;
use proof::{CommonOps, Content};
use semver::Version;
use serde::{Deserialize, Serialize};
use serde_yaml;

use std::{collections::HashSet, default::Default, fmt, ops};
use typed_builder::TypedBuilder;

Expand Down Expand Up @@ -120,11 +120,7 @@ impl proof::CommonOps for Package {

fn kind(&self) -> &str {
// Backfill the `kind` if it is empty (legacy format)
self.common
.kind
.as_ref()
.map(|s| s.as_str())
.unwrap_or(Self::KIND)
self.common.kind.as_deref().unwrap_or(Self::KIND)
}
}

Expand Down
10 changes: 3 additions & 7 deletions crev-data/src/proof/trust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use crate::{
proof::{self, CommonOps, Content},
serde_content_serialize, serde_draft_serialize, Level, Result,
};
use crev_common;

use derive_builder::Builder;
use failure::bail;
use serde::{Deserialize, Serialize};
use serde_yaml;

use std::fmt;

const CURRENT_TRUST_PROOF_SERIALIZATION_VERSION: i64 = -1;
Expand Down Expand Up @@ -111,11 +111,7 @@ impl proof::CommonOps for Trust {

fn kind(&self) -> &str {
// Backfill the `kind` if it is empty (legacy format)
self.common
.kind
.as_ref()
.map(|s| s.as_str())
.unwrap_or(Self::KIND)
self.common.kind.as_deref().unwrap_or(Self::KIND)
}
}

Expand Down
10 changes: 4 additions & 6 deletions crev-data/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,15 @@ pub fn ensure_serializes_to_valid_proof_works() -> Result<()> {
"name".into(),
Version::parse("1.0.0").unwrap(),
),
digest: digest.clone(),
digest,
digest_type: proof::default_digest_type(),
revision: "".into(),
revision_type: proof::default_revision_type(),
};

let mut package = a.as_pubid().create_package_review_proof(
package.clone(),
Default::default(),
"a".into(),
)?;
let mut package =
a.as_pubid()
.create_package_review_proof(package, Default::default(), "a".into())?;
assert!(package.ensure_serializes_to_valid_proof().is_ok());
package.comment = std::iter::repeat("a").take(32_000).collect::<String>();
assert!(package.ensure_serializes_to_valid_proof().is_err());
Expand Down
5 changes: 2 additions & 3 deletions crev-lib/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ use crev_common::{
};
use crev_data::id::{OwnId, PubId};
use failure::{bail, format_err};
use miscreant;
use num_cpus;

use serde::{Deserialize, Serialize};
use serde_yaml;

use std::{self, fmt, io::Write, path::Path};

const CURRENT_LOCKED_ID_SERIALIZATION_VERSION: i64 = -1;
Expand Down
2 changes: 1 addition & 1 deletion crev-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crev_data::{
},
Digest, Id,
};
use crev_wot;

pub use crev_wot::TrustDistanceParams;
use failure::format_err;
use semver::Version;
Expand Down
16 changes: 6 additions & 10 deletions crev-lib/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ use crev_data::{
proof::{self, trust::TrustLevel},
Id, PubId, Url,
};
use crev_wot;

use default::default;
use directories::ProjectDirs;
use failure::{bail, format_err};
use git2;

use insideout::InsideOut;
use resiter::*;
use serde::{Deserialize, Serialize};
use serde_yaml;

use std::{
collections::HashSet,
ffi::OsString,
Expand Down Expand Up @@ -623,11 +623,7 @@ impl Local {
let trust = self.build_trust_proof(from_id, ids, trust_or_distrust)?;

// TODO: Look up previous trust proof?
Ok(util::edit_proof_content_iteractively(
&trust.into(),
None,
None,
)?)
Ok(util::edit_proof_content_iteractively(&trust, None, None)?)
}

/// Fetch other people's proof repostiory from a git URL, into the current database on disk
Expand Down Expand Up @@ -707,7 +703,7 @@ impl Local {
}

/// True if something was fetched
fn fetch_ids_not_fetched_yet<'a>(
fn fetch_ids_not_fetched_yet(
&self,
ids: impl Iterator<Item = Id>,
already_fetched_ids: &mut HashSet<Id>,
Expand Down Expand Up @@ -1002,7 +998,7 @@ impl Local {
eprintln!("There's no way to recover your CrevID if you forget your passphrase.");
let passphrase = read_new_passphrase()?;

let id = crev_data::id::OwnId::generate(crev_data::Url::new_git(url.clone()));
let id = crev_data::id::OwnId::generate(crev_data::Url::new_git(url));
let locked = id::LockedId::from_own_id(&id, &passphrase)?;

self.save_locked_id(&locked)?;
Expand Down
13 changes: 6 additions & 7 deletions crev-lib/src/repo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use crev_data::{
proof::{self, ContentExt},
Digest,
};
use crev_wot;

use failure::{bail, format_err, Fail};
use git2;

use serde::{Deserialize, Serialize};
use serde_yaml;

use std::{
collections::HashSet,
fs,
Expand Down Expand Up @@ -81,10 +81,9 @@ impl Repo {

pub fn open(path: &Path) -> Result<Self> {
if !path.exists() {
Err(std::io::Error::new(
std::io::ErrorKind::NotFound,
"directory not found",
))?;
return Err(
std::io::Error::new(std::io::ErrorKind::NotFound, "directory not found").into(),
);
}

Self::new(path)
Expand Down
6 changes: 3 additions & 3 deletions crev-lib/src/repo/staging.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use common_failures::prelude::*;
use crev_common;

use crev_data::proof;
use failure::bail;
use serde::{Deserialize, Serialize};
use serde_cbor;

use std::{
collections::HashMap,
fs,
Expand Down Expand Up @@ -75,7 +75,7 @@ impl Staging {
let path = full_path.strip_prefix(&self.root_path)?.to_owned();
println!("Adding {}", path.display());
self.entries.insert(
path.to_owned(),
path,
StagingPathInfo {
blake_hash: crev_common::blake2b256sum_file(&full_path)?,
},
Expand Down
11 changes: 4 additions & 7 deletions crev-lib/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fn proofdb_distance() -> Result<()> {

let b_to_d = b.create_signed_trust_proof(vec![d.as_pubid()], TrustLevel::Medium)?;

trustdb.import_from_iter(vec![(b_to_d, url.clone())].into_iter());
trustdb.import_from_iter(vec![(b_to_d, url)].into_iter());

let trust_set: HashSet<_> = trustdb
.calculate_trust_set(a.as_ref(), &distance_params)
Expand Down Expand Up @@ -193,10 +193,7 @@ fn overwritting_reviews() -> Result<()> {
.create_package_review_proof(package.clone(), default(), "b".into())?
.sign_by(&a)?;

for order in vec![
vec![proof1.clone(), proof2.clone()],
vec![proof2.clone(), proof1.clone()],
] {
for order in vec![vec![proof1.clone(), proof2.clone()], vec![proof2, proof1]] {
let mut trustdb = ProofDB::new();
trustdb.import_from_iter(order.into_iter().map(|x| (x, url.clone())));
assert_eq!(
Expand Down Expand Up @@ -258,7 +255,7 @@ fn dont_consider_an_empty_review_as_valid() -> Result<()> {

let proof1 = a
.as_pubid()
.create_package_review_proof(package.clone(), review, "a".into())?
.create_package_review_proof(package, review, "a".into())?
.sign_by(&a)?;

let mut trustdb = ProofDB::new();
Expand Down Expand Up @@ -325,7 +322,7 @@ fn proofdb_distrust() -> Result<()> {

let e_to_d = e.create_signed_trust_proof(vec![d.as_pubid()], TrustLevel::Distrust)?;

trustdb.import_from_iter(vec![(e_to_d, url.clone())].into_iter());
trustdb.import_from_iter(vec![(e_to_d, url)].into_iter());

let trust_set: HashSet<_> = trustdb
.calculate_trust_set(a.as_ref(), &distance_params)
Expand Down
4 changes: 2 additions & 2 deletions crev-lib/src/tests/issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn build_proof_with_advisories(
};
let review = proof::review::PackageBuilder::default()
.from(id.id.to_owned())
.package(package_info.clone())
.package(package_info)
.comment("comment".into())
.advisories(advisories)
.build()
Expand All @@ -62,7 +62,7 @@ fn build_proof_with_issues(id: &OwnId, version: Version, issues: Vec<Issue>) ->
};
let review = proof::review::PackageBuilder::default()
.from(id.id.to_owned())
.package(package_info.clone())
.package(package_info)
.comment("comment".into())
.issues(issues)
.build()
Expand Down
5 changes: 2 additions & 3 deletions crev-lib/src/util/mod.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
pub mod git;

use crate::prelude::*;
use crev_common;

use crev_data::proof::{self, ContentExt};
use failure::bail;
use git2;

use std::{
self, env, ffi,
fmt::Write as FmtWrite,
fs, io,
io::Write,
path::{Path, PathBuf},
};
use tempdir;

pub use crev_common::{
read_file_to_string, run_with_shell_cmd, store_str_to_file, store_to_file_with,
Expand Down
6 changes: 3 additions & 3 deletions crev-wot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ impl ProofDB {
.get(pkg_id)
.into_iter()
.flat_map(move |i| i.get(&from))
.flat_map(move |pkg_ids| pkg_ids)
.flatten()
.cloned()
.collect()
}
Expand Down Expand Up @@ -409,7 +409,7 @@ impl ProofDB {
.into_iter()
.flat_map(move |map| map.get(name))
.flat_map(move |map| map.get(version))
.flat_map(|v| v)
.flatten()
.map(move |pkg_review_id| {
self.get_pkg_review_by_pkg_review_id(pkg_review_id)
.expect("exists")
Expand Down Expand Up @@ -1235,7 +1235,7 @@ impl TrustSet {
details.effective_trust = effective_trust;
changed = true;
}
match details.referers.entry(referer.clone()) {
match details.referers.entry(referer) {
Entry::Vacant(entry) => {
entry.insert(effective_trust);
changed = true;
Expand Down

0 comments on commit dc0011d

Please sign in to comment.