diff options
| author | Noah Lev <camelidcamel@gmail.com> | 2022-02-18 15:27:58 -0800 |
|---|---|---|
| committer | Noah Lev <camelidcamel@gmail.com> | 2022-03-23 22:31:57 -0700 |
| commit | 95960b7d54ecd05b03734cadea071cd5cc29fa35 (patch) | |
| tree | 5e084fabe1a14d4bfb90ec63e7f1d9bbbf2845a5 /compiler/rustc_parse/src/parser | |
| parent | 4212835d993537158aa39406a489351a4efdda71 (diff) | |
| download | rust-95960b7d54ecd05b03734cadea071cd5cc29fa35.tar.gz rust-95960b7d54ecd05b03734cadea071cd5cc29fa35.zip | |
Make `standalone` an enum
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 4f2a308f2e9..162982ebbe2 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -161,15 +161,24 @@ impl AttemptLocalParseRecovery { #[derive(Debug, Copy, Clone)] struct IncDecRecovery { /// Is this increment/decrement its own statement? - /// - /// This is `None` when we are unsure. - standalone: Option<bool>, + standalone: IsStandalone, /// Is this an increment or decrement? op: IncOrDec, /// Is this pre- or postfix? fixity: UnaryFixity, } +/// Is an increment or decrement expression its own statement? +#[derive(Debug, Copy, Clone)] +enum IsStandalone { + /// It's standalone, i.e., its own statement. + Standalone, + /// It's a subexpression, i.e., *not* standalone. + Subexpr, + /// It's maybe standalone; we're not sure. + Maybe, +} + #[derive(Debug, Copy, Clone, PartialEq, Eq)] enum IncOrDec { Inc, @@ -1226,11 +1235,9 @@ impl<'a> Parser<'a> { op_span: Span, prev_is_semi: bool, ) -> PResult<'a, P<Expr>> { - let kind = IncDecRecovery { - standalone: Some(prev_is_semi), - op: IncOrDec::Inc, - fixity: UnaryFixity::Pre, - }; + let standalone = + if prev_is_semi { IsStandalone::Standalone } else { IsStandalone::Subexpr }; + let kind = IncDecRecovery { standalone, op: IncOrDec::Inc, fixity: UnaryFixity::Pre }; self.recover_from_inc_dec(operand_expr, kind, op_span) } @@ -1240,8 +1247,11 @@ impl<'a> Parser<'a> { operand_expr: P<Expr>, op_span: Span, ) -> PResult<'a, P<Expr>> { - let kind = - IncDecRecovery { standalone: None, op: IncOrDec::Inc, fixity: UnaryFixity::Post }; + let kind = IncDecRecovery { + standalone: IsStandalone::Maybe, + op: IncOrDec::Inc, + fixity: UnaryFixity::Post, + }; self.recover_from_inc_dec(operand_expr, kind, op_span) } @@ -1271,8 +1281,10 @@ impl<'a> Parser<'a> { }; match kind.standalone { - Some(true) => self.inc_dec_standalone_recovery(&mut err, kind, spans, false), - Some(false) => { + IsStandalone::Standalone => { + self.inc_dec_standalone_recovery(&mut err, kind, spans, false) + } + IsStandalone::Subexpr => { let Ok(base_src) = self.span_to_snippet(base.span) else { return help_base_case(err, base) }; match kind.fixity { @@ -1284,7 +1296,7 @@ impl<'a> Parser<'a> { } } } - None => { + IsStandalone::Maybe => { let Ok(base_src) = self.span_to_snippet(base.span) else { return help_base_case(err, base) }; match kind.fixity { |
