Remove error condition in parse_attribute
This function is only ever called when the `#` has already been consumed, no need to produce an error message here.
This commit is contained in:
parent
e1b1d7b029
commit
4d0519a4e7
@ -124,35 +124,22 @@ impl<'a> Parser<'a> {
|
|||||||
let lo = self.token.span;
|
let lo = self.token.span;
|
||||||
// Attributes can't have attributes of their own [Editor's note: not with that attitude]
|
// Attributes can't have attributes of their own [Editor's note: not with that attitude]
|
||||||
self.collect_tokens_no_attrs(|this| {
|
self.collect_tokens_no_attrs(|this| {
|
||||||
if this.eat(&token::Pound) {
|
assert!(this.eat(&token::Pound), "parse_attribute called in non-attribute position");
|
||||||
let style = if this.eat(&token::Not) {
|
|
||||||
ast::AttrStyle::Inner
|
|
||||||
} else {
|
|
||||||
ast::AttrStyle::Outer
|
|
||||||
};
|
|
||||||
|
|
||||||
this.expect(&token::OpenDelim(Delimiter::Bracket))?;
|
let style =
|
||||||
let item = this.parse_attr_item(false)?;
|
if this.eat(&token::Not) { ast::AttrStyle::Inner } else { ast::AttrStyle::Outer };
|
||||||
this.expect(&token::CloseDelim(Delimiter::Bracket))?;
|
|
||||||
let attr_sp = lo.to(this.prev_token.span);
|
|
||||||
|
|
||||||
// Emit error if inner attribute is encountered and forbidden.
|
this.expect(&token::OpenDelim(Delimiter::Bracket))?;
|
||||||
if style == ast::AttrStyle::Inner {
|
let item = this.parse_attr_item(false)?;
|
||||||
this.error_on_forbidden_inner_attr(attr_sp, inner_parse_policy);
|
this.expect(&token::CloseDelim(Delimiter::Bracket))?;
|
||||||
}
|
let attr_sp = lo.to(this.prev_token.span);
|
||||||
|
|
||||||
Ok(attr::mk_attr_from_item(
|
// Emit error if inner attribute is encountered and forbidden.
|
||||||
&self.sess.attr_id_generator,
|
if style == ast::AttrStyle::Inner {
|
||||||
item,
|
this.error_on_forbidden_inner_attr(attr_sp, inner_parse_policy);
|
||||||
None,
|
|
||||||
style,
|
|
||||||
attr_sp,
|
|
||||||
))
|
|
||||||
} else {
|
|
||||||
let token_str = pprust::token_to_string(&this.token);
|
|
||||||
let msg = &format!("expected `#`, found `{token_str}`");
|
|
||||||
Err(this.struct_span_err(this.token.span, msg))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(attr::mk_attr_from_item(&self.sess.attr_id_generator, item, None, style, attr_sp))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user