mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 06:22:00 +00:00
Inline Parser::parse_item_common_
.
It has a single call site, it isn't that big, and its name is confusingly similar to `Parser::parse_item_common`.
This commit is contained in:
parent
2f305ff460
commit
48cdfc388d
@ -128,54 +128,43 @@ impl<'a> Parser<'a> {
|
||||
Some(item.into_inner())
|
||||
});
|
||||
|
||||
self.collect_tokens_trailing_token(attrs, force_collect, |this, attrs| {
|
||||
let item = this.parse_item_common_(attrs, mac_allowed, attrs_allowed, fn_parse_mode)?;
|
||||
Ok((item, TrailingToken::None))
|
||||
self.collect_tokens_trailing_token(attrs, force_collect, |this, mut attrs| {
|
||||
let lo = this.token.span;
|
||||
let vis = this.parse_visibility(FollowedByType::No)?;
|
||||
let mut def = this.parse_defaultness();
|
||||
let kind = this.parse_item_kind(
|
||||
&mut attrs,
|
||||
mac_allowed,
|
||||
lo,
|
||||
&vis,
|
||||
&mut def,
|
||||
fn_parse_mode,
|
||||
Case::Sensitive,
|
||||
)?;
|
||||
if let Some((ident, kind)) = kind {
|
||||
this.error_on_unconsumed_default(def, &kind);
|
||||
let span = lo.to(this.prev_token.span);
|
||||
let id = DUMMY_NODE_ID;
|
||||
let item = Item { ident, attrs, id, kind, vis, span, tokens: None };
|
||||
return Ok((Some(item), TrailingToken::None));
|
||||
}
|
||||
|
||||
// At this point, we have failed to parse an item.
|
||||
if !matches!(vis.kind, VisibilityKind::Inherited) {
|
||||
this.dcx().emit_err(errors::VisibilityNotFollowedByItem { span: vis.span, vis });
|
||||
}
|
||||
|
||||
if let Defaultness::Default(span) = def {
|
||||
this.dcx().emit_err(errors::DefaultNotFollowedByItem { span });
|
||||
}
|
||||
|
||||
if !attrs_allowed {
|
||||
this.recover_attrs_no_item(&attrs)?;
|
||||
}
|
||||
Ok((None, TrailingToken::None))
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_item_common_(
|
||||
&mut self,
|
||||
mut attrs: AttrVec,
|
||||
mac_allowed: bool,
|
||||
attrs_allowed: bool,
|
||||
fn_parse_mode: FnParseMode,
|
||||
) -> PResult<'a, Option<Item>> {
|
||||
let lo = self.token.span;
|
||||
let vis = self.parse_visibility(FollowedByType::No)?;
|
||||
let mut def = self.parse_defaultness();
|
||||
let kind = self.parse_item_kind(
|
||||
&mut attrs,
|
||||
mac_allowed,
|
||||
lo,
|
||||
&vis,
|
||||
&mut def,
|
||||
fn_parse_mode,
|
||||
Case::Sensitive,
|
||||
)?;
|
||||
if let Some((ident, kind)) = kind {
|
||||
self.error_on_unconsumed_default(def, &kind);
|
||||
let span = lo.to(self.prev_token.span);
|
||||
let id = DUMMY_NODE_ID;
|
||||
let item = Item { ident, attrs, id, kind, vis, span, tokens: None };
|
||||
return Ok(Some(item));
|
||||
}
|
||||
|
||||
// At this point, we have failed to parse an item.
|
||||
if !matches!(vis.kind, VisibilityKind::Inherited) {
|
||||
self.dcx().emit_err(errors::VisibilityNotFollowedByItem { span: vis.span, vis });
|
||||
}
|
||||
|
||||
if let Defaultness::Default(span) = def {
|
||||
self.dcx().emit_err(errors::DefaultNotFollowedByItem { span });
|
||||
}
|
||||
|
||||
if !attrs_allowed {
|
||||
self.recover_attrs_no_item(&attrs)?;
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
/// Error in-case `default` was parsed in an in-appropriate context.
|
||||
fn error_on_unconsumed_default(&self, def: Defaultness, kind: &ItemKind) {
|
||||
if let Defaultness::Default(span) = def {
|
||||
|
Loading…
Reference in New Issue
Block a user