Skip to content

Fix Self macro and partial macro invocation parsing null check #4073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions gcc/rust/ast/rust-path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ Path::convert_to_simple_path (bool with_opening_scope_resolution) const
for (const auto &segment : segments)
{
// return empty path if doesn't meet simple path segment requirements
if (segment.is_error () || segment.has_generic_args ()
|| segment.as_string () == "Self")
if (segment.is_error () || segment.has_generic_args ())
return SimplePath::create_empty ();

// create segment and add to vector
Expand Down
11 changes: 8 additions & 3 deletions gcc/rust/parse/rust-parse-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11760,6 +11760,8 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr ()
std::unique_ptr<AST::MacroInvocation> invoc
= parse_macro_invocation_partial (std::move (path),
std::move (outer_attrs));
if (invoc == nullptr)
return ExprOrStmt::create_error ();

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

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

if (invoc->get_invoc_data ().get_delim_tok_tree ().get_delim_type ()
== AST::CURLY
&& after_macro != DOT && after_macro != QUESTION_MARK)
AST::DelimType delim_type = invoc->get_invoc_data ()
.get_delim_tok_tree ()
.get_delim_type ();

if (delim_type == AST::CURLY && after_macro != DOT
&& after_macro != QUESTION_MARK)
{
rust_debug ("braced macro statement");
return ExprOrStmt (
Expand Down
8 changes: 8 additions & 0 deletions gcc/testsuite/rust/compile/issue-3974.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
impl<'a, F> RunUntil<'a, F> {
// { dg-error "could not resolve type path" "" { target *-*-* } .-1 }
fn project<'pin>() -> Projection<'pin, 'a, F> {
// { dg-error "could not resolve type path" "" { target *-*-* } .-1 }
Self!()
// { dg-error "could not resolve macro invocation" "" { target *-*-* } .-1 }
}
}
Loading