Skip to content

another round of new clippy lints #128

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

Merged
merged 7 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ exclude = ["fuzz", "bitcoind-tests"]
large_enum_variant = "allow" # docs say "measure before paying attention to this"; why is it on by default??
similar_names = "allow" # Too many (subjectively) false positives.
uninlined_format_args = "allow" # This is a subjective style choice.
indexing_slicing = "allow" # Too many false positives ... would be cool though
match_bool = "allow" # Adds extra indentation and LOC.
match_same_arms = "allow" # Collapses things that are conceptually unrelated to each other.
must_use_candidate = "allow" # Useful for audit but many false positives.
Expand All @@ -65,7 +66,7 @@ cloned_instead_of_copied = "warn"
copy_iterator = "warn"
default_trait_access = "warn"
doc_link_with_quotes = "warn"
doc_markdown = "allow"
doc_markdown = "warn"
empty_enum = "warn"
enum_glob_use = "allow"
expl_impl_clone_on_copy = "warn"
Expand All @@ -78,7 +79,7 @@ float_cmp = "warn"
fn_params_excessive_bools = "warn"
from_iter_instead_of_collect = "warn"
if_not_else = "warn"
ignored_unit_patterns = "allow"
ignored_unit_patterns = "warn"
implicit_clone = "warn"
implicit_hasher = "warn"
inconsistent_struct_constructor = "warn"
Expand All @@ -87,7 +88,7 @@ inefficient_to_string = "allow"
inline_always = "warn"
into_iter_without_iter = "warn"
invalid_upcast_comparisons = "warn"
items_after_statements = "allow"
items_after_statements = "warn"
iter_filter_is_ok = "warn"
iter_filter_is_some = "warn"
iter_not_returning_iterator = "warn"
Expand All @@ -98,16 +99,15 @@ large_stack_arrays = "warn"
large_types_passed_by_value = "warn"
linkedlist = "warn"
macro_use_imports = "warn"
manual_assert = "allow"
manual_assert = "warn"
manual_instant_elapsed = "warn"
manual_is_power_of_two = "warn"
manual_is_variant_and = "warn"
manual_let_else = "allow"
manual_let_else = "warn"
manual_ok_or = "warn"
manual_string_new = "warn"
many_single_char_names = "warn"
map_unwrap_or = "allow"
match_on_vec_items = "warn"
map_unwrap_or = "warn"
match_wild_err_arm = "warn"
match_wildcard_for_single_variants = "allow"
maybe_infinite_iter = "warn"
Expand Down
32 changes: 15 additions & 17 deletions src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,19 +438,6 @@ impl Call {
/// takes the list of type `E^(<2^n)` and an initial accumulator of type `A`,
/// and it produces the final accumulator of type `A`.
fn list_fold(bound: NonZeroPow2Usize, f: &ProgNode) -> Result<ProgNode, simplicity::types::Error> {
/* f_0 : E × A → A
* f_0 := f
*/
let mut f_array = f.clone();

/* (fold f)_1 : E^<2 × A → A
* (fold f)_1 := case IH f_0
*/
let ctx = f.inference_context();
let ioh = ProgNode::i().h(ctx);
let mut f_fold = ProgNode::case(ioh.as_ref(), &f_array)?;
let mut i = NonZeroPow2Usize::TWO;

fn next_f_array(f_array: &ProgNode) -> Result<ProgNode, simplicity::types::Error> {
/* f_(n + 1) : E^(2^(n + 1)) × A → A
* f_(n + 1) := OIH ▵ (OOH ▵ IH; f_n); f_n
Expand Down Expand Up @@ -487,6 +474,19 @@ fn list_fold(bound: NonZeroPow2Usize, f: &ProgNode) -> Result<ProgNode, simplici
.map(PairBuilder::build)
}

/* f_0 : E × A → A
* f_0 := f
*/
let mut f_array = f.clone();

/* (fold f)_1 : E^<2 × A → A
* (fold f)_1 := case IH f_0
*/
let ctx = f.inference_context();
let ioh = ProgNode::i().h(ctx);
let mut f_fold = ProgNode::case(ioh.as_ref(), &f_array)?;
let mut i = NonZeroPow2Usize::TWO;

while i < bound {
f_array = next_f_array(&f_array)?;
f_fold = next_f_fold(&f_array, &f_fold)?;
Expand Down Expand Up @@ -617,8 +617,7 @@ impl Match {
.pattern()
.as_variable()
.cloned()
.map(Pattern::Identifier)
.unwrap_or(Pattern::Ignore),
.map_or(Pattern::Ignore, Pattern::Identifier),
);
let left = self.left().expression().compile(scope)?;
scope.pop_scope();
Expand All @@ -629,8 +628,7 @@ impl Match {
.pattern()
.as_variable()
.cloned()
.map(Pattern::Identifier)
.unwrap_or(Pattern::Ignore),
.map_or(Pattern::Ignore, Pattern::Identifier),
);
let right = self.right().expression().compile(scope)?;
scope.pop_scope();
Expand Down
11 changes: 4 additions & 7 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,11 @@ impl Position {
///
/// Line or column are zero.
pub const fn new(line: usize, col: usize) -> Self {
if line == 0 {
panic!("Line must not be zero");
}
// assert_ne not available in constfn
assert!(line != 0, "line must not be zero",);
// Safety: Checked above
let line = unsafe { NonZeroUsize::new_unchecked(line) };
if col == 0 {
panic!("Column must not be zero");
}
assert!(col != 0, "column must not be zero",);
// Safety: Checked above
let col = unsafe { NonZeroUsize::new_unchecked(col) };
Self { line, col }
Expand Down Expand Up @@ -236,7 +233,7 @@ impl fmt::Display for RichError {
writeln!(f, "{:width$} |", " ", width = line_num_width)?;

let mut lines = file.lines().skip(start_line_index).peekable();
let start_line_len = lines.peek().map(|l| l.len()).unwrap_or(0);
let start_line_len = lines.peek().map_or(0, |l| l.len());

for (relative_line_index, line_str) in lines.take(n_spanned_lines).enumerate() {
let line_num = start_line_index + relative_line_index + 1;
Expand Down
11 changes: 6 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ macro_rules! impl_eq_hash {
/// the initial budget. The budget prevents the generated structure from becoming too deep, which
/// could cause issues in the code that processes these structures.
///
/// https://github.com/rust-fuzz/arbitrary/issues/78
/// <https://github.com/rust-fuzz/arbitrary/issues/78>
#[cfg(feature = "arbitrary")]
trait ArbitraryRec: Sized {
/// Generate a recursive structure from unstructured data.
Expand Down Expand Up @@ -426,7 +426,7 @@ mod tests {

pub fn assert_run_success(self) {
match self.run() {
Ok(_) => {}
Ok(()) => {}
Err(error) => panic!("Unexpected error: {error}"),
}
}
Expand Down Expand Up @@ -620,9 +620,10 @@ fn main() {
) {
Ok(_) => panic!("Accepted faulty program"),
Err(error) => {
if !error.contains("Expected expression of type `bool`, found type `()`") {
panic!("Unexpected error: {error}")
}
assert!(
error.contains("Expected expression of type `bool`, found type `()`"),
"Unexpected error: {error}",
);
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ impl WitnessValues {
/// witnesses will be pruned and which won't be pruned. This check skips unassigned witnesses.
pub fn is_consistent(&self, witness_types: &WitnessTypes) -> Result<(), Error> {
for name in self.0.keys() {
let declared_ty = match witness_types.get(name) {
Some(ty) => ty,
None => continue,
let Some(declared_ty) = witness_types.get(name) else {
continue;
};
let assigned_ty = self.0[name].ty();
if assigned_ty != declared_ty {
Expand Down
Loading