aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/parse
diff options
context:
space:
mode:
authorKushal Pal <kushalpal109@gmail.com>2024-01-26 18:35:59 +0530
committerCohenArthur <arthur.cohen@embecosm.com>2024-02-05 17:08:39 +0000
commit1e0e6a46abec24271ddea3f4936f2b94d7e2465e (patch)
tree8d81767c97b1d3037b725bc2f4c110ceadaf1238 /gcc/rust/parse
parentdf78aec1a2772ecb205284324c9472abfda4abf2 (diff)
downloadgcc-1e0e6a46abec24271ddea3f4936f2b94d7e2465e.zip
gcc-1e0e6a46abec24271ddea3f4936f2b94d7e2465e.tar.gz
gcc-1e0e6a46abec24271ddea3f4936f2b94d7e2465e.tar.bz2
Fix macro parsing for trait items.
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_trait_item): Handle macros in trait items similar to how its handled for trait implementation items. Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Diffstat (limited to 'gcc/rust/parse')
-rw-r--r--gcc/rust/parse/rust-parse-impl.h37
1 files changed, 19 insertions, 18 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index ce7b9cc..9fa6d69 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -5094,6 +5094,18 @@ Parser<ManagedTokenSource>::parse_trait_item ()
const_TokenPtr tok = lexer.peek_token ();
switch (tok->get_id ())
{
+ case SUPER:
+ case SELF:
+ case CRATE:
+ case DOLLAR_SIGN:
+ // these seem to be SimplePath tokens, so this is a macro invocation
+ // semi
+ return parse_macro_invocation_semi (std::move (outer_attrs));
+ case IDENTIFIER:
+ if (lexer.peek_token ()->get_str () == Values::WeakKeywords::DEFAULT)
+ return parse_function (std::move (vis), std::move (outer_attrs));
+ else
+ return parse_macro_invocation_semi (std::move (outer_attrs));
case TYPE:
return parse_trait_type (std::move (outer_attrs), vis);
case CONST:
@@ -5110,25 +5122,14 @@ Parser<ManagedTokenSource>::parse_trait_item ()
case EXTERN_KW:
case FN_KW:
return parse_function (std::move (vis), std::move (outer_attrs));
-
- default: {
- // TODO: try and parse macro invocation semi - if fails, maybe error.
- std::unique_ptr<AST::TraitItem> macro_invoc
- = parse_macro_invocation_semi (outer_attrs);
-
- if (macro_invoc == nullptr)
- {
- // TODO: error?
- return nullptr;
- }
- else
- {
- return macro_invoc;
- }
- /* FIXME: macro invocations can only start with certain tokens. be
- * more picky with these? */
- }
+ default:
+ break;
}
+ add_error (Error (tok->get_locus (),
+ "unrecognised token %qs for item in trait",
+ tok->get_token_description ()));
+ // skip?
+ return nullptr;
}
// Parse a typedef trait item.