about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2022-01-25 10:47:10 -0800
committerMichael Goulet <michael@errs.io>2022-01-25 10:47:10 -0800
commita090bb1dea18af72dce2195fa4de396bcb51061b (patch)
tree6dc713dc36ed7fbee4b5483792db4e3a68fa0cd7
parente7825f2b690c9a0d21b6f6d84c404bb53b151b38 (diff)
downloadrust-a090bb1dea18af72dce2195fa4de396bcb51061b.tar.gz
rust-a090bb1dea18af72dce2195fa4de396bcb51061b.zip
Remove delayed bug when encountering label in bad turbofish
-rw-r--r--compiler/rustc_parse/src/parser/diagnostics.rs2
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs5
-rw-r--r--src/test/ui/parser/issues/issue-93282.rs5
-rw-r--r--src/test/ui/parser/issues/issue-93282.stderr19
-rw-r--r--src/test/ui/parser/require-parens-for-chained-comparison.rs2
-rw-r--r--src/test/ui/parser/require-parens-for-chained-comparison.stderr18
6 files changed, 45 insertions, 6 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs
index c41f2d3299b..15f29d083db 100644
--- a/compiler/rustc_parse/src/parser/diagnostics.rs
+++ b/compiler/rustc_parse/src/parser/diagnostics.rs
@@ -737,7 +737,7 @@ impl<'a> Parser<'a> {
                                     "::".to_string(),
                                     Applicability::MaybeIncorrect,
                                 );
-                                if self.check(&TokenKind::Semi) {
+                                if matches!(self.token.kind, token::Semi | token::CloseDelim(_)) {
                                     turbo_err.emit();
                                     *expr = self.mk_expr_err(expr.span);
                                     return Ok(());
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index 26284728ff2..19ad1b3cec8 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -1448,6 +1448,8 @@ impl<'a> Parser<'a> {
         let lo = label.ident.span;
         let label = Some(label);
         let ate_colon = self.eat(&token::Colon);
+        let msg = "expected `while`, `for`, `loop` or `{` after a label";
+
         let expr = if self.eat_keyword(kw::While) {
             self.parse_while_expr(label, lo, attrs)
         } else if self.eat_keyword(kw::For) {
@@ -1457,13 +1459,12 @@ impl<'a> Parser<'a> {
         } else if self.check(&token::OpenDelim(token::Brace)) || self.token.is_whole_block() {
             self.parse_block_expr(label, lo, BlockCheckMode::Default, attrs)
         } else if !ate_colon && (self.check(&TokenKind::Comma) || self.check(&TokenKind::Gt)) {
+            self.struct_span_err(self.token.span, msg).span_label(self.token.span, msg).emit();
             // We're probably inside of a `Path<'a>` that needs a turbofish, so suppress the
             // "must be followed by a colon" error.
-            self.diagnostic().delay_span_bug(lo, "this label wasn't parsed correctly");
             consume_colon = false;
             Ok(self.mk_expr_err(lo))
         } else {
-            let msg = "expected `while`, `for`, `loop` or `{` after a label";
             self.struct_span_err(self.token.span, msg).span_label(self.token.span, msg).emit();
             // Continue as an expression in an effort to recover on `'label: non_block_expr`.
             self.parse_expr()
diff --git a/src/test/ui/parser/issues/issue-93282.rs b/src/test/ui/parser/issues/issue-93282.rs
new file mode 100644
index 00000000000..85a11866867
--- /dev/null
+++ b/src/test/ui/parser/issues/issue-93282.rs
@@ -0,0 +1,5 @@
+fn main() {
+    f<'a,>
+    //~^ ERROR expected
+    //~| ERROR expected
+}
diff --git a/src/test/ui/parser/issues/issue-93282.stderr b/src/test/ui/parser/issues/issue-93282.stderr
new file mode 100644
index 00000000000..a66beacc81d
--- /dev/null
+++ b/src/test/ui/parser/issues/issue-93282.stderr
@@ -0,0 +1,19 @@
+error: expected `while`, `for`, `loop` or `{` after a label
+  --> $DIR/issue-93282.rs:2:9
+   |
+LL |     f<'a,>
+   |         ^ expected `while`, `for`, `loop` or `{` after a label
+
+error: expected one of `.`, `:`, `;`, `?`, `for`, `loop`, `while`, `{`, `}`, or an operator, found `,`
+  --> $DIR/issue-93282.rs:2:9
+   |
+LL |     f<'a,>
+   |         ^ expected one of 10 possible tokens
+   |
+help: use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments
+   |
+LL |     f::<'a,>
+   |      ++
+
+error: aborting due to 2 previous errors
+
diff --git a/src/test/ui/parser/require-parens-for-chained-comparison.rs b/src/test/ui/parser/require-parens-for-chained-comparison.rs
index 68636f6b907..aaa703f763e 100644
--- a/src/test/ui/parser/require-parens-for-chained-comparison.rs
+++ b/src/test/ui/parser/require-parens-for-chained-comparison.rs
@@ -21,10 +21,12 @@ fn main() {
 
     let _ = f<'_, i8>();
     //~^ ERROR expected one of
+    //~| ERROR expected
     //~| HELP use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments
 
     f<'_>();
     //~^ comparison operators cannot be chained
+    //~| ERROR expected
     //~| HELP use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments
 
     let _ = f<u8>;
diff --git a/src/test/ui/parser/require-parens-for-chained-comparison.stderr b/src/test/ui/parser/require-parens-for-chained-comparison.stderr
index cde6f8c674f..92d700753dc 100644
--- a/src/test/ui/parser/require-parens-for-chained-comparison.stderr
+++ b/src/test/ui/parser/require-parens-for-chained-comparison.stderr
@@ -53,6 +53,12 @@ help: use `::<...>` instead of `<...>` to specify lifetime, type, or const argum
 LL |     let _ = f::<u8, i8>();
    |              ++
 
+error: expected `while`, `for`, `loop` or `{` after a label
+  --> $DIR/require-parens-for-chained-comparison.rs:22:17
+   |
+LL |     let _ = f<'_, i8>();
+   |                 ^ expected `while`, `for`, `loop` or `{` after a label
+
 error: expected one of `.`, `:`, `;`, `?`, `else`, `for`, `loop`, `while`, `{`, or an operator, found `,`
   --> $DIR/require-parens-for-chained-comparison.rs:22:17
    |
@@ -64,8 +70,14 @@ help: use `::<...>` instead of `<...>` to specify lifetime, type, or const argum
 LL |     let _ = f::<'_, i8>();
    |              ++
 
+error: expected `while`, `for`, `loop` or `{` after a label
+  --> $DIR/require-parens-for-chained-comparison.rs:27:9
+   |
+LL |     f<'_>();
+   |         ^ expected `while`, `for`, `loop` or `{` after a label
+
 error: comparison operators cannot be chained
-  --> $DIR/require-parens-for-chained-comparison.rs:26:6
+  --> $DIR/require-parens-for-chained-comparison.rs:27:6
    |
 LL |     f<'_>();
    |      ^  ^
@@ -76,7 +88,7 @@ LL |     f::<'_>();
    |      ++
 
 error: comparison operators cannot be chained
-  --> $DIR/require-parens-for-chained-comparison.rs:30:14
+  --> $DIR/require-parens-for-chained-comparison.rs:32:14
    |
 LL |     let _ = f<u8>;
    |              ^  ^
@@ -84,5 +96,5 @@ LL |     let _ = f<u8>;
    = help: use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments
    = help: or use `(...)` if you meant to specify fn arguments
 
-error: aborting due to 8 previous errors
+error: aborting due to 10 previous errors