8
8
//! show up for normal completions, or they won't show completions other than lifetimes depending
9
9
//! on the fixture input.
10
10
use hir:: { sym, Name , ScopeDef } ;
11
- use syntax:: { ast, ToSmolStr , TokenText } ;
12
11
13
12
use crate :: {
14
13
completions:: Completions ,
@@ -21,33 +20,24 @@ pub(crate) fn complete_lifetime(
21
20
ctx : & CompletionContext < ' _ > ,
22
21
lifetime_ctx : & LifetimeContext ,
23
22
) {
24
- let ( lp, lifetime) = match lifetime_ctx {
25
- LifetimeContext { kind : LifetimeKind :: Lifetime , lifetime } => ( None , lifetime) ,
26
- LifetimeContext {
27
- kind : LifetimeKind :: LifetimeParam { is_decl : false , param } ,
28
- lifetime,
29
- } => ( Some ( param) , lifetime) ,
30
- _ => return ,
31
- } ;
32
- let param_lifetime = match ( lifetime, lp. and_then ( |lp| lp. lifetime ( ) ) ) {
33
- ( Some ( lt) , Some ( lp) ) if lp == lt. clone ( ) => return ,
34
- ( Some ( _) , Some ( lp) ) => Some ( lp) ,
35
- _ => None ,
23
+ let & LifetimeContext { kind : LifetimeKind :: Lifetime { in_lifetime_param_bound, def } , .. } =
24
+ lifetime_ctx
25
+ else {
26
+ return ;
36
27
} ;
37
- let param_lifetime = param_lifetime. as_ref ( ) . map ( ast:: Lifetime :: text) ;
38
- let param_lifetime = param_lifetime. as_ref ( ) . map ( TokenText :: as_str) ;
39
28
40
29
ctx. process_all_names_raw ( & mut |name, res| {
41
- if matches ! (
42
- res,
43
- ScopeDef :: GenericParam ( hir:: GenericParam :: LifetimeParam ( _) )
44
- if param_lifetime != Some ( & * name. display_no_db( ctx. edition) . to_smolstr( ) )
45
- ) {
30
+ if matches ! ( res, ScopeDef :: GenericParam ( hir:: GenericParam :: LifetimeParam ( _) ) ) {
46
31
acc. add_lifetime ( ctx, name) ;
47
32
}
48
33
} ) ;
49
- if param_lifetime. is_none ( ) {
50
- acc. add_lifetime ( ctx, Name :: new_symbol_root ( sym:: tick_static. clone ( ) ) ) ;
34
+ acc. add_lifetime ( ctx, Name :: new_symbol_root ( sym:: tick_static. clone ( ) ) ) ;
35
+ if !in_lifetime_param_bound
36
+ && def. is_some_and ( |def| {
37
+ !matches ! ( def, hir:: GenericDef :: Function ( _) | hir:: GenericDef :: Impl ( _) )
38
+ } )
39
+ {
40
+ acc. add_lifetime ( ctx, Name :: new_symbol_root ( sym:: tick_underscore. clone ( ) ) ) ;
51
41
}
52
42
}
53
43
@@ -222,6 +212,8 @@ fn foo<'footime, 'lifetime: 'a$0>() {}
222
212
"# ,
223
213
expect ! [ [ r#"
224
214
lt 'footime
215
+ lt 'lifetime
216
+ lt 'static
225
217
"# ] ] ,
226
218
) ;
227
219
}
0 commit comments