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

Clippy warnings #3

Closed
fee1-dead opened this issue Nov 6, 2021 · 1 comment
Closed

Clippy warnings #3

fee1-dead opened this issue Nov 6, 2021 · 1 comment

Comments

@fee1-dead
Copy link

fee1-dead commented Nov 6, 2021

When I run the cargo clippy linter program on your repo, the current project has 29 warnings and one error. Clippy detects code style issues, correctness issues and complexity issues. The cargo clippy output as of 208d0d0 is below:

    Checking flow-rust-sdk v3.9.1 (/home/beef/develop/flow-rust-sdk)
warning: redundant field names in struct initialization
   --> src/lib.rs:665:9
    |
665 |         arguments: arguments,
    |         ^^^^^^^^^^^^^^^^^^^^ help: replace it with: `arguments`
    |
    = note: `#[warn(clippy::redundant_field_names)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names

warning: redundant field names in struct initialization
   --> src/lib.rs:666:9
    |
666 |         reference_block_id: reference_block_id,
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `reference_block_id`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names

warning: redundant field names in struct initialization
   --> src/lib.rs:667:9
    |
667 |         gas_limit: gas_limit,
    |         ^^^^^^^^^^^^^^^^^^^^ help: replace it with: `gas_limit`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names

warning: unneeded `return` statement
   --> src/lib.rs:292:9
    |
292 |         return Err("Could not produce result")?;
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `Err("Could not produce result")?`
    |
    = note: `#[warn(clippy::needless_return)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return

warning: manual implementation of an assign operation
   --> src/lib.rs:252:13
    |
252 |             i = i + 1;
    |             ^^^^^^^^^ help: replace it with: `i += 1`
    |
    = note: `#[warn(clippy::assign_op_pattern)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern

warning: manual implementation of an assign operation
   --> src/lib.rs:257:21
    |
257 |                     time = time + 200;
    |                     ^^^^^^^^^^^^^^^^^ help: replace it with: `time += 200`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern

error: identical args used in this `assert_ne!` macro call
   --> src/lib.rs:262:36
    |
262 |                         assert_ne!(res.error_message, res.error_message);
    |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `#[deny(clippy::eq_op)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#eq_op

warning: returning an `Err(_)` with the `?` operator
   --> src/lib.rs:288:28
    |
288 |                     return Err("Cadence Runtime Error")?;
    |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `Err("Cadence Runtime Error".into())`
    |
    = note: `#[warn(clippy::try_err)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#try_err

warning: returning an `Err(_)` with the `?` operator
   --> src/lib.rs:292:16
    |
292 |         return Err("Could not produce result")?;
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `Err("Could not produce result".into())`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#try_err

warning: unneeded `return` statement
   --> src/lib.rs:544:9
    |
544 | /         return Argument {
545 | |             r#type: "Array",
546 | |             value: values,
547 | |         };
    | |__________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
help: remove `return`
    |
544 ~         Argument {
545 +             r#type: "Array",
546 +             value: values,
547 +         }
    |

warning: unneeded `return` statement
   --> src/lib.rs:551:9
    |
551 | /         return Argument {
552 | |             r#type: "Dictionary",
553 | |             value: values
554 | |                 .into_iter()
555 | |                 .map(|(x, y)| json!({"Key":x, "Value":y}))
556 | |                 .collect(),
557 | |         };
    | |__________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
help: remove `return`
    |
551 ~         Argument {
552 +             r#type: "Dictionary",
553 +             value: values
554 +                 .into_iter()
555 +                 .map(|(x, y)| json!({"Key":x, "Value":y}))
556 +                 .collect(),
  ...

warning: unneeded `return` statement
   --> src/lib.rs:561:9
    |
561 |         return to_vec(&json!(self)).unwrap();
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `to_vec(&json!(self)).unwrap()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return

warning: unneeded `return` statement
   --> src/lib.rs:567:9
    |
567 | /         return Argument {
568 | |             r#type: "Bool",
569 | |             value,
570 | |         };
    | |__________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
help: remove `return`
    |
567 ~         Argument {
568 +             r#type: "Bool",
569 +             value,
570 +         }
    |

warning: unneeded `return` statement
   --> src/lib.rs:576:9
    |
576 | /         return Argument {
577 | |             r#type: "String",
578 | |             value,
579 | |         };
    | |__________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
help: remove `return`
    |
576 ~         Argument {
577 +             r#type: "String",
578 +             value,
579 +         }
    |

warning: unneeded `return` statement
   --> src/lib.rs:583:9
    |
583 |         return to_vec(&json!(self)).unwrap();
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `to_vec(&json!(self)).unwrap()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return

warning: unneeded `return` statement
   --> src/lib.rs:590:9
    |
590 | /         return Argument {
591 | |             r#type: "String",
592 | |             value,
593 | |         };
    | |__________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
help: remove `return`
    |
590 ~         Argument {
591 +             r#type: "String",
592 +             value,
593 +         }
    |

warning: unneeded `return` statement
   --> src/lib.rs:598:9
    |
598 | /         return Argument {
599 | |             r#type: "UFix64",
600 | |             value: value.to_string(),
601 | |         };
    | |__________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
help: remove `return`
    |
598 ~         Argument {
599 +             r#type: "UFix64",
600 +             value: value.to_string(),
601 +         }
    |

warning: used `assert_eq!` with a literal bool
   --> src/lib.rs:597:9
    |
597 |         assert_eq!(value >= 0.0, true); // cannot have a negative ufix
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)`
    |
    = note: `#[warn(clippy::bool_assert_comparison)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#bool_assert_comparison

warning: unneeded `return` statement
   --> src/lib.rs:605:9
    |
605 | /         return Argument {
606 | |             r#type: "Fix64",
607 | |             value: value.to_string(),
608 | |         };
    | |__________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
help: remove `return`
    |
605 ~         Argument {
606 +             r#type: "Fix64",
607 +             value: value.to_string(),
608 +         }
    |

warning: unneeded `return` statement
   --> src/lib.rs:612:9
    |
612 | /         return Argument {
613 | |             r#type: "UInt64",
614 | |             value: value.to_string(),
615 | |         };
    | |__________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
help: remove `return`
    |
612 ~         Argument {
613 +             r#type: "UInt64",
614 +             value: value.to_string(),
615 +         }
    |

warning: unneeded `return` statement
   --> src/lib.rs:619:9
    |
619 | /         return Argument {
620 | |             r#type: "Int64",
621 | |             value: value.to_string(),
622 | |         };
    | |__________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
help: remove `return`
    |
619 ~         Argument {
620 +             r#type: "Int64",
621 +             value: value.to_string(),
622 +         }
    |

warning: unneeded `return` statement
   --> src/lib.rs:626:9
    |
626 | /         return Argument {
627 | |             r#type: "Address",
628 | |             value,
629 | |         };
    | |__________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
help: remove `return`
    |
626 ~         Argument {
627 +             r#type: "Address",
628 +             value,
629 +         }
    |

warning: unneeded `return` statement
   --> src/lib.rs:633:9
    |
633 |         return to_vec(&json!(self)).unwrap();
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `to_vec(&json!(self)).unwrap()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return

warning: manual implementation of an assign operation
   --> src/lib.rs:639:5
    |
639 |     i = i - vec.len();
    |     ^^^^^^^^^^^^^^^^^ help: replace it with: `i -= vec.len()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern

warning: manual implementation of an assign operation
   --> src/lib.rs:642:9
    |
642 |         i = i - 1;
    |         ^^^^^^^^^ help: replace it with: `i -= 1`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern

warning: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices
   --> src/lib.rs:681:25
    |
681 |     payload_signatures: &Vec<TransactionSignature>,
    |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `&[TransactionSignature]`
    |
    = note: `#[warn(clippy::ptr_arg)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg

warning: unneeded `return` statement
   --> src/lib.rs:720:5
    |
720 |     return out;
    |     ^^^^^^^^^^^ help: remove `return`: `out`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return

warning: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Vec`
   --> src/lib.rs:710:40
    |
710 |     for (i, sig) in payload_signatures.into_iter().enumerate() {
    |                                        ^^^^^^^^^ help: call directly: `iter`
    |
    = note: `#[warn(clippy::into_iter_on_ref)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_ref

warning: unneeded `return` statement
   --> src/lib.rs:751:5
    |
751 |     return out;
    |     ^^^^^^^^^^^ help: remove `return`: `out`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return

warning: unneeded `return` statement
   --> src/lib.rs:766:5
    |
766 | /     return Argument::array(
767 | |         account_keys
768 | |             .into_iter()
769 | |             .map(|x| json!(Argument::string(format!("f847b840{}02038203e8", x))))
770 | |             .collect::<Vec<Value>>(),
771 | |     );
    | |______^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
help: remove `return`
    |
766 ~     Argument::array(
767 +         account_keys
768 +             .into_iter()
769 +             .map(|x| json!(Argument::string(format!("f847b840{}02038203e8", x))))
770 +             .collect::<Vec<Value>>(),
771 +     )
    |

warning: `flow-rust-sdk` (lib) generated 29 warnings
error: could not compile `flow-rust-sdk` due to previous error; 29 warnings emitted

I suggest running clippy and rustfmt in the CI to avoid issues like these from occurring.

@MarshallBelles
Copy link
Owner

@fee1-dead the priority of this project has been functionality over style. That being said, this was an easy fix so you will find it in release 4.0.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants