diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-02-19 09:59:56 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-02-27 16:40:15 +1100 |
| commit | a8a486c846e29e663f7ee433a61613b98815cf4d (patch) | |
| tree | 3e3b55d12f73ab23ce1617bea3fdcef3fe313458 /compiler/rustc_parse/src/parser/expr.rs | |
| parent | 62b4e551124ffc38196740efd6ff3b6979a504eb (diff) | |
| download | rust-a8a486c846e29e663f7ee433a61613b98815cf4d.tar.gz rust-a8a486c846e29e663f7ee433a61613b98815cf4d.zip | |
Refactor `take_for_recovery` call sites.
To make them more concise and similar to each other.
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index e1a5e17004f..f5d4f4f57b9 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -2688,23 +2688,20 @@ impl<'a> Parser<'a> { branch_span: Span, attrs: AttrWrapper, ) { - if attrs.is_empty() { - return; + if !attrs.is_empty() + && let [x0 @ xn] | [x0, .., xn] = &*attrs.take_for_recovery(self.sess) + { + let attributes = x0.span.to(xn.span); + let last = xn.span; + let ctx = if is_ctx_else { "else" } else { "if" }; + self.dcx().emit_err(errors::OuterAttributeNotAllowedOnIfElse { + last, + branch_span, + ctx_span, + ctx: ctx.to_string(), + attributes, + }); } - - let attrs: &[ast::Attribute] = &attrs.take_for_recovery(self.sess); - let (attributes, last) = match attrs { - [] => return, - [x0 @ xn] | [x0, .., xn] => (x0.span.to(xn.span), xn.span), - }; - let ctx = if is_ctx_else { "else" } else { "if" }; - self.dcx().emit_err(errors::OuterAttributeNotAllowedOnIfElse { - last, - branch_span, - ctx_span, - ctx: ctx.to_string(), - attributes, - }); } fn error_on_extra_if(&mut self, cond: &P<Expr>) -> PResult<'a, ()> { |
