@@ -435,6 +435,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
435
435
generics_def_id,
436
436
def_id : _,
437
437
generic_args,
438
+ have_turbofish,
438
439
} => {
439
440
let generics = self . tcx . generics_of ( generics_def_id) ;
440
441
let is_type = matches ! ( arg. unpack( ) , GenericArgKind :: Type ( _) ) ;
@@ -482,11 +483,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
482
483
. unwrap ( )
483
484
. into_buffer ( ) ;
484
485
485
- infer_subdiags. push ( SourceKindSubdiag :: GenericSuggestion {
486
- span : insert_span,
487
- arg_count : generic_args. len ( ) ,
488
- args,
489
- } ) ;
486
+ if !have_turbofish {
487
+ infer_subdiags. push ( SourceKindSubdiag :: GenericSuggestion {
488
+ span : insert_span,
489
+ arg_count : generic_args. len ( ) ,
490
+ args,
491
+ } ) ;
492
+ }
490
493
}
491
494
InferSourceKind :: FullyQualifiedMethodCall { receiver, successor, substs, def_id } => {
492
495
let printer = fmt_printer ( self , Namespace :: ValueNS ) ;
@@ -616,6 +619,7 @@ enum InferSourceKind<'tcx> {
616
619
generics_def_id : DefId ,
617
620
def_id : DefId ,
618
621
generic_args : & ' tcx [ GenericArg < ' tcx > ] ,
622
+ have_turbofish : bool ,
619
623
} ,
620
624
FullyQualifiedMethodCall {
621
625
receiver : & ' tcx Expr < ' tcx > ,
@@ -676,6 +680,7 @@ struct InsertableGenericArgs<'tcx> {
676
680
substs : SubstsRef < ' tcx > ,
677
681
generics_def_id : DefId ,
678
682
def_id : DefId ,
683
+ have_turbofish : bool ,
679
684
}
680
685
681
686
/// A visitor which searches for the "best" spot to use in the inference error.
@@ -916,6 +921,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
916
921
substs,
917
922
generics_def_id : def_id,
918
923
def_id,
924
+ have_turbofish : false ,
919
925
}
920
926
} ;
921
927
return Box :: new ( insertable. into_iter ( ) ) ;
@@ -933,6 +939,9 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
933
939
substs : SubstsRef < ' tcx > ,
934
940
) -> impl Iterator < Item = InsertableGenericArgs < ' tcx > > + ' a {
935
941
let tcx = self . infcx . tcx ;
942
+ let have_turbofish = path. segments . iter ( ) . any ( |segment| {
943
+ segment. args . map_or ( false , |args| args. args . iter ( ) . any ( |arg| arg. is_ty_or_const ( ) ) )
944
+ } ) ;
936
945
// The last segment of a path often has `Res::Err` and the
937
946
// correct `Res` is the one of the whole path.
938
947
//
@@ -942,7 +951,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
942
951
let generics_def_id = tcx. res_generics_def_id ( path. res ) ?;
943
952
let generics = tcx. generics_of ( generics_def_id) ;
944
953
if generics. has_impl_trait ( ) {
945
- None ?
954
+ None ?;
946
955
}
947
956
let insert_span =
948
957
path. segments . last ( ) . unwrap ( ) . ident . span . shrink_to_hi ( ) . with_hi ( path. span . hi ( ) ) ;
@@ -951,6 +960,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
951
960
substs,
952
961
generics_def_id,
953
962
def_id : path. res . def_id ( ) ,
963
+ have_turbofish,
954
964
}
955
965
} ;
956
966
@@ -970,6 +980,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
970
980
substs,
971
981
generics_def_id,
972
982
def_id : res. def_id ( ) ,
983
+ have_turbofish,
973
984
} )
974
985
} )
975
986
. chain ( last_segment_using_path_data)
@@ -998,7 +1009,13 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
998
1009
}
999
1010
let span = tcx. hir ( ) . span ( segment. hir_id ) ;
1000
1011
let insert_span = segment. ident . span . shrink_to_hi ( ) . with_hi ( span. hi ( ) ) ;
1001
- InsertableGenericArgs { insert_span, substs, generics_def_id : def_id, def_id }
1012
+ InsertableGenericArgs {
1013
+ insert_span,
1014
+ substs,
1015
+ generics_def_id : def_id,
1016
+ def_id,
1017
+ have_turbofish : false ,
1018
+ }
1002
1019
} ;
1003
1020
1004
1021
let parent_def_id = generics. parent . unwrap ( ) ;
@@ -1121,7 +1138,13 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
1121
1138
1122
1139
for args in self . expr_inferred_subst_iter ( expr) {
1123
1140
debug ! ( ?args) ;
1124
- let InsertableGenericArgs { insert_span, substs, generics_def_id, def_id } = args;
1141
+ let InsertableGenericArgs {
1142
+ insert_span,
1143
+ substs,
1144
+ generics_def_id,
1145
+ def_id,
1146
+ have_turbofish,
1147
+ } = args;
1125
1148
let generics = tcx. generics_of ( generics_def_id) ;
1126
1149
if let Some ( argument_index) = generics
1127
1150
. own_substs ( substs)
@@ -1144,6 +1167,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
1144
1167
generics_def_id,
1145
1168
def_id,
1146
1169
generic_args,
1170
+ have_turbofish,
1147
1171
} ,
1148
1172
} ) ;
1149
1173
}
0 commit comments