diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2022-11-13 21:49:27 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-13 21:49:27 -0500 |
| commit | 4fdd944af46e074807f132d46135f2945b57d1b0 (patch) | |
| tree | 85eb81afecd1160a935b9fed19d8ebdcba0b88d7 /compiler/rustc_parse/src/parser/expr.rs | |
| parent | 7678cfdf187a434672f1931cf83fcc8533bc9db8 (diff) | |
| parent | df86ad8d36a038ee61e3ee977082ea6623613bbd (diff) | |
| download | rust-4fdd944af46e074807f132d46135f2945b57d1b0.tar.gz rust-4fdd944af46e074807f132d46135f2945b57d1b0.zip | |
Rollup merge of #104362 - WaffleLapkin:span_bug_won't_come_on_time_today, r=Aaron1011
Add `delay_span_bug` to `AttrWrapper::take_for_recovery` `take_for_recovery` should only be used for recovery (when we should already have an error), so using `delay_span_bug` seems appropriate. cc `@Aaron1011` (you've added the `FIXME` that this pr fixes)
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 7355730c9eb..b072573af23 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -2272,7 +2272,7 @@ impl<'a> Parser<'a> { self.mk_block_err(cond_span.shrink_to_hi()) } } else { - let attrs = self.parse_outer_attributes()?.take_for_recovery(); // For recovery. + let attrs = self.parse_outer_attributes()?; // For recovery. let block = if self.check(&token::OpenDelim(Delimiter::Brace)) { self.parse_block()? } else { @@ -2289,7 +2289,7 @@ impl<'a> Parser<'a> { })? } }; - self.error_on_if_block_attrs(lo, false, block.span, &attrs); + self.error_on_if_block_attrs(lo, false, block.span, attrs); block }; let els = if self.eat_keyword(kw::Else) { Some(self.parse_else_expr()?) } else { None }; @@ -2350,7 +2350,7 @@ impl<'a> Parser<'a> { /// Parses an `else { ... }` expression (`else` token already eaten). fn parse_else_expr(&mut self) -> PResult<'a, P<Expr>> { let else_span = self.prev_token.span; // `else` - let attrs = self.parse_outer_attributes()?.take_for_recovery(); // For recovery. + let attrs = self.parse_outer_attributes()?; // For recovery. let expr = if self.eat_keyword(kw::If) { self.parse_if_expr()? } else if self.check(&TokenKind::OpenDelim(Delimiter::Brace)) { @@ -2385,7 +2385,7 @@ impl<'a> Parser<'a> { }, } }; - self.error_on_if_block_attrs(else_span, true, expr.span, &attrs); + self.error_on_if_block_attrs(else_span, true, expr.span, attrs); Ok(expr) } @@ -2394,8 +2394,13 @@ impl<'a> Parser<'a> { ctx_span: Span, is_ctx_else: bool, branch_span: Span, - attrs: &[ast::Attribute], + attrs: AttrWrapper, ) { + if attrs.is_empty() { + return; + } + + 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), |
