about summary refs log tree commit diff
path: root/compiler/rustc_parse
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-07-25 18:57:59 +0200
committerGitHub <noreply@github.com>2024-07-25 18:57:59 +0200
commit9fd5679d52c99c99ea08db0dde91fd7130804c16 (patch)
treed496f3f415d75065ece67cac0132467a014a9b95 /compiler/rustc_parse
parent512277ff70082a9614b277e8c460c99702d17723 (diff)
parent4ac60601d32d96688494c4bb404a04205501a02b (diff)
downloadrust-9fd5679d52c99c99ea08db0dde91fd7130804c16.tar.gz
rust-9fd5679d52c99c99ea08db0dde91fd7130804c16.zip
Rollup merge of #128185 - surechen:fix_128042_2, r=compiler-errors
Fix a span error when parsing a wrong param of function.

fixes #128042

Before this change, the span of param `*mut Self` in  `fn oof(*mut Self)` contains `(` before it, so the suggestion in E0424 will be error.
Diffstat (limited to 'compiler/rustc_parse')
-rw-r--r--compiler/rustc_parse/src/parser/item.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs
index fbc5b914600..9aaf4b99243 100644
--- a/compiler/rustc_parse/src/parser/item.rs
+++ b/compiler/rustc_parse/src/parser/item.rs
@@ -2773,7 +2773,14 @@ impl<'a> Parser<'a> {
             let snapshot = p.create_snapshot_for_diagnostic();
             let param = p.parse_param_general(req_name, first_param).or_else(|e| {
                 let guar = e.emit();
-                let lo = p.prev_token.span;
+                // When parsing a param failed, we should check to make the span of the param
+                // not contain '(' before it.
+                // For example when parsing `*mut Self` in function `fn oof(*mut Self)`.
+                let lo = if let TokenKind::OpenDelim(Delimiter::Parenthesis) = p.prev_token.kind {
+                    p.prev_token.span.shrink_to_hi()
+                } else {
+                    p.prev_token.span
+                };
                 p.restore_snapshot(snapshot);
                 // Skip every token until next possible arg or end.
                 p.eat_to_tokens(&[&token::Comma, &token::CloseDelim(Delimiter::Parenthesis)]);