@@ -2146,41 +2146,44 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
2146
2146
// First (determined here), if `self` is by-reference, then the
2147
2147
// implied output region is the region of the self parameter.
2148
2148
if has_self {
2149
- // Look for `self: &'a Self` - also desugared from `&'a self`,
2150
- // and if that matches, use it for elision and return early.
2151
- let is_self_ty = |res : Res | {
2152
- if let Res :: SelfTy ( ..) = res {
2153
- return true ;
2154
- }
2155
-
2156
- // Can't always rely on literal (or implied) `Self` due
2157
- // to the way elision rules were originally specified.
2158
- let impl_self = impl_self. map ( |ty| & ty. node ) ;
2159
- if let Some ( & hir:: TyKind :: Path ( hir:: QPath :: Resolved ( None , ref path) ) ) = impl_self {
2160
- match path. res {
2161
- // Whitelist the types that unambiguously always
2162
- // result in the same type constructor being used
2163
- // (it can't differ between `Self` and `self`).
2164
- Res :: Def ( DefKind :: Struct , _)
2165
- | Res :: Def ( DefKind :: Union , _)
2166
- | Res :: Def ( DefKind :: Enum , _)
2167
- | Res :: PrimTy ( _) => {
2168
- return res == path. res
2169
- }
2170
- _ => { }
2149
+ struct SelfVisitor < ' a > {
2150
+ map : & ' a NamedRegionMap ,
2151
+ impl_self : Option < & ' a hir:: TyKind > ,
2152
+ lifetime : Option < Region > ,
2153
+ }
2154
+
2155
+ impl SelfVisitor < ' _ > {
2156
+ // Look for `self: &'a Self` - also desugared from `&'a self`,
2157
+ // and if that matches, use it for elision and return early.
2158
+ fn is_self_ty ( & self , res : Res ) -> bool {
2159
+ if let Res :: SelfTy ( ..) = res {
2160
+ return true ;
2171
2161
}
2172
- }
2173
2162
2174
- false
2175
- } ;
2163
+ // Can't always rely on literal (or implied) `Self` due
2164
+ // to the way elision rules were originally specified.
2165
+ if let Some ( & hir:: TyKind :: Path ( hir:: QPath :: Resolved ( None , ref path) ) ) =
2166
+ self . impl_self
2167
+ {
2168
+ match path. res {
2169
+ // Whitelist the types that unambiguously always
2170
+ // result in the same type constructor being used
2171
+ // (it can't differ between `Self` and `self`).
2172
+ Res :: Def ( DefKind :: Struct , _)
2173
+ | Res :: Def ( DefKind :: Union , _)
2174
+ | Res :: Def ( DefKind :: Enum , _)
2175
+ | Res :: PrimTy ( _) => {
2176
+ return res == path. res
2177
+ }
2178
+ _ => { }
2179
+ }
2180
+ }
2176
2181
2177
- struct SelfVisitor < ' a , F : FnMut ( Res ) -> bool > {
2178
- is_self_ty : F ,
2179
- map : & ' a NamedRegionMap ,
2180
- lifetime : Option < Region > ,
2182
+ false
2183
+ }
2181
2184
}
2182
2185
2183
- impl < ' a , F : FnMut ( Res ) -> bool > Visitor < ' a > for SelfVisitor < ' a , F > {
2186
+ impl < ' a > Visitor < ' a > for SelfVisitor < ' a > {
2184
2187
fn nested_visit_map < ' this > ( & ' this mut self ) -> NestedVisitorMap < ' this , ' a > {
2185
2188
NestedVisitorMap :: None
2186
2189
}
@@ -2189,7 +2192,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
2189
2192
if let hir:: TyKind :: Rptr ( lifetime_ref, ref mt) = ty. node {
2190
2193
if let hir:: TyKind :: Path ( hir:: QPath :: Resolved ( None , ref path) ) = mt. ty . node
2191
2194
{
2192
- if ( self . is_self_ty ) ( path. res ) {
2195
+ if self . is_self_ty ( path. res ) {
2193
2196
self . lifetime = self . map . defs . get ( & lifetime_ref. hir_id ) . copied ( ) ;
2194
2197
return ;
2195
2198
}
@@ -2200,8 +2203,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
2200
2203
}
2201
2204
2202
2205
let mut visitor = SelfVisitor {
2203
- is_self_ty,
2204
2206
map : self . map ,
2207
+ impl_self : impl_self. map ( |ty| & ty. node ) ,
2205
2208
lifetime : None ,
2206
2209
} ;
2207
2210
visitor. visit_ty ( & inputs[ 0 ] ) ;
0 commit comments