mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Refactor take_for_recovery
call sites.
To make them more concise and similar to each other.
This commit is contained in:
parent
62b4e55112
commit
a8a486c846
@ -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, ()> {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user