Skip to content

Commit 5120701

Browse files
committed
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>
1 parent 64be9c3 commit 5120701

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

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

+19-18
Original file line numberDiff line numberDiff line change
@@ -5094,6 +5094,18 @@ Parser<ManagedTokenSource>::parse_trait_item ()
50945094
const_TokenPtr tok = lexer.peek_token ();
50955095
switch (tok->get_id ())
50965096
{
5097+
case SUPER:
5098+
case SELF:
5099+
case CRATE:
5100+
case DOLLAR_SIGN:
5101+
// these seem to be SimplePath tokens, so this is a macro invocation
5102+
// semi
5103+
return parse_macro_invocation_semi (std::move (outer_attrs));
5104+
case IDENTIFIER:
5105+
if (lexer.peek_token ()->get_str () == Values::WeakKeywords::DEFAULT)
5106+
return parse_function (std::move (vis), std::move (outer_attrs));
5107+
else
5108+
return parse_macro_invocation_semi (std::move (outer_attrs));
50975109
case TYPE:
50985110
return parse_trait_type (std::move (outer_attrs), vis);
50995111
case CONST:
@@ -5110,25 +5122,14 @@ Parser<ManagedTokenSource>::parse_trait_item ()
51105122
case EXTERN_KW:
51115123
case FN_KW:
51125124
return parse_function (std::move (vis), std::move (outer_attrs));
5113-
5114-
default: {
5115-
// TODO: try and parse macro invocation semi - if fails, maybe error.
5116-
std::unique_ptr<AST::TraitItem> macro_invoc
5117-
= parse_macro_invocation_semi (outer_attrs);
5118-
5119-
if (macro_invoc == nullptr)
5120-
{
5121-
// TODO: error?
5122-
return nullptr;
5123-
}
5124-
else
5125-
{
5126-
return macro_invoc;
5127-
}
5128-
/* FIXME: macro invocations can only start with certain tokens. be
5129-
* more picky with these? */
5130-
}
5125+
default:
5126+
break;
51315127
}
5128+
add_error (Error (tok->get_locus (),
5129+
"unrecognised token %qs for item in trait",
5130+
tok->get_token_description ()));
5131+
// skip?
5132+
return nullptr;
51325133
}
51335134

51345135
// Parse a typedef trait item.

0 commit comments

Comments
 (0)