rth / vtext

Simple NLP in Rust with Python bindings
Apache License 2.0
147 stars 11 forks source link

Fix clippy warnings #77

Closed rth closed 4 years ago

joshlk commented 4 years ago

Out of interest, what were the clippy warnings?

rth commented 4 years ago

They were quite helpful actually, a few examples below,

$ cargo clippy
[..]

warning: redundant field names in struct initialization
   --> src/tokenize_sentence/mod.rs:216:9
    |
216 |         text: text,
    |         ^^^^^^^^^^ help: replace it with: `text`
    |
    = 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: unused `#[macro_use]` import
  --> src/lib.rs:46:1
   |
46 | #[macro_use]
   | ^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: redundant clone
   --> src/tokenize_sentence/mod.rs:150:39
    |
150 |         self.punctuation = punctuation.clone();
    |                                       ^^^^^^^^ help: remove this
    |
    = note: `#[warn(clippy::redundant_clone)]` on by default
note: this value is dropped without further use
   --> src/tokenize_sentence/mod.rs:150:28
    |
150 |         self.punctuation = punctuation.clone();
    |                            ^^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone

warning: this boolean expression can be simplified
   --> src/tokenize_sentence/mod.rs:247:19
    |
247 |         } else if !end.is_none() & !start.is_none() {
    |                   ^^^^^^^^^^^^^^ help: try: `end.is_some()`
    |
    = note: `#[warn(clippy::nonminimal_bool)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonminimal_bool

warning: this boolean expression can be simplified
   --> src/tokenize_sentence/mod.rs:247:36
    |
247 |         } else if !end.is_none() & !start.is_none() {
    |                                    ^^^^^^^^^^^^^^^^ help: try: `start.is_some()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonminimal_bool

warning: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
   --> src/tokenize_sentence/mod.rs:246:33
    |
243 |         if start.is_none() {
    |            --------------- the check is happening here
...
246 |             bytes_span = &bytes[start.unwrap()..];
    |                                 ^^^^^^^^^^^^^^
    |
    = note: `#[warn(clippy::unnecessary_unwrap)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_unwrap