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 <pierre-emmanuel.patry@embecosm.com>
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
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))
{
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 (
--- /dev/null
+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 }
+ }
+}