@@ -120,11 +120,27 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
120
120
if let ty:: ReFree ( ref free_region) = * region {
121
121
if let ty:: BrAnon ( ..) = free_region. bound_region {
122
122
let anonymous_region_binding_scope = free_region. scope ;
123
+ let node_id = self . tcx
124
+ . hir
125
+ . as_local_node_id ( anonymous_region_binding_scope)
126
+ . unwrap ( ) ;
127
+ let mut is_impl_item = false ;
128
+ match self . tcx . hir . find ( node_id) {
129
+
130
+ Some ( hir_map:: NodeItem ( ..) ) |
131
+ Some ( hir_map:: NodeTraitItem ( ..) ) => {
132
+ // Success -- proceed to return Some below
133
+ }
134
+ Some ( hir_map:: NodeImplItem ( ..) ) => {
135
+ is_impl_item =
136
+ self . is_bound_region_in_impl_item ( anonymous_region_binding_scope) ;
137
+ }
138
+ _ => return None ,
139
+ }
123
140
return Some ( FreeRegionInfo {
124
141
def_id : anonymous_region_binding_scope,
125
142
boundregion : free_region. bound_region ,
126
- is_impl_item :
127
- self . is_bound_region_in_impl_item ( anonymous_region_binding_scope) ,
143
+ is_impl_item : is_impl_item,
128
144
} ) ;
129
145
}
130
146
}
@@ -162,34 +178,18 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
162
178
163
179
// Here we check if the bound region is in Impl Item.
164
180
pub fn is_bound_region_in_impl_item ( & self , anonymous_region_binding_scope : DefId ) -> bool {
165
- let node_id = self . tcx
166
- . hir
167
- . as_local_node_id ( anonymous_region_binding_scope)
168
- . unwrap ( ) ;
169
- match self . tcx . hir . find ( node_id) {
170
-
171
- Some ( hir_map:: NodeItem ( ..) ) |
172
- Some ( hir_map:: NodeTraitItem ( ..) ) => {
173
- // Success -- proceed to return Some below
174
- }
175
- Some ( hir_map:: NodeImplItem ( ..) ) => {
176
- let container_id = self . tcx
177
- . associated_item ( anonymous_region_binding_scope)
178
- . container
179
- . id ( ) ;
180
- if self . tcx . impl_trait_ref ( container_id) . is_some ( ) {
181
- // For now, we do not try to target impls of traits. This is
182
- // because this message is going to suggest that the user
183
- // change the fn signature, but they may not be free to do so,
184
- // since the signature must match the trait.
185
- //
186
- // FIXME(#42706) -- in some cases, we could do better here.
187
- return true ;
188
- }
189
- }
190
- _ => {
191
- return false ;
192
- }
181
+ let container_id = self . tcx
182
+ . associated_item ( anonymous_region_binding_scope)
183
+ . container
184
+ . id ( ) ;
185
+ if self . tcx . impl_trait_ref ( container_id) . is_some ( ) {
186
+ // For now, we do not try to target impls of traits. This is
187
+ // because this message is going to suggest that the user
188
+ // change the fn signature, but they may not be free to do so,
189
+ // since the signature must match the trait.
190
+ //
191
+ // FIXME(#42706) -- in some cases, we could do better here.
192
+ return true ;
193
193
}
194
194
false
195
195
}
0 commit comments