@@ -5,6 +5,7 @@ use rustc_ast::{
5
5
TyKind ,
6
6
} ;
7
7
use rustc_hir:: def:: LifetimeRes ;
8
+ use rustc_middle:: span_bug;
8
9
use rustc_middle:: ty:: ResolverAstLowering ;
9
10
use rustc_span:: symbol:: { kw, Ident } ;
10
11
use rustc_span:: Span ;
@@ -21,11 +22,26 @@ impl<'ast> LifetimeCollectVisitor<'ast> {
21
22
}
22
23
23
24
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) ;
29
45
}
30
46
}
31
47
}
0 commit comments