@@ -533,18 +533,19 @@ enum InferSourceKind<'tcx> {
533533}
534534
535535impl < ' 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 ( )
548549 }
549550}
550551
@@ -631,7 +632,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
631632 }
632633 }
633634 fn ty_cost ( self , ty : Ty < ' tcx > ) -> usize {
634- match ty. kind ( ) {
635+ match * ty. kind ( ) {
635636 ty:: Closure ( ..) => 1000 ,
636637 ty:: FnDef ( ..) => 150 ,
637638 ty:: FnPtr ( ..) => 30 ,
@@ -645,6 +646,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
645646 . sum :: < usize > ( )
646647 }
647648 ty:: Tuple ( args) => 5 + args. iter ( ) . map ( |arg| self . ty_cost ( arg) ) . sum :: < usize > ( ) ,
649+ ty:: Ref ( _, ty, _) => 2 + self . ty_cost ( ty) ,
648650 ty:: Infer ( ..) => 0 ,
649651 _ => 1 ,
650652 }
@@ -673,8 +675,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
673675 }
674676 } ;
675677
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 } ;
678679
679680 base_cost + suggestion_may_apply
680681 }
@@ -1022,8 +1023,10 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
10221023 debug ! ( ?args) ;
10231024 let InsertableGenericArgs { insert_span, substs, generics_def_id, def_id } = args;
10241025 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) )
10271030 {
10281031 let substs = self . infcx . resolve_vars_if_possible ( substs) ;
10291032 let generic_args = & generics. own_substs_no_defaults ( tcx, substs)
0 commit comments