@@ -23,7 +23,7 @@ pub(crate) mod env_vars;
2323
2424use std:: iter;
2525
26- use hir:: { known, ScopeDef , Variant } ;
26+ use hir:: { known, HasAttrs , ScopeDef , Variant } ;
2727use ide_db:: { imports:: import_assets:: LocatedImport , SymbolKind } ;
2828use syntax:: ast;
2929
@@ -181,6 +181,9 @@ impl Completions {
181181 resolution : hir:: ScopeDef ,
182182 doc_aliases : Vec < syntax:: SmolStr > ,
183183 ) {
184+ if !ctx. check_stability ( resolution. attrs ( ctx. db ) . as_deref ( ) ) {
185+ return ;
186+ }
184187 let is_private_editable = match ctx. def_is_visible ( & resolution) {
185188 Visible :: Yes => false ,
186189 Visible :: Editable => true ,
@@ -206,6 +209,9 @@ impl Completions {
206209 local_name : hir:: Name ,
207210 resolution : hir:: ScopeDef ,
208211 ) {
212+ if !ctx. check_stability ( resolution. attrs ( ctx. db ) . as_deref ( ) ) {
213+ return ;
214+ }
209215 let is_private_editable = match ctx. def_is_visible ( & resolution) {
210216 Visible :: Yes => false ,
211217 Visible :: Editable => true ,
@@ -228,6 +234,9 @@ impl Completions {
228234 path_ctx : & PathCompletionCtx ,
229235 e : hir:: Enum ,
230236 ) {
237+ if !ctx. check_stability ( Some ( & e. attrs ( ctx. db ) ) ) {
238+ return ;
239+ }
231240 e. variants ( ctx. db )
232241 . into_iter ( )
233242 . for_each ( |variant| self . add_enum_variant ( ctx, path_ctx, variant, None ) ) ;
@@ -241,6 +250,9 @@ impl Completions {
241250 local_name : hir:: Name ,
242251 doc_aliases : Vec < syntax:: SmolStr > ,
243252 ) {
253+ if !ctx. check_stability ( Some ( & module. attrs ( ctx. db ) ) ) {
254+ return ;
255+ }
244256 self . add_path_resolution (
245257 ctx,
246258 path_ctx,
@@ -257,6 +269,9 @@ impl Completions {
257269 mac : hir:: Macro ,
258270 local_name : hir:: Name ,
259271 ) {
272+ if !ctx. check_stability ( Some ( & mac. attrs ( ctx. db ) ) ) {
273+ return ;
274+ }
260275 let is_private_editable = match ctx. is_visible ( & mac) {
261276 Visible :: Yes => false ,
262277 Visible :: Editable => true ,
@@ -280,6 +295,9 @@ impl Completions {
280295 func : hir:: Function ,
281296 local_name : Option < hir:: Name > ,
282297 ) {
298+ if !ctx. check_stability ( Some ( & func. attrs ( ctx. db ) ) ) {
299+ return ;
300+ }
283301 let is_private_editable = match ctx. is_visible ( & func) {
284302 Visible :: Yes => false ,
285303 Visible :: Editable => true ,
@@ -304,6 +322,9 @@ impl Completions {
304322 receiver : Option < hir:: Name > ,
305323 local_name : Option < hir:: Name > ,
306324 ) {
325+ if !ctx. check_stability ( Some ( & func. attrs ( ctx. db ) ) ) {
326+ return ;
327+ }
307328 let is_private_editable = match ctx. is_visible ( & func) {
308329 Visible :: Yes => false ,
309330 Visible :: Editable => true ,
@@ -328,6 +349,9 @@ impl Completions {
328349 func : hir:: Function ,
329350 import : LocatedImport ,
330351 ) {
352+ if !ctx. check_stability ( Some ( & func. attrs ( ctx. db ) ) ) {
353+ return ;
354+ }
331355 let is_private_editable = match ctx. is_visible ( & func) {
332356 Visible :: Yes => false ,
333357 Visible :: Editable => true ,
@@ -348,6 +372,9 @@ impl Completions {
348372 }
349373
350374 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+ }
351378 let is_private_editable = match ctx. is_visible ( & konst) {
352379 Visible :: Yes => false ,
353380 Visible :: Editable => true ,
@@ -364,6 +391,9 @@ impl Completions {
364391 ctx : & CompletionContext < ' _ > ,
365392 type_alias : hir:: TypeAlias ,
366393 ) {
394+ if !ctx. check_stability ( Some ( & type_alias. attrs ( ctx. db ) ) ) {
395+ return ;
396+ }
367397 let is_private_editable = match ctx. is_visible ( & type_alias) {
368398 Visible :: Yes => false ,
369399 Visible :: Editable => true ,
@@ -380,6 +410,9 @@ impl Completions {
380410 ctx : & CompletionContext < ' _ > ,
381411 type_alias : hir:: TypeAlias ,
382412 ) {
413+ if !ctx. check_stability ( Some ( & type_alias. attrs ( ctx. db ) ) ) {
414+ return ;
415+ }
383416 self . add_opt ( render_type_alias_with_eq ( RenderContext :: new ( ctx) , type_alias) ) ;
384417 }
385418
@@ -390,6 +423,9 @@ impl Completions {
390423 variant : hir:: Variant ,
391424 path : hir:: ModPath ,
392425 ) {
426+ if !ctx. check_stability ( Some ( & variant. attrs ( ctx. db ) ) ) {
427+ return ;
428+ }
393429 if let Some ( builder) =
394430 render_variant_lit ( RenderContext :: new ( ctx) , path_ctx, None , variant, Some ( path) )
395431 {
@@ -404,6 +440,9 @@ impl Completions {
404440 variant : hir:: Variant ,
405441 local_name : Option < hir:: Name > ,
406442 ) {
443+ if !ctx. check_stability ( Some ( & variant. attrs ( ctx. db ) ) ) {
444+ return ;
445+ }
407446 if let PathCompletionCtx { kind : PathKind :: Pat { pat_ctx } , .. } = path_ctx {
408447 cov_mark:: hit!( enum_variant_pattern_path) ;
409448 self . add_variant_pat ( ctx, pat_ctx, Some ( path_ctx) , variant, local_name) ;
@@ -425,6 +464,9 @@ impl Completions {
425464 field : hir:: Field ,
426465 ty : & hir:: Type ,
427466 ) {
467+ if !ctx. check_stability ( Some ( & field. attrs ( ctx. db ) ) ) {
468+ return ;
469+ }
428470 let is_private_editable = match ctx. is_visible ( & field) {
429471 Visible :: Yes => false ,
430472 Visible :: Editable => true ,
@@ -448,6 +490,9 @@ impl Completions {
448490 path : Option < hir:: ModPath > ,
449491 local_name : Option < hir:: Name > ,
450492 ) {
493+ if !ctx. check_stability ( Some ( & strukt. attrs ( ctx. db ) ) ) {
494+ return ;
495+ }
451496 if let Some ( builder) =
452497 render_struct_literal ( RenderContext :: new ( ctx) , path_ctx, strukt, path, local_name)
453498 {
@@ -462,6 +507,9 @@ impl Completions {
462507 path : Option < hir:: ModPath > ,
463508 local_name : Option < hir:: Name > ,
464509 ) {
510+ if !ctx. check_stability ( Some ( & un. attrs ( ctx. db ) ) ) {
511+ return ;
512+ }
465513 let item = render_union_literal ( RenderContext :: new ( ctx) , un, path, local_name) ;
466514 self . add_opt ( item) ;
467515 }
@@ -473,6 +521,8 @@ impl Completions {
473521 field : usize ,
474522 ty : & hir:: Type ,
475523 ) {
524+ // Only used for (unnamed) tuples, whose all fields *are* stable. No need to check
525+ // stability here.
476526 let item = render_tuple_field ( RenderContext :: new ( ctx) , receiver, field, ty) ;
477527 self . add ( item) ;
478528 }
@@ -494,6 +544,9 @@ impl Completions {
494544 variant : hir:: Variant ,
495545 local_name : Option < hir:: Name > ,
496546 ) {
547+ if !ctx. check_stability ( Some ( & variant. attrs ( ctx. db ) ) ) {
548+ return ;
549+ }
497550 self . add_opt ( render_variant_pat (
498551 RenderContext :: new ( ctx) ,
499552 pattern_ctx,
@@ -511,6 +564,9 @@ impl Completions {
511564 variant : hir:: Variant ,
512565 path : hir:: ModPath ,
513566 ) {
567+ if !ctx. check_stability ( Some ( & variant. attrs ( ctx. db ) ) ) {
568+ return ;
569+ }
514570 let path = Some ( & path) ;
515571 self . add_opt ( render_variant_pat (
516572 RenderContext :: new ( ctx) ,
@@ -529,6 +585,9 @@ impl Completions {
529585 strukt : hir:: Struct ,
530586 local_name : Option < hir:: Name > ,
531587 ) {
588+ if !ctx. check_stability ( Some ( & strukt. attrs ( ctx. db ) ) ) {
589+ return ;
590+ }
532591 self . add_opt ( render_struct_pat ( RenderContext :: new ( ctx) , pattern_ctx, strukt, local_name) ) ;
533592 }
534593}
0 commit comments