@@ -2052,13 +2052,15 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2052
2052
// Handle `self` specially.
2053
2053
if index == 0 && has_self {
2054
2054
let self_lifetime = self . find_lifetime_for_self ( ty) ;
2055
- if let Set1 :: One ( lifetime ) = self_lifetime {
2055
+ elision_lifetime = match self_lifetime {
2056
2056
// We found `self` elision.
2057
- elision_lifetime = Elision :: Self_ ( lifetime) ;
2058
- } else {
2057
+ Set1 :: One ( lifetime) => Elision :: Self_ ( lifetime) ,
2058
+ // `self` itself had ambiguous lifetimes, e.g.
2059
+ // &Box<&Self>
2060
+ Set1 :: Many => Elision :: Err ,
2059
2061
// We do not have `self` elision: disregard the `Elision::Param` that we may
2060
2062
// have found.
2061
- elision_lifetime = Elision :: None ;
2063
+ Set1 :: Empty => Elision :: None ,
2062
2064
}
2063
2065
}
2064
2066
debug ! ( "(resolving function / closure) recorded parameter" ) ;
@@ -2082,6 +2084,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2082
2084
r : & ' r Resolver < ' a , ' tcx > ,
2083
2085
impl_self : Option < Res > ,
2084
2086
lifetime : Set1 < LifetimeRes > ,
2087
+ self_found : bool ,
2085
2088
}
2086
2089
2087
2090
impl SelfVisitor < ' _ , ' _ , ' _ > {
@@ -2105,7 +2108,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2105
2108
impl < ' a > Visitor < ' a > for SelfVisitor < ' _ , ' _ , ' _ > {
2106
2109
fn visit_ty ( & mut self , ty : & ' a Ty ) {
2107
2110
trace ! ( "SelfVisitor considering ty={:?}" , ty) ;
2108
- if let TyKind :: Ref ( lt, ref mt) = ty. kind && self . is_self_ty ( & mt. ty ) {
2111
+ if self . is_self_ty ( ty) {
2112
+ trace ! ( "SelfVisitor found Self" ) ;
2113
+ self . self_found = true ;
2114
+ }
2115
+ if let TyKind :: Ref ( lt, _) = ty. kind {
2109
2116
let lt_id = if let Some ( lt) = lt {
2110
2117
lt. id
2111
2118
} else {
@@ -2146,10 +2153,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2146
2153
Res :: Def ( DefKind :: Struct | DefKind :: Union | DefKind :: Enum , _, ) | Res :: PrimTy ( _)
2147
2154
)
2148
2155
} ) ;
2149
- let mut visitor = SelfVisitor { r : self . r , impl_self, lifetime : Set1 :: Empty } ;
2156
+ let mut visitor =
2157
+ SelfVisitor { r : self . r , impl_self, lifetime : Set1 :: Empty , self_found : false } ;
2150
2158
visitor. visit_ty ( ty) ;
2151
- trace ! ( "SelfVisitor found={:?}" , visitor. lifetime) ;
2152
- visitor. lifetime
2159
+ trace ! ( "SelfVisitor found={:?}, self_found={:?} " , visitor. lifetime, visitor . self_found ) ;
2160
+ if visitor. self_found { visitor . lifetime } else { Set1 :: Empty }
2153
2161
}
2154
2162
2155
2163
/// Searches the current set of local scopes for labels. Returns the `NodeId` of the resolved
0 commit comments