@@ -533,18 +533,19 @@ enum InferSourceKind<'tcx> {
533
533
}
534
534
535
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
- }
536
+ fn from_expansion ( & self ) -> bool {
537
+ let source_from_expansion = match self . kind {
538
+ InferSourceKind :: LetBinding { insert_span, .. }
539
+ | InferSourceKind :: ClosureArg { insert_span, .. }
540
+ | InferSourceKind :: GenericArg { insert_span, .. } => insert_span. from_expansion ( ) ,
541
+ InferSourceKind :: FullyQualifiedMethodCall { receiver, .. } => {
542
+ receiver. span . from_expansion ( )
543
+ }
544
+ InferSourceKind :: ClosureReturn { data, should_wrap_expr, .. } => {
545
+ data. span ( ) . from_expansion ( ) || should_wrap_expr. map_or ( false , Span :: from_expansion)
546
+ }
547
+ } ;
548
+ source_from_expansion || self . span . from_expansion ( )
548
549
}
549
550
}
550
551
@@ -631,7 +632,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
631
632
}
632
633
}
633
634
fn ty_cost ( self , ty : Ty < ' tcx > ) -> usize {
634
- match ty. kind ( ) {
635
+ match * ty. kind ( ) {
635
636
ty:: Closure ( ..) => 1000 ,
636
637
ty:: FnDef ( ..) => 150 ,
637
638
ty:: FnPtr ( ..) => 30 ,
@@ -645,6 +646,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
645
646
. sum :: < usize > ( )
646
647
}
647
648
ty:: Tuple ( args) => 5 + args. iter ( ) . map ( |arg| self . ty_cost ( arg) ) . sum :: < usize > ( ) ,
649
+ ty:: Ref ( _, ty, _) => 2 + self . ty_cost ( ty) ,
648
650
ty:: Infer ( ..) => 0 ,
649
651
_ => 1 ,
650
652
}
@@ -673,8 +675,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
673
675
}
674
676
} ;
675
677
676
- let suggestion_may_apply =
677
- if source. main_insert_span ( ) . can_be_used_for_suggestions ( ) { 0 } else { 10000 } ;
678
+ let suggestion_may_apply = if source. from_expansion ( ) { 10000 } else { 0 } ;
678
679
679
680
base_cost + suggestion_may_apply
680
681
}
@@ -1022,8 +1023,10 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
1022
1023
debug ! ( ?args) ;
1023
1024
let InsertableGenericArgs { insert_span, substs, generics_def_id, def_id } = args;
1024
1025
let generics = tcx. generics_of ( generics_def_id) ;
1025
- if let Some ( argument_index) =
1026
- generics. own_substs ( substs) . iter ( ) . position ( |& arg| self . generic_arg_is_target ( arg) )
1026
+ if let Some ( argument_index) = generics
1027
+ . own_substs ( substs)
1028
+ . iter ( )
1029
+ . position ( |& arg| self . generic_arg_contains_target ( arg) )
1027
1030
{
1028
1031
let substs = self . infcx . resolve_vars_if_possible ( substs) ;
1029
1032
let generic_args = & generics. own_substs_no_defaults ( tcx, substs)
0 commit comments