88//! show up for normal completions, or they won't show completions other than lifetimes depending
99//! on the fixture input.
1010use hir:: { sym, Name , ScopeDef } ;
11- use syntax:: { ast, ToSmolStr , TokenText } ;
1211
1312use crate :: {
1413 completions:: Completions ,
@@ -21,33 +20,24 @@ pub(crate) fn complete_lifetime(
2120 ctx : & CompletionContext < ' _ > ,
2221 lifetime_ctx : & LifetimeContext ,
2322) {
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 ;
3627 } ;
37- let param_lifetime = param_lifetime. as_ref ( ) . map ( ast:: Lifetime :: text) ;
38- let param_lifetime = param_lifetime. as_ref ( ) . map ( TokenText :: as_str) ;
3928
4029 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 ( _) ) ) {
4631 acc. add_lifetime ( ctx, name) ;
4732 }
4833 } ) ;
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 ( ) ) ) ;
5141 }
5242}
5343
@@ -222,6 +212,8 @@ fn foo<'footime, 'lifetime: 'a$0>() {}
222212"# ,
223213 expect ! [ [ r#"
224214 lt 'footime
215+ lt 'lifetime
216+ lt 'static
225217 "# ] ] ,
226218 ) ;
227219 }
0 commit comments