about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/expr.rs
diff options
context:
space:
mode:
authorTakayuki Maeda <takoyaki0316@gmail.com>2023-03-03 14:33:31 +0900
committerTakayuki Maeda <takoyaki0316@gmail.com>2023-03-03 14:34:11 +0900
commit871ee18086dd77fc42a2f78b225efb73d15d0de7 (patch)
tree7ba17331e1e095c41b26887ed1217a7addd3ddb2 /compiler/rustc_parse/src/parser/expr.rs
parent13471d3b2046cce78181dde6cfc146c09f55e29e (diff)
downloadrust-871ee18086dd77fc42a2f78b225efb73d15d0de7.tar.gz
rust-871ee18086dd77fc42a2f78b225efb73d15d0de7.zip
check if snippet is `)`
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs9
1 files changed, 7 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,