Skip to content

parser: Implement recovery for potential unknown macro variables $ IDENT #69229

Open
@petrochenkov

Description

@petrochenkov

#69211 simplified parsing and fixed treatment of $ tokens coming from proc macros, but slightly regressed diagnostics.

If a declarative macro body contains something that looks like an unknown macro variable $ var, then it's preserved and outputted like two-token sequence punctuation $ and identifier var.

We previously tried to detect such sequences in Parser::bump, but the detection wasn't correct and wasn't done in the best way for recovery.

Instead, we need to support parsing the $ IDENT sequences in context dependent fashion, as an error expression in expression position, as an error type in type position etc.

Currently supported positions for macro variables (roughly in the order of importance):

  • expr
  • ty
  • pat
  • item
  • ident
  • lifetime
  • vis
  • path
  • block
  • literal
  • meta
  • stmt

It's quite possible that implementing this recovery for ident can successfully make implementing it for expr, ty, pat, path and meta unnecessary.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions