Skip to content

Commit 451f128

Browse files
committed
Parse negative literals in const generic arguments
1 parent 9ad04b9 commit 451f128

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5796,8 +5796,7 @@ impl<'a> Parser<'a> {
57965796
} else {
57975797
// FIXME(const_generics): this currently conflicts with emplacement syntax
57985798
// with negative integer literals.
5799-
let lit = self.parse_lit()?;
5800-
self.mk_expr(lit.span, ExprKind::Lit(lit), ThinVec::new())
5799+
self.parse_literal_maybe_minus()?
58015800
};
58025801
let value = AnonConst {
58035802
id: ast::DUMMY_NODE_ID,

src/test/ui/const-generics/const-expression-parameter.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ fn foo_b() {
1414
u32_identity::<1 + 2>(); //~ ERROR expected one of `,` or `>`, found `+`
1515
}
1616

17+
fn foo_c() {
18+
u32_identity::< -1 >(); // ok
19+
}
20+
1721
fn main() {
1822
u32_identity::<5>(); // ok
1923
}

0 commit comments

Comments
 (0)