mozillazg / rust-pinyin

汉字转拼音

Home Page:https://docs.rs/pinyin/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

解决 clippy 提示的警告信息

mozillazg opened this issue · comments

warning: returning the result of a let binding from a block. Consider returning the expression directly.
   --> src/lib.rs:209:5
    |
209 |     ret
    |     ^^^
    |
    = note: #[warn(let_and_return)] on by default
note: this expression can be directly returned
   --> src/lib.rs:201:15
    |
201 |       let ret = match a.style {
    |  _______________^
202 | |         // 首字母
203 | |         Style::FirstLetter => py.chars().nth(0).unwrap().to_string(),
204 | |         // 韵母
205 | |         Style::Finals | Style::FinalsTone | Style::FinalsTone2 => _final(&py),
206 | |         _ => py,
207 | |     };
    | |_____^
    = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.165/index.html#let_and_return

warning: unneeded return statement
   --> src/lib.rs:260:5
    |
260 |     return ret;
    |     ^^^^^^^^^^^ help: remove `return` as shown: `ret`
    |
    = note: #[warn(needless_return)] on by default
    = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.165/index.html#needless_return

warning: unneeded return statement
   --> src/lib.rs:281:5
    |
281 |     return ret;
    |     ^^^^^^^^^^^ help: remove `return` as shown: `ret`
    |
    = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.165/index.html#needless_return

warning: you should consider adding a `Default` implementation for `Args`
   --> src/lib.rs:130:5
    |
130 | /     pub fn new() -> Args {
131 | |         Args {
132 | |             style: Style::Normal,
133 | |             heteronym: false,
134 | |         }
135 | |     }
    | |_____^
    |
    = note: #[warn(new_without_default)] on by default
    = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.165/index.html#new_without_default
help: try this
    |
130 |     impl Default for Args {
131 |         fn default() -> Self {
132 |             Self::new()
133 |         }
134 |     }
135 |
  ...

warning: this argument is passed by value, but not consumed in the function body
   --> src/lib.rs:139:15
    |
139 | fn initial(p: String) -> String {
    |               ^^^^^^ help: consider changing the type to: `&str`
    |
    = note: #[warn(needless_pass_by_value)] on by default
    = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.165/index.html#needless_pass_by_value

warning: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
   --> src/lib.rs:141:14
    |
141 |     for v in _INITIALS.iter() {
    |              ^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&_INITIALS`
    |
    = note: #[warn(explicit_iter_loop)] on by default
    = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.165/index.html#explicit_iter_loop

warning: you seem to be trying to use match for destructuring a single pattern. Consider using `if let`
   --> src/lib.rs:161:5
    |
161 | /     match a.style {
162 | |         Style::Initials => {
163 | |             return initial(p).to_string();
164 | |         }
165 | |         _ => {}
166 | |     };
    | |_____^
    |
    = note: #[warn(single_match)] on by default
    = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.165/index.html#single_match
help: try this
    |
161 |     if let Style::Initials = a.style {
162 |     return initial(p).to_string();
163 | };
    |

warning: length comparison to zero
   --> src/lib.rs:228:16
    |
228 |             if x.len() == 0 || a.heteronym {
    |                ^^^^^^^^^^^^ help: using `is_empty` is more concise: `x.is_empty()`
    |
    = note: #[warn(len_zero)] on by default
    = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.165/index.html#len_zero

warning: this loop never actually loops
   --> src/lib.rs:275:9
    |
275 | /         for pinyin in pinyin_vc {
276 | |             ret.push(pinyin);
277 | |             break;
278 | |         }
    | |_________^
    |
    = note: #[warn(never_loop)] on by default
    = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.165/index.html#never_loop

    Finished dev [unoptimized + debuginfo] target(s) in 21.25 secs
   Compiling pinyin v0.2.0 (file:///Users/xx/develop/rust-pinyin)
    Finished dev [unoptimized + debuginfo] target(s) in 4.71 secs
   Compiling pinyin v0.2.0 (file:///Users/xx/develop/rust-pinyin)
warning: this loop never actually loops
   --> tests/lib.rs:135:13
    |
135 | /             for pinyin in ret {
136 | |                 lazy_result.push(pinyin.to_string());
137 | |                 break;
138 | |             }
    | |_____________^
    |
    = note: #[warn(never_loop)] on by default
    = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.165/index.html#never_loop

    Finished dev [unoptimized + debuginfo] target(s) in 1.14 secs