@@ -223,7 +223,7 @@ impl<'a> Parser<'a> {
223223 ( Ident :: empty ( ) , ItemKind :: Use ( tree) )
224224 } else if self . check_fn_front_matter ( def_final) {
225225 // FUNCTION ITEM
226- let ( ident, sig, generics, body) = self . parse_fn ( attrs, fn_parse_mode, lo, Some ( vis) ) ?;
226+ let ( ident, sig, generics, body) = self . parse_fn ( attrs, fn_parse_mode, lo, vis) ?;
227227 ( ident, ItemKind :: Fn ( Box :: new ( Fn { defaultness : def ( ) , sig, generics, body } ) ) )
228228 } else if self . eat_keyword ( kw:: Extern ) {
229229 if self . eat_keyword ( kw:: Crate ) {
@@ -1511,9 +1511,16 @@ impl<'a> Parser<'a> {
15111511 let ( ident, is_raw) = self . ident_or_err ( ) ?;
15121512 if !is_raw && ident. is_reserved ( ) {
15131513 let err = if self . check_fn_front_matter ( false ) {
1514+ let inherited_vis = Visibility {
1515+ span : rustc_span:: DUMMY_SP ,
1516+ kind : VisibilityKind :: Inherited ,
1517+ tokens : None ,
1518+ } ;
15141519 // We use `parse_fn` to get a span for the function
15151520 let fn_parse_mode = FnParseMode { req_name : |_| true , req_body : true } ;
1516- if let Err ( mut db) = self . parse_fn ( & mut Vec :: new ( ) , fn_parse_mode, lo, None ) {
1521+ if let Err ( mut db) =
1522+ self . parse_fn ( & mut Vec :: new ( ) , fn_parse_mode, lo, & inherited_vis)
1523+ {
15171524 db. delay_as_bug ( ) ;
15181525 }
15191526 let mut err = self . struct_span_err (
@@ -1793,7 +1800,7 @@ impl<'a> Parser<'a> {
17931800 attrs : & mut Vec < Attribute > ,
17941801 fn_parse_mode : FnParseMode ,
17951802 sig_lo : Span ,
1796- vis : Option < & Visibility > ,
1803+ vis : & Visibility ,
17971804 ) -> PResult < ' a , ( Ident , FnSig , Generics , Option < P < Block > > ) > {
17981805 let header = self . parse_fn_front_matter ( vis) ?; // `const ... fn`
17991806 let ident = self . parse_ident ( ) ?; // `foo`
@@ -1909,10 +1916,10 @@ impl<'a> Parser<'a> {
19091916 /// FnQual = "const"? "async"? "unsafe"? Extern? ;
19101917 /// FnFrontMatter = FnQual "fn" ;
19111918 /// ```
1912- pub ( super ) fn parse_fn_front_matter (
1913- & mut self ,
1914- vis : Option < & Visibility > ,
1915- ) -> PResult < ' a , FnHeader > {
1919+ ///
1920+ /// `vis` represents the visibility that was already parsed, if any. Use
1921+ /// `Visibility::Inherited` when no visibility is known.
1922+ pub ( super ) fn parse_fn_front_matter ( & mut self , orig_vis : & Visibility ) -> PResult < ' a , FnHeader > {
19161923 let sp_start = self . token . span ;
19171924 let constness = self . parse_constness ( ) ;
19181925
@@ -1995,12 +2002,6 @@ impl<'a> Parser<'a> {
19952002 }
19962003 // Recover incorrect visibility order such as `async pub`
19972004 else if self . check_keyword ( kw:: Pub ) {
1998- let orig_vis = vis. unwrap_or ( & Visibility {
1999- span : rustc_span:: DUMMY_SP ,
2000- kind : VisibilityKind :: Inherited ,
2001- tokens : None ,
2002- } ) ;
2003-
20042005 let sp = sp_start. to ( self . prev_token . span ) ;
20052006 if let Ok ( snippet) = self . span_to_snippet ( sp) {
20062007 let current_vis = match self . parse_visibility ( FollowedByType :: No ) {
0 commit comments