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