@@ -41,12 +41,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
41
41
let id = free_region. scope ;
42
42
let node_id = self . tcx . hir . as_local_node_id ( id) . unwrap ( ) ;
43
43
let body_id = self . tcx . hir . maybe_body_owned_by ( node_id) . unwrap ( ) ;
44
- let mut is_first = false ;
45
44
let body = self . tcx . hir . body ( body_id) ;
46
45
if let Some ( tables) = self . in_progress_tables {
47
46
body. arguments
48
47
. iter ( )
49
- . filter_map ( |arg| {
48
+ . enumerate ( )
49
+ . filter_map ( |( index, arg) | {
50
50
let ty = tables. borrow ( ) . node_id_to_type ( arg. id ) ;
51
51
let mut found_anon_region = false ;
52
52
let new_arg_ty = self . tcx
@@ -57,9 +57,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
57
57
r
58
58
} ) ;
59
59
if found_anon_region {
60
- if body. arguments . iter ( ) . nth ( 0 ) == Some ( & arg) {
61
- is_first = true ;
62
- }
60
+ let is_first = index == 0 ;
63
61
Some ( ( arg, new_arg_ty, free_region. bound_region , is_first) )
64
62
} else {
65
63
None
@@ -91,19 +89,18 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
91
89
// only introduced anonymous regions in parameters) as well as a
92
90
// version new_ty of its type where the anonymous region is replaced
93
91
// with the named one.
94
- let ( named, ( arg, new_ty, br, is_first) , scope_def_id) = if
95
- self . is_named_region ( sub) && self . is_suitable_anonymous_region ( sup) . is_some ( ) {
96
- ( sub,
97
- self . find_arg_with_anonymous_region ( sup, sub) . unwrap ( ) ,
98
- self . is_suitable_anonymous_region ( sup) . unwrap ( ) )
99
- } else if
100
- self . is_named_region ( sup) && self . is_suitable_anonymous_region ( sub) . is_some ( ) {
101
- ( sup,
102
- self . find_arg_with_anonymous_region ( sub, sup) . unwrap ( ) ,
103
- self . is_suitable_anonymous_region ( sub) . unwrap ( ) )
104
- } else {
105
- return false ; // inapplicable
106
- } ;
92
+ let ( named, ( arg, new_ty, br, is_first) , scope_def_id) =
93
+ if sub. is_named_region ( ) && self . is_suitable_anonymous_region ( sup) . is_some ( ) {
94
+ ( sub,
95
+ self . find_arg_with_anonymous_region ( sup, sub) . unwrap ( ) ,
96
+ self . is_suitable_anonymous_region ( sup) . unwrap ( ) )
97
+ } else if sup. is_named_region ( ) && self . is_suitable_anonymous_region ( sub) . is_some ( ) {
98
+ ( sup,
99
+ self . find_arg_with_anonymous_region ( sub, sup) . unwrap ( ) ,
100
+ self . is_suitable_anonymous_region ( sub) . unwrap ( ) )
101
+ } else {
102
+ return false ; // inapplicable
103
+ } ;
107
104
108
105
// Here, we check for the case where the anonymous region
109
106
// is in the return type.
@@ -179,8 +176,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
179
176
// proceed ahead //
180
177
}
181
178
Some ( hir_map:: NodeImplItem ( ..) ) => {
182
- if self . tcx . impl_trait_ref ( self . tcx .
183
- associated_item ( anonymous_region_binding_scope) . container . id ( ) ) . is_some ( ) {
179
+ let container_id = self . tcx
180
+ . associated_item ( anonymous_region_binding_scope)
181
+ . container
182
+ . id ( ) ;
183
+ if self . tcx . impl_trait_ref ( container_id) . is_some ( ) {
184
184
// For now, we do not try to target impls of traits. This is
185
185
// because this message is going to suggest that the user
186
186
// change the fn signature, but they may not be free to do so,
@@ -189,8 +189,6 @@ associated_item(anonymous_region_binding_scope).container.id()).is_some() {
189
189
// FIXME(#42706) -- in some cases, we could do better here.
190
190
return None ;
191
191
}
192
- else { }
193
-
194
192
}
195
193
_ => return None , // inapplicable
196
194
// we target only top-level functions
0 commit comments