Prepare for invisible delimiters.

Current places where `Interpolated` is used are going to change to
instead use invisible delimiters. This prepares for that.
- It adds invisible delimiter cases to the `can_begin_*`/`may_be_*`
  methods and the `failed_to_match_macro` that are equivalent to the
  existing `Interpolated` cases.
- It adds panics/asserts in some places where invisible delimiters
  should never occur.
- In `Parser::parse_struct_fields` it excludes an ident + invisible
  delimiter from special consideration in an error message, because
  that's quite different to an ident + paren/brace/bracket.
This commit is contained in:
Nicholas Nethercote 2024-04-17 09:37:00 +10:00
parent cfafa9380b
commit cee88f7a3f
5 changed files with 108 additions and 14 deletions

View file

@ -3591,11 +3591,19 @@ impl<'a> Parser<'a> {
&& !self.token.is_reserved_ident()
&& self.look_ahead(1, |t| {
AssocOp::from_token(t).is_some()
|| matches!(t.kind, token::OpenDelim(_))
|| matches!(
t.kind,
token::OpenDelim(
Delimiter::Parenthesis
| Delimiter::Bracket
| Delimiter::Brace
)
)
|| *t == token::Dot
})
{
// Looks like they tried to write a shorthand, complex expression.
// Looks like they tried to write a shorthand, complex expression,
// E.g.: `n + m`, `f(a)`, `a[i]`, `S { x: 3 }`, or `x.y`.
e.span_suggestion_verbose(
self.token.span.shrink_to_lo(),
"try naming a field",