@@ -651,6 +651,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
651651 if let Some ( ty) = self . fcx . typeck_results . borrow ( ) . node_type_opt ( inf_id)
652652 && let Some ( vid) = self . fcx . root_vid ( ty)
653653 && self . reachable_vids . contains ( & vid)
654+ && inf_span. can_be_used_for_suggestions ( )
654655 {
655656 return ControlFlow :: Break ( errors:: SuggestAnnotation :: Unit ( inf_span) ) ;
656657 }
@@ -662,7 +663,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
662663 & mut self ,
663664 qpath : & ' tcx rustc_hir:: QPath < ' tcx > ,
664665 id : HirId ,
665- _span : Span ,
666+ span : Span ,
666667 ) -> Self :: Result {
667668 let arg_segment = match qpath {
668669 hir:: QPath :: Resolved ( _, path) => {
@@ -674,13 +675,21 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
674675 }
675676 } ;
676677 // 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+ {
678681 self . suggest_for_segment ( arg_segment, def_id, id) ?;
679682 }
680683 hir:: intravisit:: walk_qpath ( self , qpath, id)
681684 }
682685
683686 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+
684693 // Try to suggest adding an explicit qself `()` to a trait method path.
685694 // i.e. changing `Default::default()` to `<() as Default>::default()`.
686695 if let hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( None , path) ) = expr. kind
@@ -691,17 +700,21 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
691700 && let Some ( vid) = self . fcx . root_vid ( self_ty)
692701 && self . reachable_vids . contains ( & vid)
693702 && let [ .., trait_segment, _method_segment] = path. segments
703+ && expr. span . can_be_used_for_suggestions ( )
694704 {
695705 let span = path. span . shrink_to_lo ( ) . to ( trait_segment. ident . span ) ;
696706 return ControlFlow :: Break ( errors:: SuggestAnnotation :: Path ( span) ) ;
697707 }
708+
698709 // Or else, try suggesting turbofishing the method args.
699710 if let hir:: ExprKind :: MethodCall ( segment, ..) = expr. kind
700711 && let Some ( def_id) =
701712 self . fcx . typeck_results . borrow ( ) . type_dependent_def_id ( expr. hir_id )
713+ && expr. span . can_be_used_for_suggestions ( )
702714 {
703715 self . suggest_for_segment ( segment, def_id, expr. hir_id ) ?;
704716 }
717+
705718 hir:: intravisit:: walk_expr ( self , expr)
706719 }
707720
@@ -712,6 +725,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
712725 && let Some ( ty) = self . fcx . typeck_results . borrow ( ) . node_type_opt ( local. hir_id )
713726 && let Some ( vid) = self . fcx . root_vid ( ty)
714727 && self . reachable_vids . contains ( & vid)
728+ && local. span . can_be_used_for_suggestions ( )
715729 {
716730 return ControlFlow :: Break ( errors:: SuggestAnnotation :: Local (
717731 local. pat . span . shrink_to_hi ( ) ,
0 commit comments