about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/expr.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-11-14 06:30:18 +0000
committerbors <bors@rust-lang.org>2022-11-14 06:30:18 +0000
commit96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef (patch)
tree8fb6205431371f9923ca9eac04bbcbc0ce4c2e55 /compiler/rustc_parse/src/parser/expr.rs
parentf90a4ff26c9743abf612f015c4398d7158b646b6 (diff)
parent4fdd944af46e074807f132d46135f2945b57d1b0 (diff)
downloadrust-96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef.tar.gz
rust-96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef.zip
Auto merge of #104387 - Manishearth:rollup-9e551p5, r=Manishearth
Rollup of 9 pull requests

Successful merges:

 - #103709 (ci: Upgrade dist-x86_64-netbsd to NetBSD 9.0)
 - #103744 (Upgrade cc for working is_flag_supported on cross-compiles)
 - #104105 (llvm: dwo only emitted when object code emitted)
 - #104158 (Return .efi extension for EFI executable)
 - #104181 (Add a few known-bug tests)
 - #104266 (Regression test for coercion of mut-ref to dyn-star)
 - #104300 (Document `Path::parent` behavior around relative paths)
 - #104304 (Enable profiler in dist-s390x-linux)
 - #104362 (Add `delay_span_bug` to `AttrWrapper::take_for_recovery`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs15
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),