mirror of
https://github.com/allankoechke/rust.git
synced 2026-12-03 09:32:42 +00:00
Instead of checking for `#[` before trying to parse outer attributes,
check for `#` or doc comments instead. This way, we automatically recover
from leading doc comments and inner attributes on types, too.
Previously, we would only recover from doc comments and inner attributes
on types if they were preceded by normal outer attributes.
Move the whole recovery into a separate more general function in
preparation for using it in various other places, too.
This means we drop the recovery from attributes in type contexts that
aren't ascribed to a valid type (at least until the next sync point).
For example, `type T = #[a];` and `fn f() -> #[a] {}` are now fatal
(meaning the parser will only continue parsing from the next sync point).
This could be considered unfortunate but honestly it didn't make much sense:
Why would we only defatalize syntax errors in type contexts if there are
preceding attributes (which aren't legal / expected on types in the first
place, mind you); there's no reason to recover from e.g., `type T = #[a] @;`
(which used to lead to bad follow-up diagnostics). Defatalizing syntax
errors isn't inherently bad, it just needs to be done carefully and not
made dependent on "random" conditions.