Skip to content

fix(traits): Remove expression references from index suggestions - #162437

Open
NuclEnergy wants to merge 1 commit into
rust-lang:mainfrom
NuclEnergy:fix/suggest_dereferencing_index
Open

fix(traits): Remove expression references from index suggestions#162437
NuclEnergy wants to merge 1 commit into
rust-lang:mainfrom
NuclEnergy:fix/suggest_dereferencing_index

Conversation

@NuclEnergy

@NuclEnergy NuclEnergy commented Sep 7, 2026

Copy link
Copy Markdown

Fix issue: #162419

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 7, 2026
@rustbot

rustbot commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

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:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 75 candidates
  • Random selection from 20 candidates

Comment on lines +7 to +8
println!("{}", arr[&i]); //~ ERROR E0277
println!("{}", arr[&(i + 0)]); //~ ERROR E0277

@jieyouxu jieyouxu Sep 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

View changes since the review

expr.kind
&& !expr.span.is_empty()
{
let amp_span = expr.span.with_hi(expr.span.lo() + BytePos(1));

@jieyouxu jieyouxu Sep 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use explicit byte manipulations here, this kind of + BytePos(1) manipulation is prone to parser recovery multi-byte unicode ICEs.

View changes since the review

Comment on lines +5164 to +5174
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;
}

@jieyouxu jieyouxu Sep 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

View changes since the review

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 8, 2026
@rustbot

rustbot commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants