@@ -2149,46 +2149,44 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
2149
2149
false
2150
2150
} ;
2151
2151
2152
- let mut self_arg = & inputs[ 0 ] . node ;
2153
-
2154
- // Apply `self: &(mut) Self` elision rules even if nested in `Pin`.
2155
- loop {
2156
- if let hir:: TyKind :: Path ( hir:: QPath :: Resolved ( None , ref path) ) = * self_arg {
2157
- if let Res :: Def ( DefKind :: Struct , def_id) = path. res {
2158
- if self . tcx . lang_items ( ) . pin_type ( ) == Some ( def_id) {
2159
- if let Some ( args) = path
2160
- . segments
2161
- . last ( )
2162
- . and_then ( |segment| segment. args . as_ref ( ) )
2163
- {
2164
- if args. args . len ( ) == 1 {
2165
- if let GenericArg :: Type ( ty) = & args. args [ 0 ] {
2166
- self_arg = & ty. node ;
2167
- // Keep dereferencing `self_arg` until we get to non-`Pin`
2168
- // types.
2169
- continue ;
2170
- }
2171
- }
2152
+ struct SelfVisitor < ' a , F : FnMut ( Res ) -> bool > {
2153
+ is_self_ty : F ,
2154
+ map : & ' a NamedRegionMap ,
2155
+ lifetime : Option < Region > ,
2156
+ }
2157
+
2158
+ impl < ' a , F : FnMut ( Res ) -> bool > Visitor < ' a > for SelfVisitor < ' a , F > {
2159
+ fn nested_visit_map < ' this > ( & ' this mut self ) -> NestedVisitorMap < ' this , ' a > {
2160
+ NestedVisitorMap :: None
2161
+ }
2162
+
2163
+ fn visit_ty ( & mut self , ty : & ' a hir:: Ty ) {
2164
+ if let hir:: TyKind :: Rptr ( lifetime_ref, ref mt) = ty. node {
2165
+ if let hir:: TyKind :: Path ( hir:: QPath :: Resolved ( None , ref path) ) = mt. ty . node
2166
+ {
2167
+ if ( self . is_self_ty ) ( path. res ) {
2168
+ self . lifetime = self . map . defs . get ( & lifetime_ref. hir_id ) . copied ( ) ;
2169
+ return ;
2172
2170
}
2173
2171
}
2174
2172
}
2173
+ intravisit:: walk_ty ( self , ty)
2175
2174
}
2176
- break ;
2177
2175
}
2178
2176
2179
- if let hir :: TyKind :: Rptr ( lifetime_ref , ref mt ) = * self_arg {
2180
- if let hir :: TyKind :: Path ( hir :: QPath :: Resolved ( None , ref path ) ) = mt . ty . node {
2181
- if is_self_ty ( path . res ) {
2182
- if let Some ( & lifetime) = self . map . defs . get ( & lifetime_ref . hir_id ) {
2183
- let scope = Scope :: Elision {
2184
- elide : Elide :: Exact ( lifetime ) ,
2185
- s : self . scope ,
2186
- } ;
2187
- self . with ( scope , |_ , this| this . visit_ty ( output ) ) ;
2188
- return ;
2189
- }
2190
- }
2191
- }
2177
+ let mut visitor = SelfVisitor {
2178
+ is_self_ty ,
2179
+ map : self . map ,
2180
+ lifetime : None ,
2181
+ } ;
2182
+ visitor . visit_ty ( & inputs [ 0 ] ) ;
2183
+ if let Some ( lifetime ) = visitor . lifetime {
2184
+ let scope = Scope :: Elision {
2185
+ elide : Elide :: Exact ( lifetime ) ,
2186
+ s : self . scope ,
2187
+ } ;
2188
+ self . with ( scope , |_ , this| this . visit_ty ( output ) ) ;
2189
+ return ;
2192
2190
}
2193
2191
}
2194
2192
0 commit comments