@@ -651,6 +651,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
651
651
if let Some ( ty) = self . fcx . typeck_results . borrow ( ) . node_type_opt ( inf_id)
652
652
&& let Some ( vid) = self . fcx . root_vid ( ty)
653
653
&& self . reachable_vids . contains ( & vid)
654
+ && inf_span. can_be_used_for_suggestions ( )
654
655
{
655
656
return ControlFlow :: Break ( errors:: SuggestAnnotation :: Unit ( inf_span) ) ;
656
657
}
@@ -662,7 +663,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
662
663
& mut self ,
663
664
qpath : & ' tcx rustc_hir:: QPath < ' tcx > ,
664
665
id : HirId ,
665
- _span : Span ,
666
+ span : Span ,
666
667
) -> Self :: Result {
667
668
let arg_segment = match qpath {
668
669
hir:: QPath :: Resolved ( _, path) => {
@@ -674,7 +675,9 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
674
675
}
675
676
} ;
676
677
// Alternatively, try to turbofish `::<_, (), _>`.
677
- if let Some ( def_id) = self . fcx . typeck_results . borrow ( ) . qpath_res ( qpath, id) . opt_def_id ( ) {
678
+ if let Some ( def_id) = self . fcx . typeck_results . borrow ( ) . qpath_res ( qpath, id) . opt_def_id ( )
679
+ && span. can_be_used_for_suggestions ( )
680
+ {
678
681
self . suggest_for_segment ( arg_segment, def_id, id) ?;
679
682
}
680
683
hir:: intravisit:: walk_qpath ( self , qpath, id)
@@ -691,17 +694,21 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
691
694
&& let Some ( vid) = self . fcx . root_vid ( self_ty)
692
695
&& self . reachable_vids . contains ( & vid)
693
696
&& let [ .., trait_segment, _method_segment] = path. segments
697
+ && expr. span . can_be_used_for_suggestions ( )
694
698
{
695
699
let span = path. span . shrink_to_lo ( ) . to ( trait_segment. ident . span ) ;
696
700
return ControlFlow :: Break ( errors:: SuggestAnnotation :: Path ( span) ) ;
697
701
}
702
+
698
703
// Or else, try suggesting turbofishing the method args.
699
704
if let hir:: ExprKind :: MethodCall ( segment, ..) = expr. kind
700
705
&& let Some ( def_id) =
701
706
self . fcx . typeck_results . borrow ( ) . type_dependent_def_id ( expr. hir_id )
707
+ && expr. span . can_be_used_for_suggestions ( )
702
708
{
703
709
self . suggest_for_segment ( segment, def_id, expr. hir_id ) ?;
704
710
}
711
+
705
712
hir:: intravisit:: walk_expr ( self , expr)
706
713
}
707
714
@@ -712,6 +719,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
712
719
&& let Some ( ty) = self . fcx . typeck_results . borrow ( ) . node_type_opt ( local. hir_id )
713
720
&& let Some ( vid) = self . fcx . root_vid ( ty)
714
721
&& self . reachable_vids . contains ( & vid)
722
+ && local. span . can_be_used_for_suggestions ( )
715
723
{
716
724
return ControlFlow :: Break ( errors:: SuggestAnnotation :: Local (
717
725
local. pat . span . shrink_to_hi ( ) ,
0 commit comments