Skip to content
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 and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid suggestion for mismatched types in closure arguments #114256

Merged
merged 1 commit into from
Jul 30, 2023

Conversation

Urgau
Copy link
Member

@Urgau Urgau commented Jul 30, 2023

This PR fixes the invalid suggestion for mismatched types in closure arguments.

The invalid suggestion came from a wrongly created span in the parser for closure arguments that don't have a type specified. Specifically, the span in this case was the last token span, but in the case of tuples, the span represented the last parenthesis instead of the whole tuple, which is fixed by taking the more accurate span of the pattern.

There is one unfortunate downside of this fix, it worsens even more the diagnostic for mismatched types in closure args without an explicit type. This happens because there is no correct span for implied inferred type. I tried also fixing this but it's a rabbit hole.

Fixes #114180

The invalid suggestion came from a wrongly created span in `rustc_parse'
for closure arguments that didn't have a type specified. Specifically,
the span in this case was the last token span, but in the case of
tuples, the span represented the last parenthesis instead of the whole
tuple, which is fixed by taking the more accurate span of the pattern.
@rustbot
Copy link
Collaborator

rustbot commented Jul 30, 2023

r? @WaffleLapkin

(rustbot has picked a reviewer for you, use r? to override)

@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 Jul 30, 2023
@@ -0,0 +1,8 @@
// check-fail
Copy link
Member

Choose a reason for hiding this comment

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

Wait, actually, can you make this into // run-rustfix test? (also // check-fail is the default iirc, you don't need it)

Copy link
Member Author

@Urgau Urgau Jul 30, 2023

Choose a reason for hiding this comment

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

Unfortunately no, since the current suggestion is not enough to fix the issue; but applying it will lead to another suggestion which fixes the issue.

Copy link
Member

Choose a reason for hiding this comment

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

oof, that's unfortunate

@WaffleLapkin
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jul 30, 2023

📌 Commit 8ea7e45 has been approved by WaffleLapkin

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 30, 2023
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jul 30, 2023
…pkin

Fix invalid suggestion for mismatched types in closure arguments

This PR fixes the invalid suggestion for mismatched types in closure arguments.

The invalid suggestion came from a wrongly created span in the parser for closure arguments that don't have a type specified. Specifically, the span in this case was the last token span, but in the case of tuples, the span represented the last parenthesis instead of the whole tuple, which is fixed by taking the more accurate span of the pattern.

There is one unfortunate downside of this fix, it worsens even more the diagnostic for mismatched types in closure args without an explicit type. This happens because there is no correct span for implied inferred type. I tried also fixing this but it's a rabbit hole.

Fixes rust-lang#114180
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 30, 2023
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#98154 (merge functionality of `io::Sink` into `io::Empty`)
 - rust-lang#102198 (`const`-stablilize `NonNull::as_ref`)
 - rust-lang#114074 (inline format!() args from rustc_middle up to and including rustc_codegen_llvm (3))
 - rust-lang#114246 (Weaken unnameable_types lint)
 - rust-lang#114256 (Fix invalid suggestion for mismatched types in closure arguments)
 - rust-lang#114258 (Simplify `Span::can_be_used_for_suggestions` a little tiny bit)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 97bacad into rust-lang:master Jul 30, 2023
@rustbot rustbot added this to the 1.73.0 milestone Jul 30, 2023
@Urgau Urgau deleted the fix-issue-114180 branch July 31, 2023 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nonsensical suggestion on closure param type error
4 participants