Skip to content

Commit 796114a

Browse files
committed
Add documentation
1 parent ed14202 commit 796114a

File tree

1 file changed

+8
-1
lines changed
  • compiler/rustc_parse/src/parser

1 file changed

+8
-1
lines changed

compiler/rustc_parse/src/parser/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub struct Parser<'a> {
158158
/// This allows us to recover when the user forget to add braces around
159159
/// multiple statements in the closure body.
160160
pub current_closure: Option<ClosureSpans>,
161-
/// Whether the parser is allowed to recover and parse invalid code successfully (and emit a diagnostic as a side effect).
161+
/// Whether the parser is allowed to do recovery.
162162
/// This is disabled when parsing macro arguments, see #103534
163163
pub recovery: Recovery,
164164
}
@@ -506,6 +506,13 @@ impl<'a> Parser<'a> {
506506
self
507507
}
508508

509+
/// Whether the parser is allowed to recover from broken code.
510+
///
511+
/// If this returns false, recovering broken code into valid code (especially if this recovery does lookahead)
512+
/// is not allowed. All recovery done by the parser must be gated behind this check.
513+
///
514+
/// Technically, this only needs to restruct eager recovery by doing lookahead at more tokens.
515+
/// But making the distinction is very subtle, and simply forbidding all recovery is a lot simpler to uphold.
509516
fn may_recover(&self) -> bool {
510517
matches!(self.recovery, Recovery::Allowed)
511518
}

0 commit comments

Comments
 (0)