Skip to content

Commit a67aafd

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 6709c31 commit a67aafd

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
@@ -11761,6 +11761,8 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr ()
1176111761
std::unique_ptr<AST::MacroInvocation> invoc
1176211762
= parse_macro_invocation_partial (std::move (path),
1176311763
std::move (outer_attrs));
11764+
if (invoc == nullptr)
11765+
return ExprOrStmt::create_error ();
1176411766

1176511767
if (restrictions.consume_semi && maybe_skip_token (SEMICOLON))
1176611768
{
@@ -11772,9 +11774,12 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr ()
1177211774

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

11775-
if (invoc->get_invoc_data ().get_delim_tok_tree ().get_delim_type ()
11776-
== AST::CURLY
11777-
&& after_macro != DOT && after_macro != QUESTION_MARK)
11777+
AST::DelimType delim_type = invoc->get_invoc_data ()
11778+
.get_delim_tok_tree ()
11779+
.get_delim_type ();
11780+
11781+
if (delim_type == AST::CURLY && after_macro != DOT
11782+
&& after_macro != QUESTION_MARK)
1177811783
{
1177911784
rust_debug ("braced macro statement");
1178011785
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)