@@ -1041,12 +1041,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1041
1041
vec ! [ ( left, "(" . to_string( ) ) , ( right. shrink_to_hi( ) , ")" . to_string( ) ) ] ,
1042
1042
Applicability :: MachineApplicable ,
1043
1043
) ;
1044
- } else if fields. len ( ) > subpats. len ( ) {
1045
- let after_fields_span = if pat_span == DUMMY_SP {
1046
- pat_span
1047
- } else {
1048
- pat_span. with_hi ( pat_span. hi ( ) - BytePos ( 1 ) ) . shrink_to_hi ( )
1049
- } ;
1044
+ } else if fields. len ( ) > subpats. len ( ) && pat_span != DUMMY_SP {
1045
+ let after_fields_span = pat_span. with_hi ( pat_span. hi ( ) - BytePos ( 1 ) ) . shrink_to_hi ( ) ;
1050
1046
let all_fields_span = match subpats {
1051
1047
[ ] => after_fields_span,
1052
1048
[ field] => field. span ,
@@ -1055,7 +1051,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1055
1051
1056
1052
// Check if all the fields in the pattern are wildcards.
1057
1053
let all_wildcards = subpats. iter ( ) . all ( |pat| matches ! ( pat. kind, PatKind :: Wild ) ) ;
1054
+ let first_tail_wildcard =
1055
+ subpats. iter ( ) . enumerate ( ) . fold ( None , |acc, ( pos, pat) | match ( acc, & pat. kind ) {
1056
+ ( None , PatKind :: Wild ) => Some ( pos) ,
1057
+ ( Some ( _) , PatKind :: Wild ) => acc,
1058
+ _ => None ,
1059
+ } ) ;
1060
+ let tail_span = match first_tail_wildcard {
1061
+ None => after_fields_span,
1062
+ Some ( 0 ) => subpats[ 0 ] . span . to ( after_fields_span) ,
1063
+ Some ( pos) => subpats[ pos - 1 ] . span . shrink_to_hi ( ) . to ( after_fields_span) ,
1064
+ } ;
1058
1065
1066
+ // FIXME: heuristic-based suggestion to check current types for where to add `_`.
1059
1067
let mut wildcard_sugg = vec ! [ "_" ; fields. len( ) - subpats. len( ) ] . join ( ", " ) ;
1060
1068
if !subpats. is_empty ( ) {
1061
1069
wildcard_sugg = String :: from ( ", " ) + & wildcard_sugg;
@@ -1080,7 +1088,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1080
1088
) ;
1081
1089
} else {
1082
1090
err. span_suggestion_verbose (
1083
- after_fields_span ,
1091
+ tail_span ,
1084
1092
"use `..` to ignore the rest of the fields" ,
1085
1093
String :: from ( ", .." ) ,
1086
1094
Applicability :: MaybeIncorrect ,
0 commit comments