Skip to content

Commit 9995bb5

Browse files
authored
Rollup merge of #60583 - varkor:const-generics-emplace, r=petrochenkov
Fix parsing issue with negative literals as const generic arguments
2 parents e280818 + e570fe5 commit 9995bb5

File tree

3 files changed

+4
-11
lines changed

3 files changed

+4
-11
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,7 +2319,8 @@ impl<'a> Parser<'a> {
23192319
let ident = self.parse_path_segment_ident()?;
23202320

23212321
let is_args_start = |token: &token::Token| match *token {
2322-
token::Lt | token::BinOp(token::Shl) | token::OpenDelim(token::Paren) => true,
2322+
token::Lt | token::BinOp(token::Shl) | token::OpenDelim(token::Paren)
2323+
| token::LArrow => true,
23232324
_ => false,
23242325
};
23252326
let check_args_start = |this: &mut Self| {
@@ -6056,8 +6057,6 @@ impl<'a> Parser<'a> {
60566057
self.fatal("identifiers may currently not be used for const generics")
60576058
);
60586059
} else {
6059-
// FIXME(const_generics): this currently conflicts with emplacement syntax
6060-
// with negative integer literals.
60616060
self.parse_literal_maybe_minus()?
60626061
};
60636062
let value = AnonConst {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn i32_identity<const X: i32>() -> i32 {
66
}
77

88
fn foo_a() {
9-
i32_identity::<-1>(); //~ ERROR expected identifier, found `<-`
9+
i32_identity::<-1>(); // ok
1010
}
1111

1212
fn foo_b() {
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
error: expected identifier, found `<-`
2-
--> $DIR/const-expression-parameter.rs:9:19
3-
|
4-
LL | i32_identity::<-1>();
5-
| ^^ expected identifier
6-
71
error: expected one of `,` or `>`, found `+`
82
--> $DIR/const-expression-parameter.rs:13:22
93
|
@@ -16,5 +10,5 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
1610
LL | #![feature(const_generics)]
1711
| ^^^^^^^^^^^^^^
1812

19-
error: aborting due to 2 previous errors
13+
error: aborting due to previous error
2014

0 commit comments

Comments
 (0)