-1

after some upgrade of msrv I get this (In a project I dont own, just doing the msrv upgrade, so removing the 'pedantic' is not OK)

error: this could be rewritten as `let...else`
   --> asyncgit/src/sync/config.rs:99:2
    |
99  | /     let entry = match entry_res {
100 | |         Ok(ent) => ent,
101 | |         Err(_) => return Ok(None),
102 | |     };
    | |______^ help: consider writing: `let Ok(ent) = entry_res else { return Ok(None) };`

on this code

let entry_res = cfg.get_entry(key);

let entry = match entry_res {
    Ok(ent) => ent,
    Err(_) => return Ok(None),
 };

get_entry returns a Result<T,...>

The suggested fix is not valid code - unless I missed something obvious

Edit. When I say not valid code, I mean it won't compile, I am sure the syntax is correct and that it's my fault for not being able to follow what it's trying to do. But it's for sure a clippy bug

EDIT2 : apparently a known bug https://github.com/rust-lang/rust-clippy/issues/10171

pm100
  • 48,078
  • 23
  • 82
  • 145

1 Answers1

1

The suggested fix is not valid code - unless I missed something obvious

The suggested fix seems to have a pretty simple error (which you should report): it should be

let Ok(entry) = entry_res else { return Ok(None) };

Otherwise it creates the wrong top-level binding (ent rather than entry).

Aside from that, the suggested code has been valid code since 1.65.0, released November 2022 (and longer than that on nightly).

Though it is possible clippy does not properly take MSRV in account, I've no idea.

Masklinn
  • 34,759
  • 3
  • 38
  • 57
  • Ty, I was very frustrated and could not work out what it was suggesting (the fact that there was a variable called 'ent' in the original was confusing – pm100 May 11 '23 at 06:20
  • FYI - alreday reported as a clippy bug – pm100 May 11 '23 at 11:31