fix: zero_repeat_side_effects generic type needed#16681
Open
paulmialane wants to merge 1 commit intorust-lang:masterfrom
Open
fix: zero_repeat_side_effects generic type needed#16681paulmialane wants to merge 1 commit intorust-lang:masterfrom
zero_repeat_side_effects generic type needed#16681paulmialane wants to merge 1 commit intorust-lang:masterfrom
Conversation
Collaborator
|
r? @dswij rustbot has assigned @dswij. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix
zero_repeat_side_effectsemitting broken suggestions for generic typesFixes #16474
What's wrong
The
zero_repeat_side_effectslint suggests splittinginto:
This works fine for simple types, but breaks when the element type has generic parameters, causing:
The fix
I was looking to fix this by suggesting
let _: T = expr;instead of a bareexpr;.This applies to the
let_stmt_suggestionandassign_expr_suggestioncode paths (both the curly and non-curly branches).I think the
Node::Stmtcase (bare expression statement likevec![f(); 0];) does not need this fix because ifTwere ambiguous there, the original code would already fail to compile.Remaining problems
While writting the tests, I realized my implementation introduces a new broken suggestion.
When the element type is defined inside a function (for instance
issue_16474(),Ty::to_stringemits a path likeissue_16474::Entry<usize>which is invalid in the suggestion sinceissue_16474is a function, not a module.I see two different approaches:
In both case, I don't really know the best way to do this, and I wanted a reviewer's opinion on the right approach before going further.
Thank you !
changelog: [
zero_repeat_side_effects]: fix suggestion causes error for generic types