1
1
use crate :: FnCtxt ;
2
2
use rustc_hir as hir;
3
- use rustc_hir:: def:: Res ;
3
+ use rustc_hir:: def:: { DefKind , Res } ;
4
4
use rustc_hir:: def_id:: DefId ;
5
5
use rustc_infer:: { infer:: type_variable:: TypeVariableOriginKind , traits:: ObligationCauseCode } ;
6
6
use rustc_middle:: ty:: { self , Ty , TyCtxt , TypeSuperVisitable , TypeVisitable , TypeVisitor } ;
@@ -133,15 +133,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
133
133
}
134
134
}
135
135
}
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 ( )
143
140
{
144
- return true ;
141
+ if self . point_at_path_if_possible ( error, def_id, param, qpath) {
142
+ return true ;
143
+ }
145
144
}
146
145
}
147
146
hir:: ExprKind :: MethodCall ( segment, receiver, args, ..) => {
@@ -168,10 +167,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
168
167
}
169
168
}
170
169
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)
175
172
{
176
173
for param in
177
174
[ param_to_point_at, fallback_param_to_point_at, self_param_to_point_at]
@@ -193,10 +190,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
193
190
}
194
191
}
195
192
}
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 ( )
198
197
{
199
- return true ;
198
+ if self . point_at_path_if_possible ( error, def_id, param, qpath) {
199
+ return true ;
200
+ }
200
201
}
201
202
}
202
203
_ => { }
@@ -214,10 +215,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
214
215
) -> bool {
215
216
match qpath {
216
217
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
+ }
221
225
}
222
226
}
223
227
hir:: QPath :: TypeRelative ( _, segment) => {
@@ -618,14 +622,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
618
622
} ;
619
623
620
624
let variant_def_id = match expr_struct_def_kind {
621
- hir :: def :: DefKind :: Struct => {
625
+ DefKind :: Struct => {
622
626
if in_ty_adt. did ( ) != expr_struct_def_id {
623
627
// FIXME: Deal with type aliases?
624
628
return Err ( expr) ;
625
629
}
626
630
expr_struct_def_id
627
631
}
628
- hir :: def :: DefKind :: Variant => {
632
+ DefKind :: Variant => {
629
633
// If this is a variant, its parent is the type definition.
630
634
if in_ty_adt. did ( ) != self . tcx . parent ( expr_struct_def_id) {
631
635
// FIXME: Deal with type aliases?
@@ -727,14 +731,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
727
731
} ;
728
732
729
733
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 ) => {
731
735
if in_ty_adt. did ( ) != self . tcx . parent ( expr_ctor_def_id) {
732
736
// FIXME: Deal with type aliases?
733
737
return Err ( expr) ;
734
738
}
735
739
self . tcx . parent ( expr_ctor_def_id)
736
740
}
737
- hir :: def :: DefKind :: Ctor ( hir:: def:: CtorOf :: Variant , hir:: def:: CtorKind :: Fn ) => {
741
+ DefKind :: Ctor ( hir:: def:: CtorOf :: Variant , hir:: def:: CtorKind :: Fn ) => {
738
742
// For a typical enum like
739
743
// `enum Blah<T> { Variant(T) }`
740
744
// we get the following resolutions:
0 commit comments