Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing issue with negative literals as const generic arguments #60583

Merged
merged 2 commits into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2319,7 +2319,8 @@ impl<'a> Parser<'a> {
let ident = self.parse_path_segment_ident()?;

let is_args_start = |token: &token::Token| match *token {
token::Lt | token::BinOp(token::Shl) | token::OpenDelim(token::Paren) => true,
token::Lt | token::BinOp(token::Shl) | token::OpenDelim(token::Paren)
| token::LArrow => true,
_ => false,
};
let check_args_start = |this: &mut Self| {
Expand Down Expand Up @@ -6060,8 +6061,6 @@ impl<'a> Parser<'a> {
self.fatal("identifiers may currently not be used for const generics")
);
} else {
// FIXME(const_generics): this currently conflicts with emplacement syntax
// with negative integer literals.
self.parse_literal_maybe_minus()?
};
let value = AnonConst {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/const-expression-parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn i32_identity<const X: i32>() -> i32 {
}

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

fn foo_b() {
Expand Down
8 changes: 1 addition & 7 deletions src/test/ui/const-generics/const-expression-parameter.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
error: expected identifier, found `<-`
--> $DIR/const-expression-parameter.rs:9:19
|
LL | i32_identity::<-1>();
| ^^ expected identifier

error: expected one of `,` or `>`, found `+`
--> $DIR/const-expression-parameter.rs:13:22
|
Expand All @@ -16,5 +10,5 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^

error: aborting due to 2 previous errors
error: aborting due to previous error