@@ -533,6 +533,14 @@ struct FormatArgsValues<'tcx> {
533
533
}
534
534
535
535
impl < ' 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
+
536
544
fn new ( args : & ' tcx Expr < ' tcx > , format_string_span : SpanData ) -> Self {
537
545
let mut pos_to_value_index = Vec :: new ( ) ;
538
546
let mut value_args = Vec :: new ( ) ;
@@ -997,12 +1005,13 @@ impl<'tcx> FormatArgsExpn<'tcx> {
997
1005
. find ( |& name| matches ! ( name, sym:: const_format_args | sym:: format_args | sym:: format_args_nl) ) ?;
998
1006
let newline = macro_name == sym:: format_args_nl;
999
1007
1008
+ // ::core::fmt::Arguments::new_const(pieces)
1000
1009
// ::core::fmt::Arguments::new_v1(pieces, args)
1001
1010
// ::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
1003
1012
&& let ExprKind :: Path ( QPath :: TypeRelative ( ty, seg) ) = callee. kind
1004
1013
&& 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" )
1006
1015
{
1007
1016
let format_string = FormatString :: new ( cx, pieces) ?;
1008
1017
@@ -1026,7 +1035,7 @@ impl<'tcx> FormatArgsExpn<'tcx> {
1026
1035
return None ;
1027
1036
}
1028
1037
1029
- let positions = if let Some ( fmt_arg) = rest. first ( ) {
1038
+ let positions = if let Some ( fmt_arg) = rest. get ( 1 ) {
1030
1039
// If the argument contains format specs, `new_v1_formatted(_, _, fmt, _)`, parse
1031
1040
// them.
1032
1041
@@ -1042,7 +1051,11 @@ impl<'tcx> FormatArgsExpn<'tcx> {
1042
1051
} ) )
1043
1052
} ;
1044
1053
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
+ } ;
1046
1059
1047
1060
let args = izip ! ( positions, parsed_args, parser. arg_places)
1048
1061
. map ( |( position, parsed_arg, arg_span) | {
0 commit comments