diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2023-03-04 15:24:37 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-04 15:24:37 +0530 |
| commit | 035aa2816a34dcb19c1a3cd87e03c689f445f354 (patch) | |
| tree | 6013252e0918dcd5d6eff55b20a223229b067ebf | |
| parent | 0fbfc3e76916521b509b63286296dd0762170d34 (diff) | |
| parent | 871ee18086dd77fc42a2f78b225efb73d15d0de7 (diff) | |
Rollup merge of #108298 - TaKO8Ki:fix-104440, r=cjgillot
Fix ICE: check if snippet is `)` Fixes #107705
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 9 | ||||
| -rw-r--r-- | tests/ui/parser/issue-107705.rs | 3 | ||||
| -rw-r--r-- | tests/ui/parser/issue-107705.stderr | 10 |
3 files changed, 20 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index b2951e7a184..95a7ca80d5d 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1210,8 +1210,13 @@ impl<'a> Parser<'a> { // `Enum::Foo { a: 3, b: 4 }` or `Enum::Foo(3, 4)`. self.restore_snapshot(snapshot); let close_paren = self.prev_token.span; - let span = lo.to(self.prev_token.span); - if !fields.is_empty() { + let span = lo.to(close_paren); + if !fields.is_empty() && + // `token.kind` should not be compared here. + // This is because the `snapshot.token.kind` is treated as the same as + // that of the open delim in `TokenTreesReader::parse_token_tree`, even if they are different. + self.span_to_snippet(close_paren).map_or(false, |snippet| snippet == ")") + { let mut replacement_err = errors::ParenthesesWithStructFields { span, r#type: path, diff --git a/tests/ui/parser/issue-107705.rs b/tests/ui/parser/issue-107705.rs new file mode 100644 index 00000000000..b80984fcdb0 --- /dev/null +++ b/tests/ui/parser/issue-107705.rs @@ -0,0 +1,3 @@ +// compile-flags: -C debug-assertions + +fn f() {a(b:&, //~ ERROR this file contains an unclosed delimiter diff --git a/tests/ui/parser/issue-107705.stderr b/tests/ui/parser/issue-107705.stderr new file mode 100644 index 00000000000..d2d61346118 --- /dev/null +++ b/tests/ui/parser/issue-107705.stderr @@ -0,0 +1,10 @@ +error: this file contains an unclosed delimiter + --> $DIR/issue-107705.rs:3:67 + | +LL | fn f() {a(b:&, + | - - unclosed delimiter ^ + | | + | unclosed delimiter + +error: aborting due to previous error + |
