@@ -532,6 +532,22 @@ enum InferSourceKind<'tcx> {
532532    } , 
533533} 
534534
535+ impl < ' tcx >  InferSource < ' tcx >  { 
536+     /// Returns the span where we're going to insert our suggestion. 
537+      /// 
538+      /// Used when computing the cost of this infer source to check whether 
539+      /// we're inside of a macro expansion. 
540+      fn  main_insert_span ( & self )  -> Span  { 
541+         match  self . kind  { 
542+             InferSourceKind :: LetBinding  {  insert_span,  .. }  => insert_span, 
543+             InferSourceKind :: ClosureArg  {  insert_span,  .. }  => insert_span, 
544+             InferSourceKind :: GenericArg  {  insert_span,  .. }  => insert_span, 
545+             InferSourceKind :: FullyQualifiedMethodCall  {  receiver,  .. }  => receiver. span , 
546+             InferSourceKind :: ClosureReturn  {  data,  .. }  => data. span ( ) , 
547+         } 
548+     } 
549+ } 
550+ 
535551impl < ' tcx >  InferSourceKind < ' tcx >  { 
536552    fn  ty_msg ( & self ,  infcx :  & InferCtxt < ' _ ,  ' tcx > )  -> String  { 
537553        match  * self  { 
@@ -638,7 +654,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
638654        // The sources are listed in order of preference here. 
639655        let  tcx = self . infcx . tcx ; 
640656        let  ctx = CostCtxt  {  tcx } ; 
641-         match  source. kind  { 
657+         let  base_cost =  match  source. kind  { 
642658            InferSourceKind :: LetBinding  {  ty,  .. }  => ctx. ty_cost ( ty) , 
643659            InferSourceKind :: ClosureArg  {  ty,  .. }  => ctx. ty_cost ( ty) , 
644660            InferSourceKind :: GenericArg  {  def_id,  generic_args,  .. }  => { 
@@ -655,7 +671,12 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
655671            InferSourceKind :: ClosureReturn  {  ty,  should_wrap_expr,  .. }  => { 
656672                30  + ctx. ty_cost ( ty)  + if  should_wrap_expr. is_some ( )  {  10  }  else  {  0  } 
657673            } 
658-         } 
674+         } ; 
675+ 
676+         let  suggestion_may_apply =
677+             if  source. main_insert_span ( ) . can_be_used_for_suggestions ( )  {  0  }  else  {  10000  } ; 
678+ 
679+         base_cost + suggestion_may_apply
659680    } 
660681
661682    /// Uses `fn source_cost` to determine whether this inference source is preferable to 
0 commit comments