Skip to content

Commit b810cc2

Browse files
committed
Merge #128: another round of new clippy lints
0fc8f4a clippy: turn on `map_unwrap_or` lint (Andrew Poelstra) bd22858 clippy: turn on manual_let_else lint (Andrew Poelstra) ec358cc clippy: turn on manual_assert lint (Andrew Poelstra) b2767a4 clippy: move statements after items (Andrew Poelstra) 8cd383b clippy: turn on ignored_unit_patterns lint (Andrew Poelstra) 3725f92 clippy: remove match_on_vec_items (Andrew Poelstra) fd143db clippy: warn on `doc_markdown` (Andrew Poelstra) Pull request description: Mostly style. Does find one real issue with our docs. ACKs for top commit: uncomputable: ACK 0fc8f4a Tree-SHA512: acd29dd37bccda751562ed3aea64f72aa8f7796d933b60a39f25eca0472fd83744779f5338feadc1c16e5849ce616154874878b9c2fef28e4e7f369839109f33
2 parents b1dd3d3 + 0fc8f4a commit b810cc2

File tree

5 files changed

+34
-39
lines changed

5 files changed

+34
-39
lines changed

Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ exclude = ["fuzz", "bitcoind-tests"]
4444
large_enum_variant = "allow" # docs say "measure before paying attention to this"; why is it on by default??
4545
similar_names = "allow" # Too many (subjectively) false positives.
4646
uninlined_format_args = "allow" # This is a subjective style choice.
47+
indexing_slicing = "allow" # Too many false positives ... would be cool though
4748
match_bool = "allow" # Adds extra indentation and LOC.
4849
match_same_arms = "allow" # Collapses things that are conceptually unrelated to each other.
4950
must_use_candidate = "allow" # Useful for audit but many false positives.
@@ -65,7 +66,7 @@ cloned_instead_of_copied = "warn"
6566
copy_iterator = "warn"
6667
default_trait_access = "warn"
6768
doc_link_with_quotes = "warn"
68-
doc_markdown = "allow"
69+
doc_markdown = "warn"
6970
empty_enum = "warn"
7071
enum_glob_use = "allow"
7172
expl_impl_clone_on_copy = "warn"
@@ -78,7 +79,7 @@ float_cmp = "warn"
7879
fn_params_excessive_bools = "warn"
7980
from_iter_instead_of_collect = "warn"
8081
if_not_else = "warn"
81-
ignored_unit_patterns = "allow"
82+
ignored_unit_patterns = "warn"
8283
implicit_clone = "warn"
8384
implicit_hasher = "warn"
8485
inconsistent_struct_constructor = "warn"
@@ -87,7 +88,7 @@ inefficient_to_string = "allow"
8788
inline_always = "warn"
8889
into_iter_without_iter = "warn"
8990
invalid_upcast_comparisons = "warn"
90-
items_after_statements = "allow"
91+
items_after_statements = "warn"
9192
iter_filter_is_ok = "warn"
9293
iter_filter_is_some = "warn"
9394
iter_not_returning_iterator = "warn"
@@ -98,16 +99,15 @@ large_stack_arrays = "warn"
9899
large_types_passed_by_value = "warn"
99100
linkedlist = "warn"
100101
macro_use_imports = "warn"
101-
manual_assert = "allow"
102+
manual_assert = "warn"
102103
manual_instant_elapsed = "warn"
103104
manual_is_power_of_two = "warn"
104105
manual_is_variant_and = "warn"
105-
manual_let_else = "allow"
106+
manual_let_else = "warn"
106107
manual_ok_or = "warn"
107108
manual_string_new = "warn"
108109
many_single_char_names = "warn"
109-
map_unwrap_or = "allow"
110-
match_on_vec_items = "warn"
110+
map_unwrap_or = "warn"
111111
match_wild_err_arm = "warn"
112112
match_wildcard_for_single_variants = "allow"
113113
maybe_infinite_iter = "warn"

src/compile.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -438,19 +438,6 @@ impl Call {
438438
/// takes the list of type `E^(<2^n)` and an initial accumulator of type `A`,
439439
/// and it produces the final accumulator of type `A`.
440440
fn list_fold(bound: NonZeroPow2Usize, f: &ProgNode) -> Result<ProgNode, simplicity::types::Error> {
441-
/* f_0 : E × A → A
442-
* f_0 := f
443-
*/
444-
let mut f_array = f.clone();
445-
446-
/* (fold f)_1 : E^<2 × A → A
447-
* (fold f)_1 := case IH f_0
448-
*/
449-
let ctx = f.inference_context();
450-
let ioh = ProgNode::i().h(ctx);
451-
let mut f_fold = ProgNode::case(ioh.as_ref(), &f_array)?;
452-
let mut i = NonZeroPow2Usize::TWO;
453-
454441
fn next_f_array(f_array: &ProgNode) -> Result<ProgNode, simplicity::types::Error> {
455442
/* f_(n + 1) : E^(2^(n + 1)) × A → A
456443
* f_(n + 1) := OIH ▵ (OOH ▵ IH; f_n); f_n
@@ -487,6 +474,19 @@ fn list_fold(bound: NonZeroPow2Usize, f: &ProgNode) -> Result<ProgNode, simplici
487474
.map(PairBuilder::build)
488475
}
489476

477+
/* f_0 : E × A → A
478+
* f_0 := f
479+
*/
480+
let mut f_array = f.clone();
481+
482+
/* (fold f)_1 : E^<2 × A → A
483+
* (fold f)_1 := case IH f_0
484+
*/
485+
let ctx = f.inference_context();
486+
let ioh = ProgNode::i().h(ctx);
487+
let mut f_fold = ProgNode::case(ioh.as_ref(), &f_array)?;
488+
let mut i = NonZeroPow2Usize::TWO;
489+
490490
while i < bound {
491491
f_array = next_f_array(&f_array)?;
492492
f_fold = next_f_fold(&f_array, &f_fold)?;
@@ -617,8 +617,7 @@ impl Match {
617617
.pattern()
618618
.as_variable()
619619
.cloned()
620-
.map(Pattern::Identifier)
621-
.unwrap_or(Pattern::Ignore),
620+
.map_or(Pattern::Ignore, Pattern::Identifier),
622621
);
623622
let left = self.left().expression().compile(scope)?;
624623
scope.pop_scope();
@@ -629,8 +628,7 @@ impl Match {
629628
.pattern()
630629
.as_variable()
631630
.cloned()
632-
.map(Pattern::Identifier)
633-
.unwrap_or(Pattern::Ignore),
631+
.map_or(Pattern::Ignore, Pattern::Identifier),
634632
);
635633
let right = self.right().expression().compile(scope)?;
636634
scope.pop_scope();

src/error.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,11 @@ impl Position {
3535
///
3636
/// Line or column are zero.
3737
pub const fn new(line: usize, col: usize) -> Self {
38-
if line == 0 {
39-
panic!("Line must not be zero");
40-
}
38+
// assert_ne not available in constfn
39+
assert!(line != 0, "line must not be zero",);
4140
// Safety: Checked above
4241
let line = unsafe { NonZeroUsize::new_unchecked(line) };
43-
if col == 0 {
44-
panic!("Column must not be zero");
45-
}
42+
assert!(col != 0, "column must not be zero",);
4643
// Safety: Checked above
4744
let col = unsafe { NonZeroUsize::new_unchecked(col) };
4845
Self { line, col }
@@ -236,7 +233,7 @@ impl fmt::Display for RichError {
236233
writeln!(f, "{:width$} |", " ", width = line_num_width)?;
237234

238235
let mut lines = file.lines().skip(start_line_index).peekable();
239-
let start_line_len = lines.peek().map(|l| l.len()).unwrap_or(0);
236+
let start_line_len = lines.peek().map_or(0, |l| l.len());
240237

241238
for (relative_line_index, line_str) in lines.take(n_spanned_lines).enumerate() {
242239
let line_num = start_line_index + relative_line_index + 1;

src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ macro_rules! impl_eq_hash {
238238
/// the initial budget. The budget prevents the generated structure from becoming too deep, which
239239
/// could cause issues in the code that processes these structures.
240240
///
241-
/// https://github.com/rust-fuzz/arbitrary/issues/78
241+
/// <https://github.com/rust-fuzz/arbitrary/issues/78>
242242
#[cfg(feature = "arbitrary")]
243243
trait ArbitraryRec: Sized {
244244
/// Generate a recursive structure from unstructured data.
@@ -426,7 +426,7 @@ mod tests {
426426

427427
pub fn assert_run_success(self) {
428428
match self.run() {
429-
Ok(_) => {}
429+
Ok(()) => {}
430430
Err(error) => panic!("Unexpected error: {error}"),
431431
}
432432
}
@@ -620,9 +620,10 @@ fn main() {
620620
) {
621621
Ok(_) => panic!("Accepted faulty program"),
622622
Err(error) => {
623-
if !error.contains("Expected expression of type `bool`, found type `()`") {
624-
panic!("Unexpected error: {error}")
625-
}
623+
assert!(
624+
error.contains("Expected expression of type `bool`, found type `()`"),
625+
"Unexpected error: {error}",
626+
);
626627
}
627628
}
628629
}

src/witness.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,8 @@ impl WitnessValues {
114114
/// witnesses will be pruned and which won't be pruned. This check skips unassigned witnesses.
115115
pub fn is_consistent(&self, witness_types: &WitnessTypes) -> Result<(), Error> {
116116
for name in self.0.keys() {
117-
let declared_ty = match witness_types.get(name) {
118-
Some(ty) => ty,
119-
None => continue,
117+
let Some(declared_ty) = witness_types.get(name) else {
118+
continue;
120119
};
121120
let assigned_ty = self.0[name].ty();
122121
if assigned_ty != declared_ty {

0 commit comments

Comments
 (0)