diff options
| author | bors <bors@rust-lang.org> | 2022-09-05 04:54:31 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-09-05 04:54:31 +0000 |
| commit | b763b14b2fa29d5b05373317606f27fdb9053302 (patch) | |
| tree | 485366dcfe9af1ae54b5afcadcea8324d07eb6da /src | |
| parent | 90804d35fef4d90bfa6e2f03696085f872513fa0 (diff) | |
| parent | f0e586c2511019a58ad3e56be16bba76dfc7eba8 (diff) | |
| download | rust-b763b14b2fa29d5b05373317606f27fdb9053302.tar.gz rust-b763b14b2fa29d5b05373317606f27fdb9053302.zip | |
Auto merge of #9342 - relrelb:or_default, r=dswij
Suggest `Entry::or_default` for `Entry::or_insert(Default::default())` Unlike past similar work done in #6228, expand the existing `or_fun_call` lint to detect `or_insert` calls with a `T::new()` or `T::default()` argument, much like currently done for `unwrap_or` calls. In that case, suggest the use of `or_default`, which is more idiomatic. Note that even with this change, `or_insert_with(T::default)` calls aren't detected as candidates for `or_default()`, in the same manner that currently `unwrap_or_else(T::default)` calls aren't detected as candidates for `unwrap_or_default()`. Also, as a nearby cleanup, change `KNOW_TYPES` from `static` to `const`, since as far as I understand it's preferred (should Clippy have a lint for that?). Addresses #3812. *Please write a short comment explaining your change (or "none" for internal only changes)* changelog: [`or_fun_call`]: Suggest `Entry::or_default` for `Entry::or_insert(Default::default())`
Diffstat (limited to 'src')
| -rw-r--r-- | src/docs/or_fun_call.txt | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/docs/or_fun_call.txt b/src/docs/or_fun_call.txt index 5605e96c98e..6ce77cc268c 100644 --- a/src/docs/or_fun_call.txt +++ b/src/docs/or_fun_call.txt @@ -1,7 +1,8 @@ ### What it does Checks for calls to `.or(foo(..))`, `.unwrap_or(foo(..))`, -etc., and suggests to use `or_else`, `unwrap_or_else`, etc., or -`unwrap_or_default` instead. +`.or_insert(foo(..))` etc., and suggests to use `.or_else(|| foo(..))`, +`.unwrap_or_else(|| foo(..))`, `.unwrap_or_default()` or `.or_default()` +etc. instead. ### Why is this bad? The function will always be called and potentially |
