Skip to content

Commit 871ee18

Browse files
committed
check if snippet is )
1 parent 13471d3 commit 871ee18

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

compiler/rustc_parse/src/parser/expr.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1210,8 +1210,13 @@ impl<'a> Parser<'a> {
12101210
// `Enum::Foo { a: 3, b: 4 }` or `Enum::Foo(3, 4)`.
12111211
self.restore_snapshot(snapshot);
12121212
let close_paren = self.prev_token.span;
1213-
let span = lo.to(self.prev_token.span);
1214-
if !fields.is_empty() {
1213+
let span = lo.to(close_paren);
1214+
if !fields.is_empty() &&
1215+
// `token.kind` should not be compared here.
1216+
// This is because the `snapshot.token.kind` is treated as the same as
1217+
// that of the open delim in `TokenTreesReader::parse_token_tree`, even if they are different.
1218+
self.span_to_snippet(close_paren).map_or(false, |snippet| snippet == ")")
1219+
{
12151220
let mut replacement_err = errors::ParenthesesWithStructFields {
12161221
span,
12171222
r#type: path,

tests/ui/parser/issue-107705.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// compile-flags: -C debug-assertions
2+
3+
fn f() {a(b:&, //~ ERROR this file contains an unclosed delimiter

tests/ui/parser/issue-107705.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: this file contains an unclosed delimiter
2+
--> $DIR/issue-107705.rs:3:67
3+
|
4+
LL | fn f() {a(b:&,
5+
| - - unclosed delimiter ^
6+
| |
7+
| unclosed delimiter
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)