fix: zero_repeat_side_effects generic type needed#16681
fix: zero_repeat_side_effects generic type needed#16681paulmialane wants to merge 1 commit intorust-lang:masterfrom
zero_repeat_side_effects generic type needed#16681Conversation
|
r? @dswij rustbot has assigned @dswij. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
@paulmialane I see CI is failing, and the commit message is WIP. Is this ready for review? |
|
@dswij Yes, the tests are failing because of the remaining issue I mentioned in my previous message. The work isn't finished yet — I'd love a bit of help to keep going if possible. Thank you! |
|
Apologies for the delay in reviewing. @paulmialane I've taken a look at the fix, and I think it's easier to detect if the side effect we're calling is part of a generic impl. Then either we:
Ideally, we'd implement option 1. Let me know if you need further help |
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