@@ -114,51 +114,63 @@ fn diagnostic_hir_wf_check<'tcx>(
114
114
// Get the starting `hir::Ty` using our `WellFormedLoc`.
115
115
// We will walk 'into' this type to try to find
116
116
// a more precise span for our predicate.
117
- let ty = match loc {
117
+ let tys = match loc {
118
118
WellFormedLoc :: Ty ( _) => match hir. get ( hir_id) {
119
119
hir:: Node :: ImplItem ( item) => match item. kind {
120
- hir:: ImplItemKind :: Type ( ty) => Some ( ty ) ,
121
- hir:: ImplItemKind :: Const ( ty, _) => Some ( ty ) ,
120
+ hir:: ImplItemKind :: Type ( ty) => vec ! [ ty ] ,
121
+ hir:: ImplItemKind :: Const ( ty, _) => vec ! [ ty ] ,
122
122
ref item => bug ! ( "Unexpected ImplItem {:?}" , item) ,
123
123
} ,
124
124
hir:: Node :: TraitItem ( item) => match item. kind {
125
- hir:: TraitItemKind :: Type ( _, ty) => ty,
126
- hir:: TraitItemKind :: Const ( ty, _) => Some ( ty ) ,
125
+ hir:: TraitItemKind :: Type ( _, ty) => ty. into_iter ( ) . collect ( ) ,
126
+ hir:: TraitItemKind :: Const ( ty, _) => vec ! [ ty ] ,
127
127
ref item => bug ! ( "Unexpected TraitItem {:?}" , item) ,
128
128
} ,
129
129
hir:: Node :: Item ( item) => match item. kind {
130
- hir:: ItemKind :: Static ( ty, _, _) | hir:: ItemKind :: Const ( ty, _) => Some ( ty) ,
131
- hir:: ItemKind :: Impl ( ref impl_) => {
132
- assert ! ( impl_. of_trait. is_none( ) , "Unexpected trait impl: {:?}" , impl_) ;
133
- Some ( impl_. self_ty )
134
- }
130
+ hir:: ItemKind :: Static ( ty, _, _) | hir:: ItemKind :: Const ( ty, _) => vec ! [ ty] ,
131
+ hir:: ItemKind :: Impl ( ref impl_) => match & impl_. of_trait {
132
+ Some ( t) => t
133
+ . path
134
+ . segments
135
+ . last ( )
136
+ . iter ( )
137
+ . flat_map ( |seg| seg. args ( ) . args )
138
+ . filter_map ( |arg| {
139
+ if let hir:: GenericArg :: Type ( ty) = arg { Some ( * ty) } else { None }
140
+ } )
141
+ . chain ( [ impl_. self_ty ] )
142
+ . collect ( ) ,
143
+ None => {
144
+ vec ! [ impl_. self_ty]
145
+ }
146
+ } ,
135
147
ref item => bug ! ( "Unexpected item {:?}" , item) ,
136
148
} ,
137
- hir:: Node :: Field ( field) => Some ( field. ty ) ,
149
+ hir:: Node :: Field ( field) => vec ! [ field. ty] ,
138
150
hir:: Node :: ForeignItem ( ForeignItem {
139
151
kind : ForeignItemKind :: Static ( ty, _) , ..
140
- } ) => Some ( * ty) ,
152
+ } ) => vec ! [ * ty] ,
141
153
hir:: Node :: GenericParam ( hir:: GenericParam {
142
154
kind : hir:: GenericParamKind :: Type { default : Some ( ty) , .. } ,
143
155
..
144
- } ) => Some ( * ty) ,
156
+ } ) => vec ! [ * ty] ,
145
157
ref node => bug ! ( "Unexpected node {:?}" , node) ,
146
158
} ,
147
159
WellFormedLoc :: Param { function : _, param_idx } => {
148
160
let fn_decl = hir. fn_decl_by_hir_id ( hir_id) . unwrap ( ) ;
149
161
// Get return type
150
162
if param_idx as usize == fn_decl. inputs . len ( ) {
151
163
match fn_decl. output {
152
- hir:: FnRetTy :: Return ( ty) => Some ( ty ) ,
164
+ hir:: FnRetTy :: Return ( ty) => vec ! [ ty ] ,
153
165
// The unit type `()` is always well-formed
154
- hir:: FnRetTy :: DefaultReturn ( _span) => None ,
166
+ hir:: FnRetTy :: DefaultReturn ( _span) => vec ! [ ] ,
155
167
}
156
168
} else {
157
- Some ( & fn_decl. inputs [ param_idx as usize ] )
169
+ vec ! [ & fn_decl. inputs[ param_idx as usize ] ]
158
170
}
159
171
}
160
172
} ;
161
- if let Some ( ty ) = ty {
173
+ for ty in tys {
162
174
visitor. visit_ty ( ty) ;
163
175
}
164
176
visitor. cause
0 commit comments