diff options
author | Tage Johansson <frans.tage@gmail.com> | 2023-03-04 19:43:02 +0100 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2023-03-16 10:19:16 +0000 |
commit | 0e010fc08b42cf4379e2ad1b51518c22a7f82186 (patch) | |
tree | 7a10cd3d564b6fd55a20eab18b4ddfcbf3e908f8 /gcc/rust | |
parent | ae80bcdd9b3bb8ace429804dd0f493d9f31b7c29 (diff) | |
download | gcc-0e010fc08b42cf4379e2ad1b51518c22a7f82186.zip gcc-0e010fc08b42cf4379e2ad1b51518c22a7f82186.tar.gz gcc-0e010fc08b42cf4379e2ad1b51518c22a7f82186.tar.bz2 |
gccrs: Add all rust keywords (except priv) to the follow-set of `:vis` when parsing macro rules
Previously, the following macro rules were rejected by gccrs:
```Rust
macro_rules! {
($v:vis <KEY_WORD>) => { ... };
}
```
This PR fixes so the above code is accepted by the compiler for all key words like `async` or `unsafe`.
The only exception is the keyword `priv` which is not allowed.
See [this page](https://doc.rust-lang.org/reference/macro-ambiguity.html) for reference. Especially the following excerpt:
> FOLLOW(vis) = {,l any keyword or identifier except a non-raw priv; any token that can begin a type; ident, ty, and path nonterminals}.
Fixes #1060
gcc/rust/ChangeLog:
* parse/rust-parse.cc: fix follow-sets
gcc/testsuite/ChangeLog:
* rust/compile/macro47.rs: Test that :vis can be followed by some keywords
* rust/compile/macro48.rs: Test that :vis cannot be followed by the keyword priv
Signed-off-by: Tage Johansson <frans.tage@gmail.com>
Diffstat (limited to 'gcc/rust')
-rw-r--r-- | gcc/rust/parse/rust-parse.cc | 92 |
1 files changed, 64 insertions, 28 deletions
diff --git a/gcc/rust/parse/rust-parse.cc b/gcc/rust/parse/rust-parse.cc index f1e2caa..1b565bc 100644 --- a/gcc/rust/parse/rust-parse.cc +++ b/gcc/rust/parse/rust-parse.cc @@ -17,6 +17,7 @@ along with GCC; see the file COPYING3. If not see #include "rust-parse.h" #include "rust-linemap.h" #include "rust-diagnostics.h" +#include "rust-token.h" namespace Rust { @@ -166,34 +167,69 @@ peculiar_fragment_match_compatible (const AST::MacroMatchFragment &last_match, {MATCH_ARROW, COMMA, EQUAL, PIPE, SEMICOLON, COLON, RIGHT_ANGLE, RIGHT_SHIFT, LEFT_SQUARE, LEFT_CURLY, AS, WHERE}}, {AST::MacroFragSpec::VIS, - { - COMMA, - IDENTIFIER /* FIXME: Other than `priv` */, - LEFT_PAREN, - LEFT_SQUARE, - EXCLAM, - ASTERISK, - AMP, - LOGICAL_AND, - QUESTION_MARK, - LIFETIME, - LEFT_ANGLE, - LEFT_SHIFT, - SUPER, - SELF, - SELF_ALIAS, - EXTERN_TOK, - CRATE, - UNDERSCORE, - FOR, - IMPL, - FN_TOK, - UNSAFE, - TYPEOF, - DYN - // FIXME: Add Non kw identifiers - // FIXME: Add $crate as valid - }}}; + {COMMA, + IDENTIFIER, + LEFT_PAREN, + LEFT_SQUARE, + EXCLAM, + ASTERISK, + AMP, + LOGICAL_AND, + QUESTION_MARK, + LIFETIME, + LEFT_ANGLE, + LEFT_SHIFT, + UNDERSCORE, + ABSTRACT, + AS, + ASYNC, + AUTO, + BECOME, + BOX, + BREAK, + CONST, + CONTINUE, + CRATE, + DO, + DYN, + ELSE, + ENUM_TOK, + EXTERN_TOK, + FALSE_LITERAL, + FINAL_TOK, + FN_TOK, + FOR, + IF, + IMPL, + IN, + LET, + LOOP, + MACRO, + MATCH_TOK, + MOD, + MOVE, + MUT, + OVERRIDE_TOK, + PUB, + REF, + RETURN_TOK, + SELF_ALIAS, + SELF, + STATIC_TOK, + STRUCT_TOK, + SUPER, + TRAIT, + TRUE_LITERAL, + TRY, + TYPE, + TYPEOF, + UNSAFE, + UNSIZED, + USE, + VIRTUAL, + WHERE, + WHILE, + YIELD}}}; Location error_locus = match.get_match_locus (); std::string kind_str = "fragment"; |