@@ -223,7 +223,7 @@ impl<'a> Parser<'a> {
223
223
( Ident :: empty ( ) , ItemKind :: Use ( tree) )
224
224
} else if self . check_fn_front_matter ( def_final) {
225
225
// 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) ?;
227
227
( ident, ItemKind :: Fn ( Box :: new ( Fn { defaultness : def ( ) , sig, generics, body } ) ) )
228
228
} else if self . eat_keyword ( kw:: Extern ) {
229
229
if self . eat_keyword ( kw:: Crate ) {
@@ -1511,9 +1511,16 @@ impl<'a> Parser<'a> {
1511
1511
let ( ident, is_raw) = self . ident_or_err ( ) ?;
1512
1512
if !is_raw && ident. is_reserved ( ) {
1513
1513
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
+ } ;
1514
1519
// We use `parse_fn` to get a span for the function
1515
1520
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
+ {
1517
1524
db. delay_as_bug ( ) ;
1518
1525
}
1519
1526
let mut err = self . struct_span_err (
@@ -1793,7 +1800,7 @@ impl<'a> Parser<'a> {
1793
1800
attrs : & mut Vec < Attribute > ,
1794
1801
fn_parse_mode : FnParseMode ,
1795
1802
sig_lo : Span ,
1796
- vis : Option < & Visibility > ,
1803
+ vis : & Visibility ,
1797
1804
) -> PResult < ' a , ( Ident , FnSig , Generics , Option < P < Block > > ) > {
1798
1805
let header = self . parse_fn_front_matter ( vis) ?; // `const ... fn`
1799
1806
let ident = self . parse_ident ( ) ?; // `foo`
@@ -1909,10 +1916,10 @@ impl<'a> Parser<'a> {
1909
1916
/// FnQual = "const"? "async"? "unsafe"? Extern? ;
1910
1917
/// FnFrontMatter = FnQual "fn" ;
1911
1918
/// ```
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 > {
1916
1923
let sp_start = self . token . span ;
1917
1924
let constness = self . parse_constness ( ) ;
1918
1925
@@ -1995,12 +2002,6 @@ impl<'a> Parser<'a> {
1995
2002
}
1996
2003
// Recover incorrect visibility order such as `async pub`
1997
2004
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
-
2004
2005
let sp = sp_start. to ( self . prev_token . span ) ;
2005
2006
if let Ok ( snippet) = self . span_to_snippet ( sp) {
2006
2007
let current_vis = match self . parse_visibility ( FollowedByType :: No ) {
0 commit comments