map_entry
: don't suggest when {e.insert(_); None }
would be required
#15808
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #15307
Supersedes #15759
Unfortuntaly, avoiding the ugliness in the suggestion seems to require adding a bit of ugliness to the lint emission logic:
Previously, both
InsertSearchResult::snippet_{occupied,vacant}
calledInsertionSearchResult::snippet
for the common bit of logic, but also providedwrite_wrapped
, a special closure for the case where theinsert
-to-be-replaced was a final expression -- in that closure,InsertSearchResult::snippet_occupied
just wrapped theinsert
call inSome
, which was okay, butInsertSearchResult::snippet_vacant
created{ e.insert(_); None::</* value type */> }
-- and that was deemed to be too ugly.So the way I solved this was by making the closure return an
Option<String>
, withNone
returned when the required replacement would be too ugly, and returningNone
fromInsertSearchResult::snippet
if that case was encountered. Then, when constructing thesugg
, I would make itNone
whenever a call toInsertSearchResult::snippet_vacant
returned aNone
.1Diff (especially for the second commit) best viewed with whitespace ignored.
changelog: [
map_entry
]: don't suggest when{e.insert(_); None }
would be requiredr? @samueltardieu
Footnotes
Unfortunately, I wasn't able to nicely
?
out of these cases -- maybetry
-blocks would've helped ↩