diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-07-30 20:36:35 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-30 20:36:35 +0200 |
| commit | 97bacad9c26fe08f9fc5b5e5930ab13fa84284e3 (patch) | |
| tree | e060ba84f0efbf7fc1b642adf9d2c6ab8a4ad3ba /compiler | |
| parent | d113b5b848eebd07c0bbd31e4f9c876bda1eec02 (diff) | |
| parent | 8ea7e45e44b6bc6437932415a3e0f54caad890b6 (diff) | |
| download | rust-97bacad9c26fe08f9fc5b5e5930ab13fa84284e3.tar.gz rust-97bacad9c26fe08f9fc5b5e5930ab13fa84284e3.zip | |
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
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_hir_typeck/src/pat.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index 4d236a86dda..d8eb8c71b5e 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -755,7 +755,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { match binding_parent { // Check that there is explicit type (ie this is not a closure param with inferred type) // so we don't suggest moving something to the type that does not exist - hir::Node::Param(hir::Param { ty_span, .. }) if binding.span != *ty_span => { + hir::Node::Param(hir::Param { ty_span, pat, .. }) if pat.span != *ty_span => { err.multipart_suggestion_verbose( format!("to take parameter `{binding}` by reference, move `&{mutability}` to the type"), vec