@@ -23,7 +23,7 @@ pub(crate) mod env_vars;
23
23
24
24
use std:: iter;
25
25
26
- use hir:: { known, ScopeDef , Variant } ;
26
+ use hir:: { known, HasAttrs , ScopeDef , Variant } ;
27
27
use ide_db:: { imports:: import_assets:: LocatedImport , SymbolKind } ;
28
28
use syntax:: ast;
29
29
@@ -181,6 +181,9 @@ impl Completions {
181
181
resolution : hir:: ScopeDef ,
182
182
doc_aliases : Vec < syntax:: SmolStr > ,
183
183
) {
184
+ if !ctx. check_stability ( resolution. attrs ( ctx. db ) . as_deref ( ) ) {
185
+ return ;
186
+ }
184
187
let is_private_editable = match ctx. def_is_visible ( & resolution) {
185
188
Visible :: Yes => false ,
186
189
Visible :: Editable => true ,
@@ -206,6 +209,9 @@ impl Completions {
206
209
local_name : hir:: Name ,
207
210
resolution : hir:: ScopeDef ,
208
211
) {
212
+ if !ctx. check_stability ( resolution. attrs ( ctx. db ) . as_deref ( ) ) {
213
+ return ;
214
+ }
209
215
let is_private_editable = match ctx. def_is_visible ( & resolution) {
210
216
Visible :: Yes => false ,
211
217
Visible :: Editable => true ,
@@ -228,6 +234,9 @@ impl Completions {
228
234
path_ctx : & PathCompletionCtx ,
229
235
e : hir:: Enum ,
230
236
) {
237
+ if !ctx. check_stability ( Some ( & e. attrs ( ctx. db ) ) ) {
238
+ return ;
239
+ }
231
240
e. variants ( ctx. db )
232
241
. into_iter ( )
233
242
. for_each ( |variant| self . add_enum_variant ( ctx, path_ctx, variant, None ) ) ;
@@ -241,6 +250,9 @@ impl Completions {
241
250
local_name : hir:: Name ,
242
251
doc_aliases : Vec < syntax:: SmolStr > ,
243
252
) {
253
+ if !ctx. check_stability ( Some ( & module. attrs ( ctx. db ) ) ) {
254
+ return ;
255
+ }
244
256
self . add_path_resolution (
245
257
ctx,
246
258
path_ctx,
@@ -257,6 +269,9 @@ impl Completions {
257
269
mac : hir:: Macro ,
258
270
local_name : hir:: Name ,
259
271
) {
272
+ if !ctx. check_stability ( Some ( & mac. attrs ( ctx. db ) ) ) {
273
+ return ;
274
+ }
260
275
let is_private_editable = match ctx. is_visible ( & mac) {
261
276
Visible :: Yes => false ,
262
277
Visible :: Editable => true ,
@@ -280,6 +295,9 @@ impl Completions {
280
295
func : hir:: Function ,
281
296
local_name : Option < hir:: Name > ,
282
297
) {
298
+ if !ctx. check_stability ( Some ( & func. attrs ( ctx. db ) ) ) {
299
+ return ;
300
+ }
283
301
let is_private_editable = match ctx. is_visible ( & func) {
284
302
Visible :: Yes => false ,
285
303
Visible :: Editable => true ,
@@ -304,6 +322,9 @@ impl Completions {
304
322
receiver : Option < hir:: Name > ,
305
323
local_name : Option < hir:: Name > ,
306
324
) {
325
+ if !ctx. check_stability ( Some ( & func. attrs ( ctx. db ) ) ) {
326
+ return ;
327
+ }
307
328
let is_private_editable = match ctx. is_visible ( & func) {
308
329
Visible :: Yes => false ,
309
330
Visible :: Editable => true ,
@@ -328,6 +349,9 @@ impl Completions {
328
349
func : hir:: Function ,
329
350
import : LocatedImport ,
330
351
) {
352
+ if !ctx. check_stability ( Some ( & func. attrs ( ctx. db ) ) ) {
353
+ return ;
354
+ }
331
355
let is_private_editable = match ctx. is_visible ( & func) {
332
356
Visible :: Yes => false ,
333
357
Visible :: Editable => true ,
@@ -348,6 +372,9 @@ impl Completions {
348
372
}
349
373
350
374
pub ( crate ) fn add_const ( & mut self , ctx : & CompletionContext < ' _ > , konst : hir:: Const ) {
375
+ if !ctx. check_stability ( Some ( & konst. attrs ( ctx. db ) ) ) {
376
+ return ;
377
+ }
351
378
let is_private_editable = match ctx. is_visible ( & konst) {
352
379
Visible :: Yes => false ,
353
380
Visible :: Editable => true ,
@@ -364,6 +391,9 @@ impl Completions {
364
391
ctx : & CompletionContext < ' _ > ,
365
392
type_alias : hir:: TypeAlias ,
366
393
) {
394
+ if !ctx. check_stability ( Some ( & type_alias. attrs ( ctx. db ) ) ) {
395
+ return ;
396
+ }
367
397
let is_private_editable = match ctx. is_visible ( & type_alias) {
368
398
Visible :: Yes => false ,
369
399
Visible :: Editable => true ,
@@ -380,6 +410,9 @@ impl Completions {
380
410
ctx : & CompletionContext < ' _ > ,
381
411
type_alias : hir:: TypeAlias ,
382
412
) {
413
+ if !ctx. check_stability ( Some ( & type_alias. attrs ( ctx. db ) ) ) {
414
+ return ;
415
+ }
383
416
self . add_opt ( render_type_alias_with_eq ( RenderContext :: new ( ctx) , type_alias) ) ;
384
417
}
385
418
@@ -390,6 +423,9 @@ impl Completions {
390
423
variant : hir:: Variant ,
391
424
path : hir:: ModPath ,
392
425
) {
426
+ if !ctx. check_stability ( Some ( & variant. attrs ( ctx. db ) ) ) {
427
+ return ;
428
+ }
393
429
if let Some ( builder) =
394
430
render_variant_lit ( RenderContext :: new ( ctx) , path_ctx, None , variant, Some ( path) )
395
431
{
@@ -404,6 +440,9 @@ impl Completions {
404
440
variant : hir:: Variant ,
405
441
local_name : Option < hir:: Name > ,
406
442
) {
443
+ if !ctx. check_stability ( Some ( & variant. attrs ( ctx. db ) ) ) {
444
+ return ;
445
+ }
407
446
if let PathCompletionCtx { kind : PathKind :: Pat { pat_ctx } , .. } = path_ctx {
408
447
cov_mark:: hit!( enum_variant_pattern_path) ;
409
448
self . add_variant_pat ( ctx, pat_ctx, Some ( path_ctx) , variant, local_name) ;
@@ -425,6 +464,9 @@ impl Completions {
425
464
field : hir:: Field ,
426
465
ty : & hir:: Type ,
427
466
) {
467
+ if !ctx. check_stability ( Some ( & field. attrs ( ctx. db ) ) ) {
468
+ return ;
469
+ }
428
470
let is_private_editable = match ctx. is_visible ( & field) {
429
471
Visible :: Yes => false ,
430
472
Visible :: Editable => true ,
@@ -448,6 +490,9 @@ impl Completions {
448
490
path : Option < hir:: ModPath > ,
449
491
local_name : Option < hir:: Name > ,
450
492
) {
493
+ if !ctx. check_stability ( Some ( & strukt. attrs ( ctx. db ) ) ) {
494
+ return ;
495
+ }
451
496
if let Some ( builder) =
452
497
render_struct_literal ( RenderContext :: new ( ctx) , path_ctx, strukt, path, local_name)
453
498
{
@@ -462,6 +507,9 @@ impl Completions {
462
507
path : Option < hir:: ModPath > ,
463
508
local_name : Option < hir:: Name > ,
464
509
) {
510
+ if !ctx. check_stability ( Some ( & un. attrs ( ctx. db ) ) ) {
511
+ return ;
512
+ }
465
513
let item = render_union_literal ( RenderContext :: new ( ctx) , un, path, local_name) ;
466
514
self . add_opt ( item) ;
467
515
}
@@ -473,6 +521,8 @@ impl Completions {
473
521
field : usize ,
474
522
ty : & hir:: Type ,
475
523
) {
524
+ // Only used for (unnamed) tuples, whose all fields *are* stable. No need to check
525
+ // stability here.
476
526
let item = render_tuple_field ( RenderContext :: new ( ctx) , receiver, field, ty) ;
477
527
self . add ( item) ;
478
528
}
@@ -494,6 +544,9 @@ impl Completions {
494
544
variant : hir:: Variant ,
495
545
local_name : Option < hir:: Name > ,
496
546
) {
547
+ if !ctx. check_stability ( Some ( & variant. attrs ( ctx. db ) ) ) {
548
+ return ;
549
+ }
497
550
self . add_opt ( render_variant_pat (
498
551
RenderContext :: new ( ctx) ,
499
552
pattern_ctx,
@@ -511,6 +564,9 @@ impl Completions {
511
564
variant : hir:: Variant ,
512
565
path : hir:: ModPath ,
513
566
) {
567
+ if !ctx. check_stability ( Some ( & variant. attrs ( ctx. db ) ) ) {
568
+ return ;
569
+ }
514
570
let path = Some ( & path) ;
515
571
self . add_opt ( render_variant_pat (
516
572
RenderContext :: new ( ctx) ,
@@ -529,6 +585,9 @@ impl Completions {
529
585
strukt : hir:: Struct ,
530
586
local_name : Option < hir:: Name > ,
531
587
) {
588
+ if !ctx. check_stability ( Some ( & strukt. attrs ( ctx. db ) ) ) {
589
+ return ;
590
+ }
532
591
self . add_opt ( render_struct_pat ( RenderContext :: new ( ctx) , pattern_ctx, strukt, local_name) ) ;
533
592
}
534
593
}
0 commit comments