@@ -5,6 +5,7 @@ use rustc_ast::{
55 TyKind ,
66} ;
77use rustc_hir:: def:: LifetimeRes ;
8+ use rustc_middle:: span_bug;
89use rustc_middle:: ty:: ResolverAstLowering ;
910use rustc_span:: symbol:: { kw, Ident } ;
1011use rustc_span:: Span ;
@@ -21,11 +22,26 @@ impl<'ast> LifetimeCollectVisitor<'ast> {
2122 }
2223
2324 fn record_lifetime_use ( & mut self , lifetime : Lifetime ) {
24- let res = self . resolver . get_lifetime_res ( lifetime. id ) . unwrap_or ( LifetimeRes :: Error ) ;
25-
26- if res. binder ( ) . map_or ( true , |b| !self . current_binders . contains ( & b) ) {
27- if !self . collected_lifetimes . contains ( & lifetime) {
28- self . collected_lifetimes . push ( lifetime) ;
25+ match self . resolver . get_lifetime_res ( lifetime. id ) . unwrap_or ( LifetimeRes :: Error ) {
26+ LifetimeRes :: Param { binder, .. } | LifetimeRes :: Fresh { binder, .. } => {
27+ if !self . current_binders . contains ( & binder) {
28+ if !self . collected_lifetimes . contains ( & lifetime) {
29+ self . collected_lifetimes . push ( lifetime) ;
30+ }
31+ }
32+ }
33+ LifetimeRes :: Static | LifetimeRes :: Error => {
34+ if !self . collected_lifetimes . contains ( & lifetime) {
35+ self . collected_lifetimes . push ( lifetime) ;
36+ }
37+ }
38+ LifetimeRes :: Infer => { }
39+ res => {
40+ let bug_msg = format ! (
41+ "Unexpected lifetime resolution {:?} for {:?} at {:?}" ,
42+ res, lifetime. ident, lifetime. ident. span
43+ ) ;
44+ span_bug ! ( lifetime. ident. span, "{}" , bug_msg) ;
2945 }
3046 }
3147 }
0 commit comments