Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ci improve clippy (rebased) #1465

Merged
merged 13 commits into from
Jun 7, 2021
4 changes: 1 addition & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ jobs:
- run: rustup install $(cat rust-toolchain)
- run: rustup default $(cat rust-toolchain)
- run: rustup install << pipeline.parameters.nightly-toolchain >>
- run: rustup component add rustfmt-preview
- run: rustup component add clippy
- run: cargo update
- run: cargo fetch
- run: rustc +$(cat rust-toolchain) --version
Expand Down Expand Up @@ -327,7 +325,7 @@ jobs:
- restore_rustup_cache
- run:
name: Run cargo clippy
command: cargo +$(cat rust-toolchain) clippy --workspace
command: cargo +$(cat rust-toolchain) clippy --all-targets --workspace -- -D warnings
test_darwin:
macos:
xcode: "10.0.0"
Expand Down
4 changes: 2 additions & 2 deletions fil-proofs-param/src/bin/fakeipfsadd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ impl Cli {
pub fn main() {
let cli = Cli::from_args();

let mut src_file =
File::open(cli.file_path()).expect(&format!("failed to open file: {}", cli.file_path()));
let mut src_file = File::open(cli.file_path())
.unwrap_or_else(|_| panic!("failed to open file: {}", cli.file_path()));

let mut hasher = Blake2b::new();
io::copy(&mut src_file, &mut hasher).expect("failed to write BLAKE2b bytes to hasher");
Expand Down
9 changes: 3 additions & 6 deletions fil-proofs-param/src/bin/paramcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,9 @@ fn cache_window_post_params<Tree: 'static + MerkleTreeTrait>(post_config: &PoStC
)
.expect("failed to get groth params");

let _ = <FallbackPoStCompound<Tree>>::get_verifying_key(
Some(&mut OsRng),
circuit.clone(),
&public_params,
)
.expect("failed to get verifying key");
let _ =
<FallbackPoStCompound<Tree>>::get_verifying_key(Some(&mut OsRng), circuit, &public_params)
.expect("failed to get verifying key");
}

#[derive(Debug, StructOpt)]
Expand Down
68 changes: 35 additions & 33 deletions fil-proofs-param/src/bin/paramfetch.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::env;
use std::fs::{create_dir_all, rename, File};
use std::io::{self, copy, stderr, stdout, Read, Stdout, Write};
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::process::{exit, Command};

use anyhow::{ensure, Context, Result};
Expand Down Expand Up @@ -35,13 +35,13 @@ const DEFAULT_JSON: &str = include_str!("../../parameters.json");
const DEFAULT_IPGET_VERSION: &str = "v0.6.0";

#[inline]
fn ipget_dir(version: &str) -> String {
fn get_ipget_dir(version: &str) -> String {
format!("/var/tmp/ipget-{}", version)
}

#[inline]
fn ipget_path(version: &str) -> String {
format!("{}/ipget/ipget", ipget_dir(version))
fn get_ipget_path(version: &str) -> String {
format!("{}/ipget/ipget", get_ipget_dir(version))
}

/// Reader with progress bar.
Expand Down Expand Up @@ -114,12 +114,14 @@ fn download_ipget(version: &str, verbose: bool) -> Result<()> {
};

// Write downloaded file.
let write_path = format!("{}.{}", ipget_dir(version), ext);
let write_path = format!("{}.{}", get_ipget_dir(version), ext);
trace!("writing downloaded file to: {}", write_path);
let mut writer = File::create(&write_path).expect("failed to create file");
if verbose && size.is_some() {
let mut resp = FetchProgress::new(resp, size.unwrap());
copy(&mut resp, &mut writer).expect("failed to write download to file");
if verbose {
if let Some(size) = size {
let mut resp_with_progress = FetchProgress::new(resp, size);
copy(&mut resp_with_progress, &mut writer).expect("failed to write download to file");
}
} else {
copy(&mut resp, &mut writer).expect("failed to write download to file");
}
Expand All @@ -132,14 +134,14 @@ fn download_ipget(version: &str, verbose: bool) -> Result<()> {
let unzipper = GzDecoder::new(reader);
let mut unarchiver = Archive::new(unzipper);
unarchiver
.unpack(ipget_dir(version))
.unpack(get_ipget_dir(version))
.expect("failed to unzip and unarchive");
} else {
unimplemented!("unzip is not yet supported");
}
info!(
"successfully downloaded ipget binary: {}",
ipget_path(version),
get_ipget_path(version),
);

Ok(())
Expand Down Expand Up @@ -185,8 +187,8 @@ fn get_filenames_requiring_download(

fn download_file_with_ipget(
cid: &str,
path: &PathBuf,
ipget_path: &PathBuf,
path: &Path,
ipget_path: &Path,
ipget_args: &Option<String>,
verbose: bool,
) -> Result<()> {
Expand Down Expand Up @@ -368,29 +370,29 @@ pub fn main() {
return;
}

let ipget_path = match cli.ipget_bin {
Some(ipget_path) => {
let ipget_path = PathBuf::from(ipget_path);
if !ipget_path.exists() {
error!(
"provided ipget binary not found: {}, exiting",
ipget_path.display()
);
exit(1);
}
ipget_path
let ipget_path = if let Some(path_str) = cli.ipget_bin {
let path = PathBuf::from(path_str);
if !path.exists() {
error!(
"provided ipget binary not found: {}, exiting",
path.display()
);
exit(1);
}
None => {
let ipget_version = cli
.ipget_version
.unwrap_or(DEFAULT_IPGET_VERSION.to_string());
let ipget_path = PathBuf::from(ipget_path(&ipget_version));
if !ipget_path.exists() {
info!("ipget binary not found: {}", ipget_path.display());
download_ipget(&ipget_version, cli.verbose).expect("ipget download failed");
}
ipget_path

path
} else {
let ipget_version = cli
.ipget_version
.unwrap_or_else(|| DEFAULT_IPGET_VERSION.to_string());
let tmp_path = get_ipget_path(&ipget_version);
let path = PathBuf::from(&tmp_path);
if !path.exists() {
info!("ipget binary not found: {}", path.display());
download_ipget(&ipget_version, cli.verbose).expect("ipget download failed");
}

path
};
trace!("using ipget binary: {}", ipget_path.display());

Expand Down
4 changes: 2 additions & 2 deletions fil-proofs-param/src/bin/parampublish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn is_well_formed_filename(filename: &str) -> bool {
warn!("file has invalid extension: {}, ignoring file", filename);
return false;
}
let version = filename.split('-').nth(0).unwrap();
let version = filename.split('-').next().unwrap();
if version.len() < 2 {
return false;
}
Expand Down Expand Up @@ -207,7 +207,7 @@ pub fn main() {
// Store every param-id's .params and .vk file info.
let mut infos = Vec::<FileInfo>::with_capacity(2 * ids.len());
for id in &ids {
let version = id.split('-').nth(0).unwrap().to_string();
let version = id.split('-').next().unwrap().to_string();
let sector_size = meta_map[id].sector_size;
infos.push(FileInfo {
id: id.clone(),
Expand Down
2 changes: 1 addition & 1 deletion fil-proofs-param/src/bin/srspublish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn is_well_formed_filename(filename: &str) -> bool {
}
return false;
}
let version = filename.split('-').nth(0).unwrap();
let version = filename.split('-').next().unwrap();
if version.len() < 2 {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions fil-proofs-tooling/src/bin/benchy/merkleproofs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fs::{create_dir, remove_dir_all};
use std::time::{SystemTime, UNIX_EPOCH};

use anyhow::Result;
use anyhow::{ensure, Result};
use filecoin_hashers::Hasher;
use filecoin_proofs::with_shape;
use log::{debug, info};
Expand Down Expand Up @@ -57,7 +57,7 @@ fn generate_proofs<R: Rng, Tree: MerkleTreeTrait>(
.gen_cached_proof(challenge, Some(rows_to_discard))
.expect("failed to generate proof");
if validate {
assert!(proof.validate(challenge));
ensure!(proof.validate(challenge), "failed to validate proof");
}
}

Expand Down
14 changes: 6 additions & 8 deletions fil-proofs-tooling/src/bin/check_parameters/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::path::Path;

use anyhow::Result;
use bellperson::bls::Bls12;
Expand All @@ -7,11 +7,11 @@ use clap::{value_t, App, Arg, SubCommand};

use storage_proofs_core::parameter_cache::read_cached_params;

fn run_map(parameter_file: &PathBuf) -> Result<MappedParameters<Bls12>> {
read_cached_params(parameter_file)
fn run_map(parameter_file: &Path) -> Result<MappedParameters<Bls12>> {
read_cached_params(&parameter_file.to_path_buf())
}

fn main() -> Result<()> {
fn main() {
fil_logger::init();

let map_cmd = SubCommand::with_name("map")
Expand All @@ -31,11 +31,9 @@ fn main() -> Result<()> {

match matches.subcommand() {
("map", Some(m)) => {
let parameter_file = value_t!(m, "param", PathBuf)?;
run_map(&parameter_file)?;
let parameter_file_str = value_t!(m, "param", String).expect("param failed");
run_map(&Path::new(&parameter_file_str)).expect("run_map failed");
}
_ => panic!("Unrecognized subcommand"),
}

Ok(())
}
6 changes: 1 addition & 5 deletions fil-proofs-tooling/src/bin/fdlimit/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use anyhow::Result;

fn main() -> Result<()> {
fn main() {
fil_logger::init();

let res = fdlimit::raise_fd_limit().expect("failed to raise fd limit");
println!("File descriptor limit was raised to {}", res);

Ok(())
}
12 changes: 6 additions & 6 deletions fil-proofs-tooling/src/bin/micro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn make_detail_re(name: &str) -> Regex {
}

/// Parses the output of `cargo bench -p storage-proofs --bench <benchmark> -- --verbose --colors never`.
fn parse_criterion_out(s: impl AsRef<str>) -> Result<Vec<CriterionResult>> {
fn parse_criterion_out(s: impl AsRef<str>) -> Vec<CriterionResult> {
let mut res = Vec::new();

let start_re = Regex::new(r"^Benchmarking ([^:]+)$").expect("invalid regex");
Expand Down Expand Up @@ -218,7 +218,8 @@ fn parse_criterion_out(s: impl AsRef<str>) -> Result<Vec<CriterionResult>> {
med_abs_dev: r.11,
});
}
Ok(res)

res
}

/// parses a string of the form "521.80 KiB/s".
Expand Down Expand Up @@ -285,7 +286,7 @@ fn run_benches(mut args: Vec<String>) -> Result<()> {
stdout += "\n";
});

let parsed_results = parse_criterion_out(stdout)?;
let parsed_results = parse_criterion_out(stdout);

let wrapped = Metadata::wrap(parsed_results)?;

Expand Down Expand Up @@ -339,7 +340,7 @@ slope [141.11 us 159.66 us] R^2 [0.8124914 0.8320154]
mean [140.55 us 150.62 us] std. dev. [5.6028 us 15.213 us]
median [138.33 us 143.23 us] med. abs. dev. [1.7507 ms 8.4109 ms]";

let parsed = parse_criterion_out(stdout).expect("failed to parse criterion output");
let parsed = parse_criterion_out(stdout);
assert_eq!(
parsed,
vec![CriterionResult {
Expand Down Expand Up @@ -410,8 +411,7 @@ slope [141.11 us 159.66 us] R^2 [0.8124914 0.8320154]
mean [140.55 us 150.62 us] std. dev. [5.6028 us 15.213 us]
median [138.33 us 143.23 us] med. abs. dev. [1.7507 ms 8.4109 ms]";

let parsed =
parse_criterion_out(with_throughput).expect("failed to parse criterion output");
let parsed = parse_criterion_out(with_throughput);
assert_eq!(
parsed,
vec![CriterionResult {
Expand Down
5 changes: 1 addition & 4 deletions fil-proofs-tooling/src/bin/settings/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use anyhow::Result;

use storage_proofs_core::settings::SETTINGS;

fn main() -> Result<()> {
fn main() {
println!("{:#?}", *SETTINGS);
Ok(())
}
Loading