@@ -117,33 +117,32 @@ pub(crate) fn inlay_hints(
117
117
118
118
let mut acc = Vec :: new ( ) ;
119
119
120
- let hints = |node| hints ( & mut acc, & sema, config, file_id, node) ;
121
- match range_limit {
122
- Some ( FileRange { range, .. } ) => match file. covering_element ( range) {
123
- NodeOrToken :: Token ( _) => return acc,
124
- NodeOrToken :: Node ( n) => n
125
- . descendants ( )
126
- . filter ( |descendant| range. intersect ( descendant. text_range ( ) ) . is_some ( ) )
127
- . for_each ( hints) ,
128
- } ,
129
- None => file. descendants ( ) . for_each ( hints) ,
130
- } ;
120
+ if let Some ( scope) = sema. scope ( & file) {
121
+ let famous_defs = FamousDefs ( & sema, scope. krate ( ) ) ;
122
+
123
+ let hints = |node| hints ( & mut acc, & famous_defs, config, file_id, node) ;
124
+ match range_limit {
125
+ Some ( FileRange { range, .. } ) => match file. covering_element ( range) {
126
+ NodeOrToken :: Token ( _) => return acc,
127
+ NodeOrToken :: Node ( n) => n
128
+ . descendants ( )
129
+ . filter ( |descendant| range. intersect ( descendant. text_range ( ) ) . is_some ( ) )
130
+ . for_each ( hints) ,
131
+ } ,
132
+ None => file. descendants ( ) . for_each ( hints) ,
133
+ } ;
134
+ }
131
135
132
136
acc
133
137
}
134
138
135
139
fn hints (
136
140
hints : & mut Vec < InlayHint > ,
137
- sema : & Semantics < RootDatabase > ,
141
+ famous_defs @ FamousDefs ( sema, _ ) : & FamousDefs ,
138
142
config : & InlayHintsConfig ,
139
143
file_id : FileId ,
140
144
node : SyntaxNode ,
141
145
) {
142
- let famous_defs = match sema. scope ( & node) {
143
- Some ( it) => FamousDefs ( sema, it. krate ( ) ) ,
144
- None => return ,
145
- } ;
146
-
147
146
closing_brace_hints ( hints, sema, config, file_id, node. clone ( ) ) ;
148
147
match_ast ! {
149
148
match node {
@@ -168,8 +167,18 @@ fn hints(
168
167
}
169
168
Some ( ( ) )
170
169
} ,
171
- ast:: Fn ( it) => lifetime_fn_hints( hints, config, it) ,
172
- _ => Some ( ( ) ) ,
170
+ ast:: Item ( it) => match it {
171
+ // FIXME: record impl lifetimes so they aren't being reused in assoc item lifetime inlay hints
172
+ ast:: Item :: Impl ( _) => None ,
173
+ ast:: Item :: Fn ( it) => fn_lifetime_fn_hints( hints, config, it) ,
174
+ // static type elisions
175
+ ast:: Item :: Static ( it) => implicit_static_hints( hints, config, Either :: Left ( it) ) ,
176
+ ast:: Item :: Const ( it) => implicit_static_hints( hints, config, Either :: Right ( it) ) ,
177
+ _ => None ,
178
+ } ,
179
+ // FIXME: fn-ptr type, dyn fn type, and trait object type elisions
180
+ ast:: Type ( _) => None ,
181
+ _ => None ,
173
182
}
174
183
} ;
175
184
}
@@ -279,7 +288,39 @@ fn closing_brace_hints(
279
288
None
280
289
}
281
290
282
- fn lifetime_fn_hints (
291
+ fn implicit_static_hints (
292
+ acc : & mut Vec < InlayHint > ,
293
+ config : & InlayHintsConfig ,
294
+ statik_or_const : Either < ast:: Static , ast:: Const > ,
295
+ ) -> Option < ( ) > {
296
+ if config. lifetime_elision_hints != LifetimeElisionHints :: Always {
297
+ return None ;
298
+ }
299
+
300
+ if let Either :: Right ( it) = & statik_or_const {
301
+ if ast:: AssocItemList :: can_cast (
302
+ it. syntax ( ) . parent ( ) . map_or ( SyntaxKind :: EOF , |it| it. kind ( ) ) ,
303
+ ) {
304
+ return None ;
305
+ }
306
+ }
307
+
308
+ if let Some ( ast:: Type :: RefType ( ty) ) = statik_or_const. either ( |it| it. ty ( ) , |it| it. ty ( ) ) {
309
+ if ty. lifetime ( ) . is_none ( ) {
310
+ let t = ty. amp_token ( ) ?;
311
+ acc. push ( InlayHint {
312
+ range : t. text_range ( ) ,
313
+ kind : InlayKind :: LifetimeHint ,
314
+ label : "'static" . to_owned ( ) ,
315
+ tooltip : Some ( InlayTooltip :: String ( "Elided static lifetime" . into ( ) ) ) ,
316
+ } ) ;
317
+ }
318
+ }
319
+
320
+ Some ( ( ) )
321
+ }
322
+
323
+ fn fn_lifetime_fn_hints (
283
324
acc : & mut Vec < InlayHint > ,
284
325
config : & InlayHintsConfig ,
285
326
func : ast:: Fn ,
@@ -2593,6 +2634,30 @@ impl () {
2593
2634
) ;
2594
2635
}
2595
2636
2637
+ #[ test]
2638
+ fn hints_lifetimes_static ( ) {
2639
+ check_with_config (
2640
+ InlayHintsConfig {
2641
+ lifetime_elision_hints : LifetimeElisionHints :: Always ,
2642
+ ..TEST_CONFIG
2643
+ } ,
2644
+ r#"
2645
+ trait Trait {}
2646
+ static S: &str = "";
2647
+ // ^'static
2648
+ const C: &str = "";
2649
+ // ^'static
2650
+ const C: &dyn Trait = panic!();
2651
+ // ^'static
2652
+
2653
+ impl () {
2654
+ const C: &str = "";
2655
+ const C: &dyn Trait = panic!();
2656
+ }
2657
+ "# ,
2658
+ ) ;
2659
+ }
2660
+
2596
2661
#[ test]
2597
2662
fn hints_implicit_reborrow ( ) {
2598
2663
check_with_config (
0 commit comments