1
Fork 0

Refactor take_for_recovery call sites.

To make them more concise and similar to each other.
This commit is contained in:
Nicholas Nethercote 2024-02-19 09:59:56 +11:00
parent 62b4e55112
commit a8a486c846
2 changed files with 14 additions and 18 deletions

View file

@ -2688,15 +2688,11 @@ impl<'a> Parser<'a> {
branch_span: Span, branch_span: Span,
attrs: AttrWrapper, attrs: AttrWrapper,
) { ) {
if attrs.is_empty() { if !attrs.is_empty()
return; && let [x0 @ xn] | [x0, .., xn] = &*attrs.take_for_recovery(self.sess)
} {
let attributes = x0.span.to(xn.span);
let attrs: &[ast::Attribute] = &attrs.take_for_recovery(self.sess); let last = xn.span;
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" }; let ctx = if is_ctx_else { "else" } else { "if" };
self.dcx().emit_err(errors::OuterAttributeNotAllowedOnIfElse { self.dcx().emit_err(errors::OuterAttributeNotAllowedOnIfElse {
last, last,
@ -2706,6 +2702,7 @@ impl<'a> Parser<'a> {
attributes, attributes,
}); });
} }
}
fn error_on_extra_if(&mut self, cond: &P<Expr>) -> PResult<'a, ()> { fn error_on_extra_if(&mut self, cond: &P<Expr>) -> PResult<'a, ()> {
if let ExprKind::Binary(Spanned { span: binop_span, node: binop }, _, right) = &cond.kind if let ExprKind::Binary(Spanned { span: binop_span, node: binop }, _, right) = &cond.kind

View file

@ -230,8 +230,7 @@ impl<'a> Parser<'a> {
/// Also error if the previous token was a doc comment. /// Also error if the previous token was a doc comment.
fn error_outer_attrs(&self, attrs: AttrWrapper) { fn error_outer_attrs(&self, attrs: AttrWrapper) {
if !attrs.is_empty() if !attrs.is_empty()
&& let attrs = attrs.take_for_recovery(self.sess) && let attrs @ [.., last] = &*attrs.take_for_recovery(self.sess)
&& let attrs @ [.., last] = &*attrs
{ {
if last.is_doc_comment() { if last.is_doc_comment() {
self.dcx().emit_err(errors::DocCommentDoesNotDocumentAnything { self.dcx().emit_err(errors::DocCommentDoesNotDocumentAnything {