Add ErrorGuaranteed
to Recovered::Yes
and use it more.
The starting point for this was identical comments on two different fields, in `ast::VariantData::Struct` and `hir::VariantData::Struct`: ``` // FIXME: investigate making this a `Option<ErrorGuaranteed>` recovered: bool ``` I tried that, and then found that I needed to add an `ErrorGuaranteed` to `Recovered::Yes`. Then I ended up using `Recovered` instead of `Option<ErrorGuaranteed>` for these two places and elsewhere, which required moving `ErrorGuaranteed` from `rustc_parse` to `rustc_ast`. This makes things more consistent, because `Recovered` is used in more places, and there are fewer uses of `bool` and `Option<ErrorGuaranteed>`. And safer, because it's difficult/impossible to set `recovered` to `Recovered::Yes` without having emitted an error.
This commit is contained in:
parent
87293c9585
commit
fd91925bce
16 changed files with 91 additions and 105 deletions
|
@ -27,13 +27,12 @@ use rustc_ast::tokenstream::{TokenStream, TokenTree, TokenTreeCursor};
|
|||
use rustc_ast::util::case::Case;
|
||||
use rustc_ast::{
|
||||
self as ast, AnonConst, AttrArgs, AttrArgsEq, AttrId, ByRef, Const, CoroutineKind, DelimArgs,
|
||||
Expr, ExprKind, Extern, HasAttrs, HasTokens, Mutability, StrLit, Unsafe, Visibility,
|
||||
Expr, ExprKind, Extern, HasAttrs, HasTokens, Mutability, Recovered, StrLit, Unsafe, Visibility,
|
||||
VisibilityKind, DUMMY_NODE_ID,
|
||||
};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_errors::PResult;
|
||||
use rustc_errors::{Applicability, Diag, FatalError, MultiSpan};
|
||||
use rustc_errors::{Applicability, Diag, FatalError, MultiSpan, PResult};
|
||||
use rustc_session::parse::ParseSess;
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
|
@ -374,19 +373,6 @@ pub enum FollowedByType {
|
|||
No,
|
||||
}
|
||||
|
||||
/// Whether a function performed recovery
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum Recovered {
|
||||
No,
|
||||
Yes,
|
||||
}
|
||||
|
||||
impl From<Recovered> for bool {
|
||||
fn from(r: Recovered) -> bool {
|
||||
matches!(r, Recovered::Yes)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum Trailing {
|
||||
No,
|
||||
|
@ -856,9 +842,9 @@ impl<'a> Parser<'a> {
|
|||
Ok(Recovered::No) => {
|
||||
self.current_closure.take();
|
||||
}
|
||||
Ok(Recovered::Yes) => {
|
||||
Ok(Recovered::Yes(guar)) => {
|
||||
self.current_closure.take();
|
||||
recovered = Recovered::Yes;
|
||||
recovered = Recovered::Yes(guar);
|
||||
break;
|
||||
}
|
||||
Err(mut expect_err) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue