@@ -532,6 +532,22 @@ enum InferSourceKind<'tcx> {
532
532
} ,
533
533
}
534
534
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
+
535
551
impl < ' tcx > InferSourceKind < ' tcx > {
536
552
fn ty_msg ( & self , infcx : & InferCtxt < ' _ , ' tcx > ) -> String {
537
553
match * self {
@@ -638,7 +654,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
638
654
// The sources are listed in order of preference here.
639
655
let tcx = self . infcx . tcx ;
640
656
let ctx = CostCtxt { tcx } ;
641
- match source. kind {
657
+ let base_cost = match source. kind {
642
658
InferSourceKind :: LetBinding { ty, .. } => ctx. ty_cost ( ty) ,
643
659
InferSourceKind :: ClosureArg { ty, .. } => ctx. ty_cost ( ty) ,
644
660
InferSourceKind :: GenericArg { def_id, generic_args, .. } => {
@@ -655,7 +671,12 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
655
671
InferSourceKind :: ClosureReturn { ty, should_wrap_expr, .. } => {
656
672
30 + ctx. ty_cost ( ty) + if should_wrap_expr. is_some ( ) { 10 } else { 0 }
657
673
}
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
659
680
}
660
681
661
682
/// Uses `fn source_cost` to determine whether this inference source is preferable to
0 commit comments