@@ -435,6 +435,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
435435 generics_def_id,
436436 def_id : _,
437437 generic_args,
438+ have_turbofish,
438439 } => {
439440 let generics = self . tcx . generics_of ( generics_def_id) ;
440441 let is_type = matches ! ( arg. unpack( ) , GenericArgKind :: Type ( _) ) ;
@@ -482,11 +483,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
482483 . unwrap ( )
483484 . into_buffer ( ) ;
484485
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+ }
490493 }
491494 InferSourceKind :: FullyQualifiedMethodCall { receiver, successor, substs, def_id } => {
492495 let printer = fmt_printer ( self , Namespace :: ValueNS ) ;
@@ -616,6 +619,7 @@ enum InferSourceKind<'tcx> {
616619 generics_def_id : DefId ,
617620 def_id : DefId ,
618621 generic_args : & ' tcx [ GenericArg < ' tcx > ] ,
622+ have_turbofish : bool ,
619623 } ,
620624 FullyQualifiedMethodCall {
621625 receiver : & ' tcx Expr < ' tcx > ,
@@ -676,6 +680,7 @@ struct InsertableGenericArgs<'tcx> {
676680 substs : SubstsRef < ' tcx > ,
677681 generics_def_id : DefId ,
678682 def_id : DefId ,
683+ have_turbofish : bool ,
679684}
680685
681686/// A visitor which searches for the "best" spot to use in the inference error.
@@ -916,6 +921,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
916921 substs,
917922 generics_def_id : def_id,
918923 def_id,
924+ have_turbofish : false ,
919925 }
920926 } ;
921927 return Box :: new ( insertable. into_iter ( ) ) ;
@@ -933,6 +939,9 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
933939 substs : SubstsRef < ' tcx > ,
934940 ) -> impl Iterator < Item = InsertableGenericArgs < ' tcx > > + ' a {
935941 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+ } ) ;
936945 // The last segment of a path often has `Res::Err` and the
937946 // correct `Res` is the one of the whole path.
938947 //
@@ -942,7 +951,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
942951 let generics_def_id = tcx. res_generics_def_id ( path. res ) ?;
943952 let generics = tcx. generics_of ( generics_def_id) ;
944953 if generics. has_impl_trait ( ) {
945- None ?
954+ None ?;
946955 }
947956 let insert_span =
948957 path. segments . last ( ) . unwrap ( ) . ident . span . shrink_to_hi ( ) . with_hi ( path. span . hi ( ) ) ;
@@ -951,6 +960,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
951960 substs,
952961 generics_def_id,
953962 def_id : path. res . def_id ( ) ,
963+ have_turbofish,
954964 }
955965 } ;
956966
@@ -970,6 +980,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
970980 substs,
971981 generics_def_id,
972982 def_id : res. def_id ( ) ,
983+ have_turbofish,
973984 } )
974985 } )
975986 . chain ( last_segment_using_path_data)
@@ -998,7 +1009,13 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
9981009 }
9991010 let span = tcx. hir ( ) . span ( segment. hir_id ) ;
10001011 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+ }
10021019 } ;
10031020
10041021 let parent_def_id = generics. parent . unwrap ( ) ;
@@ -1121,7 +1138,13 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
11211138
11221139 for args in self . expr_inferred_subst_iter ( expr) {
11231140 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;
11251148 let generics = tcx. generics_of ( generics_def_id) ;
11261149 if let Some ( argument_index) = generics
11271150 . own_substs ( substs)
@@ -1144,6 +1167,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
11441167 generics_def_id,
11451168 def_id,
11461169 generic_args,
1170+ have_turbofish,
11471171 } ,
11481172 } ) ;
11491173 }
0 commit comments