Improve map_unwrap_or lint to support map(f).unwrap_or_default() - #17644
Conversation
|
Thanks for the pull request, and welcome! You should hear from one of our reviewers after this PR gets at least 2 reviews from the community. Please see the contribution instructions for more information. |
|
Lintcheck changes for 8788452
This comment will be updated if you push new changes |
1e77590 to
410d9c8
Compare
|
rustbot has assigned @samueltardieu for the project review. Use Why was this reviewer chosen?The reviewer was selected based on:
|
There was a problem hiding this comment.
That's a good start! I've added some suggestions.
Also, please add tests involving macros to ensure we don't trigger.
I'll start a FCP to determine whether we want to extend the map_unwrap_or lint or create a new map_unwrap_or_default one.
@rustbot label lint-nominated
|
This lint has been nominated for inclusion. |
|
Reminder, once the PR becomes ready for a review, use |
|
These are new tests. The 5th case seems to be a false negative (to me) but filtered out by fn option(opt: Option<i32>) {
let _ = opt.map(|x| x * x).unwrap_or_default(); //~ map_unwrap_or
let _ = opt.map(|x| vec![x]).unwrap_or_default(); //~ map_unwrap_or
let _ = identity!(opt.map(|x| x + 1).unwrap_or_default()); //~ map_unwrap_or
let _ = identity!(opt.map(|x| x + 1)).unwrap_or_default();
let _ = identity!(opt).map(|x| x + 1).unwrap_or_default();
} |
|
@rustbot ready |
There was a problem hiding this comment.
At the end, before it can be merged, I'll ask you to squash the commits and split the changes into two commits:
- a first commit with the effect that these changes would have on Clippy sources;
- a second commit with the changes to the lint itself.
This way, at any stage (before the first commit, after the first commit, and after both commits) tests would pass without warning, in case we need to bisect an issue.
|
The merge-queue checks will be passed once Lokathor/tinyvec#226 is merged. |
|
Now new version of |
View all comments
Option::map_or_default/Result::map_or_defaultwas stabilized in Rust 1.98.0, so themap_unwrap_orlint should also covermap(f).unwrap_or_default(), suggestingmap_or_default(f)instead.changelog: [
map_unwrap_or]: extend to supportmap(f).unwrap_or_default()