diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-02-22 03:44:24 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-02-24 00:59:38 +0100 |
| commit | 9ed4c0998381901ac68c19c30c375f5760016759 (patch) | |
| tree | b1bc6cc997c185828e32017d432a24d6958aebfe /src/librustc_parse | |
| parent | 7017058e6b289ea6253e62b9ffdae5dea036855f (diff) | |
| download | rust-9ed4c0998381901ac68c19c30c375f5760016759.tar.gz rust-9ed4c0998381901ac68c19c30c375f5760016759.zip | |
parse: extract `error_on_unmatched_vis`.
Diffstat (limited to 'src/librustc_parse')
| -rw-r--r-- | src/librustc_parse/parser/item.rs | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index 190baa9b2d9..732bbdf1c54 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -88,16 +88,9 @@ impl<'a> Parser<'a> { return Ok(Some(P(self.mk_item(lo, ident, kind, vis, Defaultness::Final, attrs)))); } - // FAILURE TO PARSE ITEM - if let VisibilityKind::Inherited = vis.node { - } else { - let vs = pprust::vis_to_string(&vis); - let vs = vs.trim_end(); - self.struct_span_err(vis.span, &format!("unmatched visibility `{}`", vs)) - .span_label(vis.span, "the unmatched visibility") - .help(&format!("you likely meant to define an item, e.g., `{} fn foo() {{}}`", vs)) - .emit(); - } + // At this point, we have failed to parse an item. + + self.error_on_unmatched_vis(&vis); if !attributes_allowed { self.recover_attrs_no_item(&attrs)?; @@ -105,6 +98,19 @@ impl<'a> Parser<'a> { Ok(None) } + /// Error in-case a non-inherited visibility was parsed but no item followed. + fn error_on_unmatched_vis(&self, vis: &Visibility) { + if let VisibilityKind::Inherited = vis.node { + return; + } + let vs = pprust::vis_to_string(&vis); + let vs = vs.trim_end(); + self.struct_span_err(vis.span, &format!("unmatched visibility `{}`", vs)) + .span_label(vis.span, "the unmatched visibility") + .help(&format!("you likely meant to define an item, e.g., `{} fn foo() {{}}`", vs)) + .emit(); + } + /// Parses one of the items allowed by the flags. fn parse_item_kind( &mut self, |
