Skip to content

Commit 1353d0a

Browse files
committed
Fix Self macro invocation parsing failure
No check was performed and the value was assumed non null. Path conversion returned an empty path for "Self" due to a hack in generics Self injection that prevented any "Self!" macro from beeing recognized correctly. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_stmt_or_expr): Add null check on parse_macro_invocation_partial call. * ast/rust-path.cc (Path::convert_to_simple_path): Do not exclude capitalized "Self". gcc/testsuite/ChangeLog: * rust/compile/issue-3974.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
1 parent 5b7a0d7 commit 1353d0a

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

gcc/rust/ast/rust-path.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ Path::convert_to_simple_path (bool with_opening_scope_resolution) const
167167
for (const auto &segment : segments)
168168
{
169169
// return empty path if doesn't meet simple path segment requirements
170-
if (segment.is_error () || segment.has_generic_args ()
171-
|| segment.as_string () == "Self")
170+
if (segment.is_error () || segment.has_generic_args ())
172171
return SimplePath::create_empty ();
173172

174173
// create segment and add to vector

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11760,6 +11760,8 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr ()
1176011760
std::unique_ptr<AST::MacroInvocation> invoc
1176111761
= parse_macro_invocation_partial (std::move (path),
1176211762
std::move (outer_attrs));
11763+
if (invoc == nullptr)
11764+
return ExprOrStmt::create_error ();
1176311765

1176411766
if (restrictions.consume_semi && maybe_skip_token (SEMICOLON))
1176511767
{
@@ -11771,9 +11773,12 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr ()
1177111773

1177211774
TokenId after_macro = lexer.peek_token ()->get_id ();
1177311775

11774-
if (invoc->get_invoc_data ().get_delim_tok_tree ().get_delim_type ()
11775-
== AST::CURLY
11776-
&& after_macro != DOT && after_macro != QUESTION_MARK)
11776+
AST::DelimType delim_type = invoc->get_invoc_data ()
11777+
.get_delim_tok_tree ()
11778+
.get_delim_type ();
11779+
11780+
if (delim_type == AST::CURLY && after_macro != DOT
11781+
&& after_macro != QUESTION_MARK)
1177711782
{
1177811783
rust_debug ("braced macro statement");
1177911784
return ExprOrStmt (
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
impl<'a, F> RunUntil<'a, F> {
2+
// { dg-error "could not resolve type path" "" { target *-*-* } .-1 }
3+
fn project<'pin>() -> Projection<'pin, 'a, F> {
4+
// { dg-error "could not resolve type path" "" { target *-*-* } .-1 }
5+
Self!()
6+
// { dg-error "could not resolve macro invocation" "" { target *-*-* } .-1 }
7+
}
8+
}

0 commit comments

Comments
 (0)