@@ -1014,6 +1014,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1014
1014
. peek ( )
1015
1015
. is_some_and ( |first| matches ! ( first, Error :: Extra ( arg_idx) if arg_idx. index( ) == 0 ) ) ;
1016
1016
let mut suggestions = vec ! [ ] ;
1017
+
1018
+ // Convert the given number into the corresponding ordinal
1019
+ // This is copied from rustc_resolve::diagnostics::ordinalize because it is too much to link rustc_resolve for this small function.
1020
+ fn ordinalize ( v : usize ) -> String {
1021
+ let suffix = match ( ( 11 ..=13 ) . contains ( & ( v % 100 ) ) , v % 10 ) {
1022
+ ( false , 1 ) => "st" ,
1023
+ ( false , 2 ) => "nd" ,
1024
+ ( false , 3 ) => "rd" ,
1025
+ _ => "th" ,
1026
+ } ;
1027
+ format ! ( "{v}{suffix}" )
1028
+ }
1029
+
1017
1030
while let Some ( error) = errors. next ( ) {
1018
1031
only_extras_so_far &= matches ! ( error, Error :: Extra ( _) ) ;
1019
1032
@@ -1055,7 +1068,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1055
1068
} else {
1056
1069
"" . to_string ( )
1057
1070
} ;
1058
- labels. push ( ( provided_span, format ! ( "unexpected argument{provided_ty_name}" ) ) ) ;
1071
+ labels. push ( ( provided_span, format ! ( "unexpected {} argument{provided_ty_name}" , ordinalize ( arg_idx . as_usize ( ) + 1 ) ) ) ) ;
1059
1072
let mut span = provided_span;
1060
1073
if span. can_be_used_for_suggestions ( )
1061
1074
&& error_span. can_be_used_for_suggestions ( )
@@ -1136,7 +1149,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1136
1149
} else {
1137
1150
"" . to_string ( )
1138
1151
} ;
1139
- labels. push ( ( span, format ! ( "an argument{rendered} is missing" ) ) ) ;
1152
+ labels. push ( ( span, format ! ( "{} argument{rendered} is missing" , ordinalize( expected_idx. as_usize( ) + 1 ) ) ) ) ;
1153
+
1140
1154
suggestion_text = match suggestion_text {
1141
1155
SuggestionText :: None => SuggestionText :: Provide ( false ) ,
1142
1156
SuggestionText :: Provide ( _) => SuggestionText :: Provide ( true ) ,
0 commit comments