@@ -88,23 +88,29 @@ impl<'a> Parser<'a> {
88
88
return Ok ( Some ( P ( self . mk_item ( lo, ident, kind, vis, Defaultness :: Final , attrs) ) ) ) ;
89
89
}
90
90
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) ;
101
94
102
95
if !attributes_allowed {
103
96
self . recover_attrs_no_item ( & attrs) ?;
104
97
}
105
98
Ok ( None )
106
99
}
107
100
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
+
108
114
/// Parses one of the items allowed by the flags.
109
115
fn parse_item_kind (
110
116
& mut self ,
0 commit comments