0

Suggest `Entry::or_default` for `Entry::or_insert(Default::default())` by relrel...

 2 years ago
source link: https://github.com/rust-lang/rust-clippy/pull/9342
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Contributor

@relrelb relrelb commented 23 days ago

edited by dswij

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())

All reactions

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK