diff options
| author | bors <bors@rust-lang.org> | 2024-02-27 11:03:07 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-02-27 11:03:07 +0000 |
| commit | 9afdb8d1d55f7ee80259009c39530d163d24dc65 (patch) | |
| tree | c992e58bb6760e15e4a5ccff02e98ebe8f058329 /compiler/rustc_parse/src/parser | |
| parent | 53ed660d47feb01055483fe81b628d5ef9705dbd (diff) | |
| parent | a8a486c846e29e663f7ee433a61613b98815cf4d (diff) | |
Auto merge of #121285 - nnethercote:delayed_bug-audit, r=lcnr
Delayed bug audit I went through all the calls to `delayed_bug` and `span_delayed_bug` and found a few places where they could be avoided. r? `@compiler-errors`
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 29 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/stmt.rs | 3 |
2 files changed, 14 insertions, 18 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, ()> { diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 15f8124823f..55d6f7d6281 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -230,8 +230,7 @@ impl<'a> Parser<'a> { /// Also error if the previous token was a doc comment. fn error_outer_attrs(&self, attrs: AttrWrapper) { if !attrs.is_empty() - && let attrs = attrs.take_for_recovery(self.sess) - && let attrs @ [.., last] = &*attrs + && let attrs @ [.., last] = &*attrs.take_for_recovery(self.sess) { if last.is_doc_comment() { self.dcx().emit_err(errors::DocCommentDoesNotDocumentAnything { |
