@@ -533,6 +533,14 @@ struct FormatArgsValues<'tcx> {
533533}
534534
535535impl < ' tcx > FormatArgsValues < ' tcx > {
536+ fn new_empty ( format_string_span : SpanData ) -> Self {
537+ Self {
538+ value_args : Vec :: new ( ) ,
539+ pos_to_value_index : Vec :: new ( ) ,
540+ format_string_span,
541+ }
542+ }
543+
536544 fn new ( args : & ' tcx Expr < ' tcx > , format_string_span : SpanData ) -> Self {
537545 let mut pos_to_value_index = Vec :: new ( ) ;
538546 let mut value_args = Vec :: new ( ) ;
@@ -997,12 +1005,13 @@ impl<'tcx> FormatArgsExpn<'tcx> {
9971005 . find ( |& name| matches ! ( name, sym:: const_format_args | sym:: format_args | sym:: format_args_nl) ) ?;
9981006 let newline = macro_name == sym:: format_args_nl;
9991007
1008+ // ::core::fmt::Arguments::new_const(pieces)
10001009 // ::core::fmt::Arguments::new_v1(pieces, args)
10011010 // ::core::fmt::Arguments::new_v1_formatted(pieces, args, fmt, _unsafe_arg)
1002- if let ExprKind :: Call ( callee, [ pieces, args , rest @ ..] ) = expr. kind
1011+ if let ExprKind :: Call ( callee, [ pieces, rest @ ..] ) = expr. kind
10031012 && let ExprKind :: Path ( QPath :: TypeRelative ( ty, seg) ) = callee. kind
10041013 && let TyKind :: Path ( QPath :: LangItem ( LangItem :: FormatArguments , _, _) ) = ty. kind
1005- && matches ! ( seg. ident. as_str( ) , "new_v1" | "new_v1_formatted" )
1014+ && matches ! ( seg. ident. as_str( ) , "new_const" | " new_v1" | "new_v1_formatted" )
10061015 {
10071016 let format_string = FormatString :: new ( cx, pieces) ?;
10081017
@@ -1026,7 +1035,7 @@ impl<'tcx> FormatArgsExpn<'tcx> {
10261035 return None ;
10271036 }
10281037
1029- let positions = if let Some ( fmt_arg) = rest. first ( ) {
1038+ let positions = if let Some ( fmt_arg) = rest. get ( 1 ) {
10301039 // If the argument contains format specs, `new_v1_formatted(_, _, fmt, _)`, parse
10311040 // them.
10321041
@@ -1042,7 +1051,11 @@ impl<'tcx> FormatArgsExpn<'tcx> {
10421051 } ) )
10431052 } ;
10441053
1045- let values = FormatArgsValues :: new ( args, format_string. span . data ( ) ) ;
1054+ let values = if let Some ( args) = rest. first ( ) {
1055+ FormatArgsValues :: new ( args, format_string. span . data ( ) )
1056+ } else {
1057+ FormatArgsValues :: new_empty ( format_string. span . data ( ) )
1058+ } ;
10461059
10471060 let args = izip ! ( positions, parsed_args, parser. arg_places)
10481061 . map ( |( position, parsed_arg, arg_span) | {
0 commit comments