Rollup merge of #114256 - Urgau:fix-issue-114180, r=WaffleLapkin

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 https://github.com/rust-lang/rust/issues/114180
This commit is contained in:
Matthias Krüger 2023-07-30 20:36:35 +02:00 committed by GitHub
commit 97bacad9c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 78 additions and 30 deletions

View file

@ -2342,7 +2342,7 @@ impl<'a> Parser<'a> {
let ty = if this.eat(&token::Colon) {
this.parse_ty()?
} else {
this.mk_ty(this.prev_token.span, TyKind::Infer)
this.mk_ty(pat.span, TyKind::Infer)
};
Ok((