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