diff --git a/src/librustc_parse/parser/path.rs b/src/librustc_parse/parser/path.rs index ee873df05ab7b..d8477ca01507d 100644 --- a/src/librustc_parse/parser/path.rs +++ b/src/librustc_parse/parser/path.rs @@ -456,8 +456,10 @@ impl<'a> Parser<'a> { } }) .is_some(); - // This will be true when a trait object type `Foo +` has been parsed. - let was_op = self.prev_token.kind == token::BinOp(token::Plus); + // This will be true when a trait object type `Foo +` or a path which was a `const fn` with + // type params has been parsed. + let was_op = + matches!(self.prev_token.kind, token::BinOp(token::Plus | token::Shr) | token::Gt); if !is_op && !was_op { // We perform these checks and early return to avoid taking a snapshot unnecessarily. return Err(err); diff --git a/src/test/ui/const-generics/const-expression-missing-braces.rs b/src/test/ui/const-generics/const-expression-missing-braces.rs index b6b9cdd87c5f9..36373532bf38d 100644 --- a/src/test/ui/const-generics/const-expression-missing-braces.rs +++ b/src/test/ui/const-generics/const-expression-missing-braces.rs @@ -27,4 +27,27 @@ fn e() { fn f() { foo::<100 - BAR>(); // ok } +fn g() { + foo::()>(); //~ ERROR expected one of +} +fn h() { + foo::()>(); //~ ERROR expected one of +} +fn i() { + foo::() + BAR>(); //~ ERROR expected one of +} +fn j() { + foo::() - BAR>(); //~ ERROR expected one of +} +fn k() { + foo::()>(); //~ ERROR expected one of +} +fn l() { + foo::()>(); //~ ERROR expected one of +} + +const fn bar() -> usize { + C +} + fn main() {} diff --git a/src/test/ui/const-generics/const-expression-missing-braces.stderr b/src/test/ui/const-generics/const-expression-missing-braces.stderr index fb8b0268b7b6b..61b080c9716d0 100644 --- a/src/test/ui/const-generics/const-expression-missing-braces.stderr +++ b/src/test/ui/const-generics/const-expression-missing-braces.stderr @@ -31,6 +31,72 @@ help: to write a `const` expression, surround it with braces for it to be unambi LL | foo::<{ BAR - BAR }>(); | ^ ^ +error: expected one of `,` or `>`, found `(` + --> $DIR/const-expression-missing-braces.rs:31:19 + | +LL | foo::()>(); + | ^ expected one of `,` or `>` + | +help: to write a `const` expression, surround it with braces for it to be unambiguous + | +LL | foo::<{ bar() }>(); + | ^ ^ + +error: expected one of `,` or `>`, found `(` + --> $DIR/const-expression-missing-braces.rs:34:21 + | +LL | foo::()>(); + | ^ expected one of `,` or `>` + | +help: to write a `const` expression, surround it with braces for it to be unambiguous + | +LL | foo::<{ bar::() }>(); + | ^ ^ + +error: expected one of `,` or `>`, found `(` + --> $DIR/const-expression-missing-braces.rs:37:21 + | +LL | foo::() + BAR>(); + | ^ expected one of `,` or `>` + | +help: to write a `const` expression, surround it with braces for it to be unambiguous + | +LL | foo::<{ bar::() + BAR }>(); + | ^ ^ + +error: expected one of `,` or `>`, found `(` + --> $DIR/const-expression-missing-braces.rs:40:21 + | +LL | foo::() - BAR>(); + | ^ expected one of `,` or `>` + | +help: to write a `const` expression, surround it with braces for it to be unambiguous + | +LL | foo::<{ bar::() - BAR }>(); + | ^ ^ + +error: expected one of `,` or `>`, found `-` + --> $DIR/const-expression-missing-braces.rs:43:15 + | +LL | foo::()>(); + | ^ expected one of `,` or `>` + | +help: to write a `const` expression, surround it with braces for it to be unambiguous + | +LL | foo::<{ BAR - bar::() }>(); + | ^ ^ + +error: expected one of `,` or `>`, found `-` + --> $DIR/const-expression-missing-braces.rs:46:15 + | +LL | foo::()>(); + | ^ expected one of `,` or `>` + | +help: to write a `const` expression, surround it with braces for it to be unambiguous + | +LL | foo::<{ BAR - bar::() }>(); + | ^ ^ + error: likely `const` expression parsed as trait bounds --> $DIR/const-expression-missing-braces.rs:13:11 | @@ -42,5 +108,5 @@ help: if you meant to write a `const` expression, surround the expression with b LL | foo::<{ BAR + BAR }>(); | ^ ^ -error: aborting due to 4 previous errors +error: aborting due to 10 previous errors