@@ -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,13 +675,21 @@ 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)
681
684
}
682
685
683
686
fn visit_expr ( & mut self , expr : & ' tcx hir:: Expr < ' tcx > ) -> Self :: Result {
687
+ if let hir:: ExprKind :: Closure ( & hir:: Closure { body, .. } )
688
+ | hir:: ExprKind :: ConstBlock ( hir:: ConstBlock { body, .. } ) = expr. kind
689
+ {
690
+ self . visit_body ( self . fcx . tcx . hir ( ) . body ( body) ) ?;
691
+ }
692
+
684
693
// Try to suggest adding an explicit qself `()` to a trait method path.
685
694
// i.e. changing `Default::default()` to `<() as Default>::default()`.
686
695
if let hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( None , path) ) = expr. kind
@@ -691,17 +700,21 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
691
700
&& let Some ( vid) = self . fcx . root_vid ( self_ty)
692
701
&& self . reachable_vids . contains ( & vid)
693
702
&& let [ .., trait_segment, _method_segment] = path. segments
703
+ && expr. span . can_be_used_for_suggestions ( )
694
704
{
695
705
let span = path. span . shrink_to_lo ( ) . to ( trait_segment. ident . span ) ;
696
706
return ControlFlow :: Break ( errors:: SuggestAnnotation :: Path ( span) ) ;
697
707
}
708
+
698
709
// Or else, try suggesting turbofishing the method args.
699
710
if let hir:: ExprKind :: MethodCall ( segment, ..) = expr. kind
700
711
&& let Some ( def_id) =
701
712
self . fcx . typeck_results . borrow ( ) . type_dependent_def_id ( expr. hir_id )
713
+ && expr. span . can_be_used_for_suggestions ( )
702
714
{
703
715
self . suggest_for_segment ( segment, def_id, expr. hir_id ) ?;
704
716
}
717
+
705
718
hir:: intravisit:: walk_expr ( self , expr)
706
719
}
707
720
@@ -712,6 +725,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
712
725
&& let Some ( ty) = self . fcx . typeck_results . borrow ( ) . node_type_opt ( local. hir_id )
713
726
&& let Some ( vid) = self . fcx . root_vid ( ty)
714
727
&& self . reachable_vids . contains ( & vid)
728
+ && local. span . can_be_used_for_suggestions ( )
715
729
{
716
730
return ControlFlow :: Break ( errors:: SuggestAnnotation :: Local (
717
731
local. pat . span . shrink_to_hi ( ) ,
0 commit comments