Use full expr span for return suggestion on type error/ambiguity by compiler-errors · Pull Request #127129 · rust-lang/rust (original) (raw)

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation11 Commits1 Checks6 Files changed

Conversation

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

[ Show hidden characters]({{ revealButtonHref }})

compiler-errors

We sometimes use parts of an expression rather than the whole thing for an obligation span. For example, a method obligation will just point to the path segment corresponding to the method in rcvr.method(args).

So let's not use that assuming it'll point to the whole expression span, which we can access from the expr hir id we store in ObligationCauseCode::WhereClauseInExpr.

Fixes #127109

@rustbot

r? @jieyouxu

rustbot has assigned @jieyouxu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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

Jun 29, 2024

@rust-log-analyzer

This comment has been minimized.

jieyouxu

Choose a reason for hiding this comment

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

The span changes LGTM, the UI test I believe has incorrect "follow-up error annotation" syntax (pre-existing, which may have led you astray).

if true {
Receiver.generic();
//~^ ERROR type annotations needed
//| HELP you might have meant to return this value

Choose a reason for hiding this comment

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

Problem: I think this needs to be

//| HELP you might have meant to return this value
//~| HELP you might have meant to return this value

to quality as a "follow-up error annotation" in the UI test mode (and suite). Hm. Actually, is the HELP error annotation just wrong in that entire file? I dug through compiletest a little and

// Matches comments like:
// //~
// //~|
// //~^
// //~^^^^^
// //[rev1]~
// //[rev1,rev2]~^^

to the best of my knowledge //| is not a supported form of test annotation lol. Apparently there's a few other tests that also does the //| but AFAICT compiletest only uses the //~| form (cargo or r-a might be different here).

Choose a reason for hiding this comment

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

Opened #127155 so I don't forgor about this.

Choose a reason for hiding this comment

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

Yeah that was my typo from copypasting from the file without thinking rather than just writing my own UI test -- //| is definitely not valid and I should have seen that lmao

@jieyouxu

@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

Jul 1, 2024

@compiler-errors

@compiler-errors

Made the test file less dumb

@rustbot ready

@rustbot rustbot added S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

and removed S-waiting-on-author

Status: This is awaiting some action (such as code changes or more information) from the author.

labels

Jul 1, 2024

jieyouxu

Choose a reason for hiding this comment

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

Looks good! r=me after CI is green.

@compiler-errors

@bors

📌 Commit 583b5fc has been approved by jieyouxu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

and removed S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

labels

Jul 1, 2024

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request

Jul 1, 2024

@GuillaumeGomez

…jieyouxu

Use full expr span for return suggestion on type error/ambiguity

We sometimes use parts of an expression rather than the whole thing for an obligation span. For example, a method obligation will just point to the path segment corresponding to the method in rcvr.method(args).

So let's not use that assuming it'll point to the whole expression span, which we can access from the expr hir id we store in ObligationCauseCode::WhereClauseInExpr.

Fixes rust-lang#127109

bors added a commit to rust-lang-ci/rust that referenced this pull request

Jul 1, 2024

@bors

…llaumeGomez

Rollup of 7 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

bors added a commit to rust-lang-ci/rust that referenced this pull request

Jul 1, 2024

@bors

…llaumeGomez

Rollup of 8 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

Jul 1, 2024

@rust-timer

Rollup merge of rust-lang#127129 - compiler-errors:full-expr-span, r=jieyouxu

Use full expr span for return suggestion on type error/ambiguity

We sometimes use parts of an expression rather than the whole thing for an obligation span. For example, a method obligation will just point to the path segment corresponding to the method in rcvr.method(args).

So let's not use that assuming it'll point to the whole expression span, which we can access from the expr hir id we store in ObligationCauseCode::WhereClauseInExpr.

Fixes rust-lang#127109

Labels

S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

T-compiler

Relevant to the compiler team, which will review and decide on the PR/issue.