Resolve manual_let_else clippy lints

error: this could be rewritten as `let...else`
        --> test_suite/tests/test_annotations.rs:1247:5
         |
    1247 | /     let f1 = match pieces.next() {
    1248 | |         Some(x) => x,
    1249 | |         None => return Err(de::Error::invalid_length(0, &"2")),
    1250 | |     };
         | |______^ help: consider writing: `let Some(x) = pieces.next() else { return Err(de::Error::invalid_length(0, &"2")) };`
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else
         = note: `-D clippy::manual-let-else` implied by `-D clippy::pedantic`

    error: this could be rewritten as `let...else`
        --> test_suite/tests/test_annotations.rs:1251:5
         |
    1251 | /     let f2 = match pieces.next() {
    1252 | |         Some(x) => x,
    1253 | |         None => return Err(de::Error::invalid_length(1, &"2")),
    1254 | |     };
         | |______^ help: consider writing: `let Some(x) = pieces.next() else { return Err(de::Error::invalid_length(1, &"2")) };`
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else

    error: this could be rewritten as `let...else`
        --> test_suite/tests/test_annotations.rs:1255:5
         |
    1255 | /     let f2 = match f2.parse() {
    1256 | |         Ok(n) => n,
    1257 | |         Err(_) => {
    1258 | |             return Err(de::Error::invalid_value(
    ...    |
    1262 | |         }
    1263 | |     };
         | |______^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else
    help: consider writing
         |
    1255 ~     let Ok(n) = f2.parse() else {
    1256 +             return Err(de::Error::invalid_value(
    1257 +                 Unexpected::Str(f2),
    1258 +                 &"an 8-bit signed integer",
    1259 +             ));
    1260 +         };
         |
This commit is contained in:
David Tolnay 2022-11-22 18:44:48 -08:00
parent ab230e6e44
commit 93bb9e147c
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -1244,22 +1244,17 @@ where
{
let s = String::deserialize(deserializer)?;
let mut pieces = s.split(';');
let f1 = match pieces.next() {
Some(x) => x,
None => return Err(de::Error::invalid_length(0, &"2")),
let Some(f1) = pieces.next() else {
return Err(de::Error::invalid_length(0, &"2"));
};
let f2 = match pieces.next() {
Some(x) => x,
None => return Err(de::Error::invalid_length(1, &"2")),
let Some(f2) = pieces.next() else {
return Err(de::Error::invalid_length(1, &"2"));
};
let f2 = match f2.parse() {
Ok(n) => n,
Err(_) => {
return Err(de::Error::invalid_value(
Unexpected::Str(f2),
&"an 8-bit signed integer",
));
}
let Ok(f2) = f2.parse() else {
return Err(de::Error::invalid_value(
Unexpected::Str(f2),
&"an 8-bit signed integer",
));
};
Ok((f1.into(), f2))
}