Skip to content

Commit a0fbf1f

Browse files
powerboat9CohenArthur
authored andcommitted
Expect identifier subpatterns to be non-alt
Fixes #4071. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_identifier_pattern): Use parse_pattern_no_alt to parse identifier pattern subpatterns. (Parser::parse_ident_leading_pattern): Likewise. gcc/testsuite/ChangeLog: * rust/compile/parse_closure_bind.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
1 parent 2d376a2 commit a0fbf1f

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

gcc/rust/parse/rust-parse-impl.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11113,7 +11113,7 @@ Parser<ManagedTokenSource>::parse_identifier_pattern ()
1111311113
lexer.skip_token ();
1111411114

1111511115
// parse required pattern to bind
11116-
bind_pattern = parse_pattern ();
11116+
bind_pattern = parse_pattern_no_alt ();
1111711117
if (bind_pattern == nullptr)
1111811118
{
1111911119
Error error (lexer.peek_token ()->get_locus (),
@@ -11240,7 +11240,8 @@ Parser<ManagedTokenSource>::parse_ident_leading_pattern ()
1124011240
// identifier with pattern bind
1124111241
lexer.skip_token ();
1124211242

11243-
std::unique_ptr<AST::Pattern> bind_pattern = parse_pattern ();
11243+
std::unique_ptr<AST::Pattern> bind_pattern
11244+
= parse_pattern_no_alt ();
1124411245
if (bind_pattern == nullptr)
1124511246
{
1124611247
Error error (
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// { dg-additional-options "-frust-compile-until=typecheck" }
2+
// TODO: this should typecheck
3+
4+
#[lang = "sized"]
5+
trait Sized {}
6+
7+
#[lang = "fn_once"]
8+
pub trait FnOnce<Args> {
9+
/// The returned type after the call operator is used.
10+
#[lang = "fn_once_output"]
11+
type Output;
12+
13+
/// Performs the call operation.
14+
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
15+
}
16+
17+
pub fn foo() {
18+
(|_a @ _b| {}) (1)
19+
}

0 commit comments

Comments
 (0)