]> git.lizzy.rs Git - rust.git/commitdiff
cancel a not emitted error after parsing const generic args
authorTakayuki Maeda <takoyaki0316@gmail.com>
Tue, 22 Mar 2022 07:06:56 +0000 (16:06 +0900)
committerTakayuki Maeda <takoyaki0316@gmail.com>
Tue, 22 Mar 2022 07:06:56 +0000 (16:06 +0900)
compiler/rustc_parse/src/parser/path.rs
src/test/ui/const-generics/ice-const-generic-function-return-ty.rs [new file with mode: 0644]
src/test/ui/const-generics/ice-const-generic-function-return-ty.stderr [new file with mode: 0644]

index 17c57867cf9cfff8435f098efa7891060d29a860..07ce879de8f0ee629999d4e99dffef2fc2badd51 100644 (file)
@@ -630,10 +630,14 @@ pub(super) fn parse_generic_arg(
                 Ok(ty) => GenericArg::Type(ty),
                 Err(err) => {
                     if is_const_fn {
-                        if let Ok(expr) = (*snapshot).parse_expr_res(Restrictions::CONST_EXPR, None)
-                        {
-                            self.restore_snapshot(snapshot);
-                            return Ok(Some(self.dummy_const_arg_needs_braces(err, expr.span)));
+                        match (*snapshot).parse_expr_res(Restrictions::CONST_EXPR, None) {
+                            Ok(expr) => {
+                                self.restore_snapshot(snapshot);
+                                return Ok(Some(self.dummy_const_arg_needs_braces(err, expr.span)));
+                            }
+                            Err(err) => {
+                                err.cancel();
+                            }
                         }
                     }
                     // Try to recover from possible `const` arg without braces.
diff --git a/src/test/ui/const-generics/ice-const-generic-function-return-ty.rs b/src/test/ui/const-generics/ice-const-generic-function-return-ty.rs
new file mode 100644 (file)
index 0000000..2bf628a
--- /dev/null
@@ -0,0 +1,5 @@
+// #95163
+fn return_ty() -> impl Into<<() as Reexported;
+//~^ ERROR expected one of `(`, `::`, `<`, or `>`, found `;`
+
+fn main() {}
diff --git a/src/test/ui/const-generics/ice-const-generic-function-return-ty.stderr b/src/test/ui/const-generics/ice-const-generic-function-return-ty.stderr
new file mode 100644 (file)
index 0000000..a72f580
--- /dev/null
@@ -0,0 +1,8 @@
+error: expected one of `(`, `::`, `<`, or `>`, found `;`
+  --> $DIR/ice-const-generic-function-return-ty.rs:2:46
+   |
+LL | fn return_ty() -> impl Into<<() as Reexported;
+   |                                              ^ expected one of `(`, `::`, `<`, or `>`
+
+error: aborting due to previous error
+