Skip to content

Commit

Permalink
Clippy Action Fix (risc0#1240)
Browse files Browse the repository at this point in the history
Fix clippy action so it fails properly and lists errors that need to be
fixed.

---------

Co-authored-by: BatAdmin <[email protected]>
Co-authored-by: Victor Graf <[email protected]>
Co-authored-by: Frank Laub <[email protected]>
  • Loading branch information
4 people authored Jan 23, 2024
1 parent 51b7698 commit d8c49df
Show file tree
Hide file tree
Showing 22 changed files with 133 additions and 150 deletions.
5 changes: 1 addition & 4 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@ xfast = "run --package xtask --"
xtask = "run --package xtask --release --"

[build]
rustflags = [
"-Dclippy::all",
"-Dwarnings"
]
rustflags = ["-Dclippy::all", "-Dwarnings"]
11 changes: 1 addition & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ jobs:
- run: cargo fmt --all --check --manifest-path bonsai/examples/governance/Cargo.toml
- run: cargo fmt --all --check --manifest-path examples/Cargo.toml
- run: cargo fmt --all --check --manifest-path tools/crates-validator/Cargo.toml
- run: cargo clippy -p risc0-zkvm
- run: cargo sort --workspace --check
- run: cargo sort --workspace --check benchmarks
- run: cargo sort --workspace --check bonsai
Expand Down Expand Up @@ -204,11 +205,6 @@ jobs:
- run: cargo check -p risc0-zkvm -F $FEATURE
- run: cargo check
working-directory: external/substrate
- uses: risc0/clippy-action@main
with:
reporter: "github-pr-check"
github_token: ${{ secrets.GITHUB_TOKEN }}
clippy_flags: --features $FEATURE --all-targets
- run: sccache --show-stats

examples:
Expand Down Expand Up @@ -341,11 +337,6 @@ jobs:
- uses: ./.github/actions/sccache
with:
key: macOS-default
- uses: risc0/clippy-action@main
with:
reporter: 'github-pr-check'
github_token: ${{ secrets.GITHUB_TOKEN }}
clippy_flags: --manifest-path tools/crates-validator/Cargo.toml
- run: cargo test
working-directory: tools/crates-validator
- run: sccache --show-stats
Expand Down
12 changes: 5 additions & 7 deletions risc0/binfmt/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ pub trait Digestible {

impl Digestible for [u8] {
fn digest<S: Sha256>(&self) -> Digest {
*S::hash_bytes(&self)
*S::hash_bytes(self)
}
}

impl Digestible for Vec<u8> {
fn digest<S: Sha256>(&self) -> Digest {
*S::hash_bytes(&self)
*S::hash_bytes(self)
}
}

Expand Down Expand Up @@ -72,11 +72,9 @@ pub fn tagged_struct<S: Sha256>(tag: &str, down: &[impl Borrow<Digest>], data: &
/// Used for hashing of the receipt claim assumptions list, and in the recursion
/// predicates.
pub fn tagged_list<S: Sha256>(tag: &str, list: &[impl Borrow<Digest>]) -> Digest {
list.into_iter()
.rev()
.fold(Digest::ZERO, |list_digest, elem| {
tagged_list_cons::<S>(tag, elem.borrow(), &list_digest)
})
list.iter().rev().fold(Digest::ZERO, |list_digest, elem| {
tagged_list_cons::<S>(tag, elem.borrow(), &list_digest)
})
}

/// Calculate the hash resulting from adding one element to a [tagged_list]
Expand Down
8 changes: 4 additions & 4 deletions risc0/build/src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn docker_build(manifest_path: &Path, src_dir: &Path, features: &[String]) -
let temp_dir = tempdir()?;
let temp_path = temp_dir.path();
let rel_manifest_path = manifest_path.strip_prefix(&src_dir)?;
create_dockerfile(&rel_manifest_path, temp_path, pkg_name.as_str(), features)?;
create_dockerfile(rel_manifest_path, temp_path, pkg_name.as_str(), features)?;
build(&src_dir, temp_path)?;
}
println!("ELFs ready at:");
Expand Down Expand Up @@ -233,15 +233,15 @@ mod test {
build("../../risc0/zkvm/methods/guest/Cargo.toml");
compare_image_id(
"risc0_zkvm_methods_guest/multi_test",
"d1e6daa70fed535c86c8458a2d003ba1f29d82724b727502a1f56259071cd0aa",
"191e6211f2fb68ba90905e25b33c9eb6e4bfda58e8d9239675a64b70e566acd6",
);
compare_image_id(
"risc0_zkvm_methods_guest/hello_commit",
"d5129f4786684dce179ddd73137fbc08c1b8e7e58d8e94ee013c9dc08a013411",
"274e0d78546e14e09d3ad352e05adb84cb2c2dc81f8a85e3b8ccd32ce2f705b8",
);
compare_image_id(
"risc0_zkvm_methods_guest/slice_io",
"5d4c8187e19bae3ae67cb8d4a3213246094403f14403a718b8b12f469d5f274f",
"812b5d6a27b565af20e8ce770534ef216e1c1fa6e5255be7c3d181eefd173250",
);
}
}
23 changes: 9 additions & 14 deletions risc0/build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::{
default::Default,
env,
fs::{self, File},
io::{stderr, BufRead, BufReader, Write},
io::{BufRead, BufReader, Write},
path::{Path, PathBuf},
process::{Command, Stdio},
};
Expand Down Expand Up @@ -219,7 +219,7 @@ where
.as_ref()
.join("riscv32im-risc0-zkvm-elf")
.join("docker")
.join(pkg.name.replace("-", "_"))
.join(pkg.name.replace('-', "_"))
.join(&target.name),
})
.collect()
Expand Down Expand Up @@ -330,7 +330,7 @@ fn build_staticlib(guest_pkg: &str, features: &[&str]) -> String {
}

// Add args to specify the package to be built, and to build is as a staticlib.
cmd.args(&[
cmd.args([
"--package",
guest_pkg,
"--target-dir",
Expand All @@ -341,7 +341,7 @@ fn build_staticlib(guest_pkg: &str, features: &[&str]) -> String {
]);

for feature in features {
cmd.args(&["--features", &(guest_pkg.to_owned() + "/" + feature)]);
cmd.args(["--features", &(guest_pkg.to_owned() + "/" + feature)]);
}

eprintln!("Building staticlib: {:?}", cmd);
Expand All @@ -361,7 +361,7 @@ fn build_staticlib(guest_pkg: &str, features: &[&str]) -> String {
}
}
Message::CompilerMessage(msg) => {
write!(stderr(), "{}", msg).unwrap();
eprint!("{}", msg);
}
_ => (),
}
Expand Down Expand Up @@ -403,18 +403,18 @@ fn build_guest_package<P>(

let features_str = guest_opts.features.join(",");
if !features_str.is_empty() {
cmd.args(&["--features", &features_str]);
cmd.args(["--features", &features_str]);
}

cmd.args(&[
cmd.args([
"--manifest-path",
pkg.manifest_path.as_str(),
"--target-dir",
target_dir.as_ref().to_str().unwrap(),
]);

if !is_debug() {
cmd.args(&["--release"]);
cmd.args(["--release"]);
}

let mut child = cmd
Expand Down Expand Up @@ -470,11 +470,7 @@ fn detect_toolchain(name: &str) {
}

let stdout = String::from_utf8(result.stdout).unwrap();
if stdout
.lines()
.find(|line| line.trim().starts_with(name))
.is_none()
{
if !stdout.lines().any(|line| line.trim().starts_with(name)) {
eprintln!("The 'risc0' toolchain could not be found.");
eprintln!("To install the risc0 toolchain, use cargo-risczero.");
eprintln!("For example:");
Expand Down Expand Up @@ -518,7 +514,6 @@ fn get_guest_dir() -> PathBuf {
.parent() // $profile
.unwrap()
.join("riscv-guest")
.into()
}

/// Embeds methods built for RISC-V for use by host-side dependencies.
Expand Down
4 changes: 2 additions & 2 deletions risc0/circuit/recursion/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -53,7 +53,7 @@ fn download_zkr() {
let out_dir = Path::new(&out_dir);
if std::fs::metadata(&src_path).is_ok() {
let tgt_path = out_dir.join(FILENAME);
std::fs::copy(&src_path, &tgt_path).unwrap();
std::fs::copy(&src_path, tgt_path).unwrap();
} else {
fn decode_hex(s: &str) -> Result<Vec<u8>, ParseIntError> {
(0..s.len())
Expand Down
2 changes: 1 addition & 1 deletion risc0/core/src/field/baby_bear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl Ord for Elem {

impl PartialOrd for Elem {
fn partial_cmp(&self, rhs: &Self) -> Option<Ordering> {
decode(self.ensure_valid().0).partial_cmp(&decode(rhs.ensure_valid().0))
Some(self.cmp(rhs))
}
}

Expand Down
Loading

0 comments on commit d8c49df

Please sign in to comment.