Skip to content

Commit 9ed4c09

Browse files
committed
parse: extract error_on_unmatched_vis.
1 parent 7017058 commit 9ed4c09

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/librustc_parse/parser/item.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,29 @@ impl<'a> Parser<'a> {
8888
return Ok(Some(P(self.mk_item(lo, ident, kind, vis, Defaultness::Final, attrs))));
8989
}
9090

91-
// FAILURE TO PARSE ITEM
92-
if let VisibilityKind::Inherited = vis.node {
93-
} else {
94-
let vs = pprust::vis_to_string(&vis);
95-
let vs = vs.trim_end();
96-
self.struct_span_err(vis.span, &format!("unmatched visibility `{}`", vs))
97-
.span_label(vis.span, "the unmatched visibility")
98-
.help(&format!("you likely meant to define an item, e.g., `{} fn foo() {{}}`", vs))
99-
.emit();
100-
}
91+
// At this point, we have failed to parse an item.
92+
93+
self.error_on_unmatched_vis(&vis);
10194

10295
if !attributes_allowed {
10396
self.recover_attrs_no_item(&attrs)?;
10497
}
10598
Ok(None)
10699
}
107100

101+
/// Error in-case a non-inherited visibility was parsed but no item followed.
102+
fn error_on_unmatched_vis(&self, vis: &Visibility) {
103+
if let VisibilityKind::Inherited = vis.node {
104+
return;
105+
}
106+
let vs = pprust::vis_to_string(&vis);
107+
let vs = vs.trim_end();
108+
self.struct_span_err(vis.span, &format!("unmatched visibility `{}`", vs))
109+
.span_label(vis.span, "the unmatched visibility")
110+
.help(&format!("you likely meant to define an item, e.g., `{} fn foo() {{}}`", vs))
111+
.emit();
112+
}
113+
108114
/// Parses one of the items allowed by the flags.
109115
fn parse_item_kind(
110116
&mut self,

0 commit comments

Comments
 (0)