From 451f1287839451fc097a406fad1a9160c22c280a Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 7 Feb 2019 14:58:47 +0100 Subject: [PATCH] Parse negative literals in const generic arguments --- src/libsyntax/parse/parser.rs | 3 +-- src/test/ui/const-generics/const-expression-parameter.rs | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d9195ebe312..d71145893c3 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -5796,8 +5796,7 @@ impl<'a> Parser<'a> { } else { // FIXME(const_generics): this currently conflicts with emplacement syntax // with negative integer literals. - let lit = self.parse_lit()?; - self.mk_expr(lit.span, ExprKind::Lit(lit), ThinVec::new()) + self.parse_literal_maybe_minus()? }; let value = AnonConst { id: ast::DUMMY_NODE_ID, diff --git a/src/test/ui/const-generics/const-expression-parameter.rs b/src/test/ui/const-generics/const-expression-parameter.rs index c582c596bfc..f4e9008dbd0 100644 --- a/src/test/ui/const-generics/const-expression-parameter.rs +++ b/src/test/ui/const-generics/const-expression-parameter.rs @@ -14,6 +14,10 @@ fn foo_b() { u32_identity::<1 + 2>(); //~ ERROR expected one of `,` or `>`, found `+` } +fn foo_c() { + u32_identity::< -1 >(); // ok +} + fn main() { u32_identity::<5>(); // ok }