@@ -117,7 +117,7 @@ impl<'a> Parser<'a> {
117117
118118impl < ' a > Parser < ' a > {
119119 pub fn parse_item ( & mut self , force_collect : ForceCollect ) -> PResult < ' a , Option < P < Item > > > {
120- let fn_parse_mode = FnParseMode { req_name : |_| true , req_body : true } ;
120+ let fn_parse_mode = FnParseMode { req_name : |_, _ | true , req_body : true } ;
121121 self . parse_item_ ( fn_parse_mode, force_collect) . map ( |i| i. map ( P ) )
122122 }
123123
@@ -935,7 +935,7 @@ impl<'a> Parser<'a> {
935935 & mut self ,
936936 force_collect : ForceCollect ,
937937 ) -> PResult < ' a , Option < Option < P < AssocItem > > > > {
938- let fn_parse_mode = FnParseMode { req_name : |_| true , req_body : true } ;
938+ let fn_parse_mode = FnParseMode { req_name : |_, _ | true , req_body : true } ;
939939 self . parse_assoc_item ( fn_parse_mode, force_collect)
940940 }
941941
@@ -944,7 +944,7 @@ impl<'a> Parser<'a> {
944944 force_collect : ForceCollect ,
945945 ) -> PResult < ' a , Option < Option < P < AssocItem > > > > {
946946 let fn_parse_mode =
947- FnParseMode { req_name : |edition| edition >= Edition :: Edition2018 , req_body : false } ;
947+ FnParseMode { req_name : |edition, _ | edition >= Edition :: Edition2018 , req_body : false } ;
948948 self . parse_assoc_item ( fn_parse_mode, force_collect)
949949 }
950950
@@ -1221,7 +1221,10 @@ impl<'a> Parser<'a> {
12211221 & mut self ,
12221222 force_collect : ForceCollect ,
12231223 ) -> PResult < ' a , Option < Option < P < ForeignItem > > > > {
1224- let fn_parse_mode = FnParseMode { req_name : |_| true , req_body : false } ;
1224+ let fn_parse_mode = FnParseMode {
1225+ req_name : |_, is_dot_dot_dot| is_dot_dot_dot == IsDotDotDot :: No ,
1226+ req_body : false ,
1227+ } ;
12251228 Ok ( self . parse_item_ ( fn_parse_mode, force_collect) ?. map (
12261229 |Item { attrs, id, span, vis, kind, tokens } | {
12271230 let kind = match ForeignItemKind :: try_from ( kind) {
@@ -2093,7 +2096,7 @@ impl<'a> Parser<'a> {
20932096 let inherited_vis =
20942097 Visibility { span : DUMMY_SP , kind : VisibilityKind :: Inherited , tokens : None } ;
20952098 // We use `parse_fn` to get a span for the function
2096- let fn_parse_mode = FnParseMode { req_name : |_| true , req_body : true } ;
2099+ let fn_parse_mode = FnParseMode { req_name : |_, _ | true , req_body : true } ;
20972100 match self . parse_fn (
20982101 & mut AttrVec :: new ( ) ,
20992102 fn_parse_mode,
@@ -2326,8 +2329,16 @@ impl<'a> Parser<'a> {
23262329/// The function decides if, per-parameter `p`, `p` must have a pattern or just a type.
23272330///
23282331/// This function pointer accepts an edition, because in edition 2015, trait declarations
2329- /// were allowed to omit parameter names. In 2018, they became required.
2330- type ReqName = fn ( Edition ) -> bool ;
2332+ /// were allowed to omit parameter names. In 2018, they became required. It also accepts an
2333+ /// `IsDotDotDot` parameter, as `extern` function declarations and function pointer types are
2334+ /// allowed to omit the name of the `...` but regular function items are not.
2335+ type ReqName = fn ( Edition , IsDotDotDot ) -> bool ;
2336+
2337+ #[ derive( PartialEq ) ]
2338+ pub ( crate ) enum IsDotDotDot {
2339+ Yes ,
2340+ No ,
2341+ }
23312342
23322343/// Parsing configuration for functions.
23332344///
@@ -2360,6 +2371,8 @@ pub(crate) struct FnParseMode {
23602371 /// to true.
23612372 /// * The span is from Edition 2015. In particular, you can get a
23622373 /// 2015 span inside a 2021 crate using macros.
2374+ ///
2375+ /// Or if `IsDotDotDot::Yes`, this function will also return `false` with an `extern` block.
23632376 pub ( super ) req_name : ReqName ,
23642377 /// If this flag is set to `true`, then plain, semicolon-terminated function
23652378 /// prototypes are not allowed here.
@@ -2991,10 +3004,15 @@ impl<'a> Parser<'a> {
29913004 return Ok ( ( res?, Trailing :: No , UsePreAttrPos :: No ) ) ;
29923005 }
29933006
2994- let is_name_required = match this. token . kind {
2995- token:: DotDotDot => false ,
2996- _ => req_name ( this. token . span . with_neighbor ( this. prev_token . span ) . edition ( ) ) ,
3007+ let is_dot_dot_dot = if this. token . kind == token:: DotDotDot {
3008+ IsDotDotDot :: Yes
3009+ } else {
3010+ IsDotDotDot :: No
29973011 } ;
3012+ let is_name_required = req_name (
3013+ this. token . span . with_neighbor ( this. prev_token . span ) . edition ( ) ,
3014+ is_dot_dot_dot,
3015+ ) ;
29983016 let ( pat, ty) = if is_name_required || this. is_named_param ( ) {
29993017 debug ! ( "parse_param_general parse_pat (is_name_required:{})" , is_name_required) ;
30003018 let ( pat, colon) = this. parse_fn_param_pat_colon ( ) ?;
0 commit comments