Skip to content

Commit 89ad4f2

Browse files
Merge #1062
1062: Properly perform follow set checking on matcher r=CohenArthur a=CohenArthur Addresses #947 Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2 parents 0fa8821 + 912b042 commit 89ad4f2

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

gcc/rust/parse/rust-parse.cc

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,25 @@ peculiar_fragment_match_compatible (AST::MacroMatchFragment &last_match,
227227
}
228228
case AST::MacroMatch::Matcher: {
229229
auto matcher = static_cast<AST::MacroMatcher *> (&match);
230-
auto &matches = matcher->get_matches ();
231-
if (!matches.empty ())
232-
error_locus = matches.front ()->get_match_locus ();
230+
auto first_token = matcher->get_delim_type ();
231+
TokenId delim_id;
232+
switch (first_token)
233+
{
234+
case AST::PARENS:
235+
delim_id = LEFT_PAREN;
236+
break;
237+
case AST::SQUARE:
238+
delim_id = LEFT_SQUARE;
239+
break;
240+
case AST::CURLY:
241+
delim_id = LEFT_CURLY;
242+
break;
243+
}
244+
if (contains (allowed_toks, delim_id))
245+
return true;
246+
kind_str = "token `" + std::string (get_token_description (delim_id))
247+
+ "` at start of matcher";
248+
error_locus = matcher->get_match_locus ();
233249
break;
234250
}
235251
case AST::MacroMatch::Fragment: {

gcc/testsuite/rust/compile/macro39.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
macro_rules! m {
2+
($e:expr (, parenthesis_forbidden)) => {{}}; // { dg-error "token .\\(. at start of matcher is not allowed after .expr. fragment" }
3+
// { dg-error "required first macro rule" "" { target *-*-* } .-1 }
4+
// { dg-error "failed to parse item in crate" "" { target *-*-* } .-2 }
5+
}

0 commit comments

Comments
 (0)