11use crate :: FnCtxt ;
22use rustc_hir as hir;
3- use rustc_hir:: def:: Res ;
3+ use rustc_hir:: def:: { DefKind , Res } ;
44use rustc_hir:: def_id:: DefId ;
55use rustc_infer:: { infer:: type_variable:: TypeVariableOriginKind , traits:: ObligationCauseCode } ;
66use rustc_middle:: ty:: { self , Ty , TyCtxt , TypeSuperVisitable , TypeVisitable , TypeVisitor } ;
@@ -133,15 +133,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
133133 }
134134 }
135135 }
136- // Notably, we only point to params that are local to the
137- // item we're checking, since those are the ones we are able
138- // to look in the final `hir::PathSegment` for. Everything else
139- // would require a deeper search into the `qpath` than I think
140- // is worthwhile.
141- if let Some ( param_to_point_at) = param_to_point_at
142- && self . point_at_path_if_possible ( error, def_id, param_to_point_at, qpath)
136+
137+ for param in [ param_to_point_at, fallback_param_to_point_at, self_param_to_point_at]
138+ . into_iter ( )
139+ . flatten ( )
143140 {
144- return true ;
141+ if self . point_at_path_if_possible ( error, def_id, param, qpath) {
142+ return true ;
143+ }
145144 }
146145 }
147146 hir:: ExprKind :: MethodCall ( segment, receiver, args, ..) => {
@@ -168,10 +167,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
168167 }
169168 }
170169 hir:: ExprKind :: Struct ( qpath, fields, ..) => {
171- if let Res :: Def (
172- hir:: def:: DefKind :: Struct | hir:: def:: DefKind :: Variant ,
173- variant_def_id,
174- ) = self . typeck_results . borrow ( ) . qpath_res ( qpath, hir_id)
170+ if let Res :: Def ( DefKind :: Struct | DefKind :: Variant , variant_def_id) =
171+ self . typeck_results . borrow ( ) . qpath_res ( qpath, hir_id)
175172 {
176173 for param in
177174 [ param_to_point_at, fallback_param_to_point_at, self_param_to_point_at]
@@ -193,10 +190,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
193190 }
194191 }
195192 }
196- if let Some ( param_to_point_at) = param_to_point_at
197- && self . point_at_path_if_possible ( error, def_id, param_to_point_at, qpath)
193+
194+ for param in [ param_to_point_at, fallback_param_to_point_at, self_param_to_point_at]
195+ . into_iter ( )
196+ . flatten ( )
198197 {
199- return true ;
198+ if self . point_at_path_if_possible ( error, def_id, param, qpath) {
199+ return true ;
200+ }
200201 }
201202 }
202203 _ => { }
@@ -214,10 +215,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
214215 ) -> bool {
215216 match qpath {
216217 hir:: QPath :: Resolved ( _, path) => {
217- if let Some ( segment) = path. segments . last ( )
218- && self . point_at_generic_if_possible ( error, def_id, param, segment)
219- {
220- return true ;
218+ for segment in path. segments . iter ( ) . rev ( ) {
219+ if let Res :: Def ( kind, def_id) = segment. res
220+ && !matches ! ( kind, DefKind :: Mod | DefKind :: ForeignMod )
221+ && self . point_at_generic_if_possible ( error, def_id, param, segment)
222+ {
223+ return true ;
224+ }
221225 }
222226 }
223227 hir:: QPath :: TypeRelative ( _, segment) => {
@@ -618,14 +622,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
618622 } ;
619623
620624 let variant_def_id = match expr_struct_def_kind {
621- hir :: def :: DefKind :: Struct => {
625+ DefKind :: Struct => {
622626 if in_ty_adt. did ( ) != expr_struct_def_id {
623627 // FIXME: Deal with type aliases?
624628 return Err ( expr) ;
625629 }
626630 expr_struct_def_id
627631 }
628- hir :: def :: DefKind :: Variant => {
632+ DefKind :: Variant => {
629633 // If this is a variant, its parent is the type definition.
630634 if in_ty_adt. did ( ) != self . tcx . parent ( expr_struct_def_id) {
631635 // FIXME: Deal with type aliases?
@@ -727,14 +731,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
727731 } ;
728732
729733 let variant_def_id = match expr_struct_def_kind {
730- hir :: def :: DefKind :: Ctor ( hir:: def:: CtorOf :: Struct , hir:: def:: CtorKind :: Fn ) => {
734+ DefKind :: Ctor ( hir:: def:: CtorOf :: Struct , hir:: def:: CtorKind :: Fn ) => {
731735 if in_ty_adt. did ( ) != self . tcx . parent ( expr_ctor_def_id) {
732736 // FIXME: Deal with type aliases?
733737 return Err ( expr) ;
734738 }
735739 self . tcx . parent ( expr_ctor_def_id)
736740 }
737- hir :: def :: DefKind :: Ctor ( hir:: def:: CtorOf :: Variant , hir:: def:: CtorKind :: Fn ) => {
741+ DefKind :: Ctor ( hir:: def:: CtorOf :: Variant , hir:: def:: CtorKind :: Fn ) => {
738742 // For a typical enum like
739743 // `enum Blah<T> { Variant(T) }`
740744 // we get the following resolutions:
0 commit comments