fix(traits): Remove expression references from index suggestions - #162437
fix(traits): Remove expression references from index suggestions#162437NuclEnergy wants to merge 1 commit into
Conversation
|
Thanks for the pull request, and welcome! The Rust Project has assigned @jieyouxu (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks. Please see the contribution instructions and our LLM policy for more information. Why was this reviewer chosen?The reviewer was selected based on:
|
| println!("{}", arr[&i]); //~ ERROR E0277 | ||
| println!("{}", arr[&(i + 0)]); //~ ERROR E0277 |
There was a problem hiding this comment.
Instead of the error code, use a (substring of) the error mesage here. The error code is not obvious in terms of the suggestion we are exercising.
| expr.kind | ||
| && !expr.span.is_empty() | ||
| { | ||
| let amp_span = expr.span.with_hi(expr.span.lo() + BytePos(1)); |
There was a problem hiding this comment.
Don't use explicit byte manipulations here, this kind of + BytePos(1) manipulation is prone to parser recovery multi-byte unicode ICEs.
| if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(amp_span) | ||
| && snippet == "&" | ||
| { | ||
| err.span_suggestion_verbose( | ||
| amp_span, | ||
| "remove this reference", | ||
| "", | ||
| Applicability::MachineApplicable, | ||
| ); | ||
| return; | ||
| } |
There was a problem hiding this comment.
This is not a great way to do the removal span calculation. This only accounts for the exact syntax of the shape &<inner>. Consider cases like & i, that will unnecessarily leave a whitespace behind i.
We have the structured hir::Expr, consider using until etc. to find the span from the start of the overall expr &<inner> versus the start of the <inner> subexpr.
Would be good to add & i as another test case.
|
Reminder, once the PR becomes ready for a review, use |
Fix issue: #162419