From 01babdccda43197055d3fb7fb3b3c76fce640c64 Mon Sep 17 00:00:00 2001 From: yukang Date: Fri, 11 Nov 2022 19:28:51 +0800 Subject: [PATCH] add more testcase for issue 68987 --- compiler/rustc_parse/src/lexer/tokentrees.rs | 2 +- .../ui/parser/issue-68987-unmatch-issue-2.rs | 12 +++++++++++ .../parser/issue-68987-unmatch-issue-2.stderr | 16 ++++++++++++++ .../ui/parser/issue-68987-unmatch-issue-3.rs | 7 +++++++ .../parser/issue-68987-unmatch-issue-3.stderr | 21 +++++++++++++++++++ 5 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/parser/issue-68987-unmatch-issue-2.rs create mode 100644 src/test/ui/parser/issue-68987-unmatch-issue-2.stderr create mode 100644 src/test/ui/parser/issue-68987-unmatch-issue-3.rs create mode 100644 src/test/ui/parser/issue-68987-unmatch-issue-3.stderr diff --git a/compiler/rustc_parse/src/lexer/tokentrees.rs b/compiler/rustc_parse/src/lexer/tokentrees.rs index ec5575917de13..2eb565a679f00 100644 --- a/compiler/rustc_parse/src/lexer/tokentrees.rs +++ b/compiler/rustc_parse/src/lexer/tokentrees.rs @@ -279,7 +279,7 @@ impl<'a> TokenTreesReader<'a> { "...as it matches this but it has different indentation", ); - // If there is a empty block in the mismatched span, note it + // If there is a empty block in the mismatched span, note it for span in self.empty_block_spans.keys() { if let Some(d) = self.empty_block_spans.get(span) && *d == delim && block_span.contains(*span) { diff --git a/src/test/ui/parser/issue-68987-unmatch-issue-2.rs b/src/test/ui/parser/issue-68987-unmatch-issue-2.rs new file mode 100644 index 0000000000000..e833143c6edb0 --- /dev/null +++ b/src/test/ui/parser/issue-68987-unmatch-issue-2.rs @@ -0,0 +1,12 @@ +async fn obstest() -> Result<> { + let obs_connect = || -> Result<(), MyError) { //~ ERROR mismatched closing delimiter + async { + } + } + + if let Ok(version, scene_list) = obs_connect() { + + } else { + + } +} //~ ERROR unexpected closing delimiter diff --git a/src/test/ui/parser/issue-68987-unmatch-issue-2.stderr b/src/test/ui/parser/issue-68987-unmatch-issue-2.stderr new file mode 100644 index 0000000000000..fe195e3da4215 --- /dev/null +++ b/src/test/ui/parser/issue-68987-unmatch-issue-2.stderr @@ -0,0 +1,16 @@ +error: unexpected closing delimiter: `}` + --> $DIR/issue-68987-unmatch-issue-2.rs:12:1 + | +LL | } + | ^ unexpected closing delimiter + +error: mismatched closing delimiter: `)` + --> $DIR/issue-68987-unmatch-issue-2.rs:1:32 + | +LL | async fn obstest() -> Result<> { + | ^ unclosed delimiter +LL | let obs_connect = || -> Result<(), MyError) { + | ^ mismatched closing delimiter + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/parser/issue-68987-unmatch-issue-3.rs b/src/test/ui/parser/issue-68987-unmatch-issue-3.rs new file mode 100644 index 0000000000000..fea994479e44f --- /dev/null +++ b/src/test/ui/parser/issue-68987-unmatch-issue-3.rs @@ -0,0 +1,7 @@ +fn f(i: u32, j: u32) { + let res = String::new(); + let mut cnt = i; + while cnt < j { + write!&mut res, " "); //~ ERROR mismatched closing delimiter + } +} //~ ERROR unexpected closing delimiter diff --git a/src/test/ui/parser/issue-68987-unmatch-issue-3.stderr b/src/test/ui/parser/issue-68987-unmatch-issue-3.stderr new file mode 100644 index 0000000000000..ff81916053c92 --- /dev/null +++ b/src/test/ui/parser/issue-68987-unmatch-issue-3.stderr @@ -0,0 +1,21 @@ +error: unexpected closing delimiter: `}` + --> $DIR/issue-68987-unmatch-issue-3.rs:7:1 + | +LL | fn f(i: u32, j: u32) { + | - this delimiter might not be properly closed... +... +LL | } + | - ...as it matches this but it has different indentation +LL | } + | ^ unexpected closing delimiter + +error: mismatched closing delimiter: `)` + --> $DIR/issue-68987-unmatch-issue-3.rs:4:19 + | +LL | while cnt < j { + | ^ unclosed delimiter +LL | write!&mut res, " "); + | ^ mismatched closing delimiter + +error: aborting due to 2 previous errors +