@@ -4,12 +4,12 @@ mod analysis;
44#[ cfg( test) ]
55mod tests;
66
7- use std:: iter;
7+ use std:: { iter, sync :: LazyLock } ;
88
99use base_db:: toolchain_channel;
1010use hir:: {
1111 DisplayTarget , HasAttrs , InFile , Local , ModuleDef , ModuleSource , Name , PathResolution ,
12- ScopeDef , Semantics , SemanticsScope , Symbol , Type , TypeInfo ,
12+ ScopeDef , Semantics , SemanticsScope , Symbol , Type , TypeInfo , sym ,
1313} ;
1414use ide_db:: {
1515 FilePosition , FxHashMap , FxHashSet , RootDatabase , famous_defs:: FamousDefs ,
@@ -601,7 +601,18 @@ impl CompletionContext<'_> {
601601 let Some ( attrs) = attrs else {
602602 return true ;
603603 } ;
604- !attrs. is_unstable ( ) || self . is_nightly
604+ if !attrs. is_unstable ( ) {
605+ return true ;
606+ }
607+ if !self . is_nightly {
608+ return false ;
609+ }
610+ // Unstable on nightly, but we still don't want to suggest internal features, unless the feature flag is enabled.
611+ let Some ( unstable_feature) = attrs. unstable_feature ( self . db ) else {
612+ return true ;
613+ } ;
614+ !INTERNAL_FEATURES . contains ( & unstable_feature)
615+ || self . krate . is_unstable_feature_enabled ( self . db , & unstable_feature)
605616 }
606617
607618 pub ( crate ) fn check_stability_and_hidden < I > ( & self , item : I ) -> bool
@@ -924,3 +935,40 @@ const OP_TRAIT_LANG: &[hir::LangItem] = &[
924935 hir:: LangItem :: Shr ,
925936 hir:: LangItem :: Sub ,
926937] ;
938+
939+ // FIXME: Find a way to keep this up to date somehow?
940+ const INTERNAL_FEATURES_LIST : & [ Symbol ] = & [
941+ sym:: abi_unadjusted,
942+ sym:: allocator_internals,
943+ sym:: allow_internal_unsafe,
944+ sym:: allow_internal_unstable,
945+ sym:: cfg_emscripten_wasm_eh,
946+ sym:: cfg_target_has_reliable_f16_f128,
947+ sym:: compiler_builtins,
948+ sym:: custom_mir,
949+ sym:: eii_internals,
950+ sym:: field_representing_type_raw,
951+ sym:: intrinsics,
952+ sym:: lang_items,
953+ sym:: link_cfg,
954+ sym:: more_maybe_bounds,
955+ sym:: negative_bounds,
956+ sym:: pattern_complexity_limit,
957+ sym:: prelude_import,
958+ sym:: profiler_runtime,
959+ sym:: rustc_attrs,
960+ sym:: staged_api,
961+ sym:: test_unstable_lint,
962+ sym:: builtin_syntax,
963+ sym:: link_llvm_intrinsics,
964+ sym:: needs_panic_runtime,
965+ sym:: panic_runtime,
966+ sym:: pattern_types,
967+ sym:: rustdoc_internals,
968+ sym:: contracts_internals,
969+ sym:: freeze_impls,
970+ sym:: unsized_fn_params,
971+ ] ;
972+
973+ static INTERNAL_FEATURES : LazyLock < FxHashSet < Symbol > > =
974+ LazyLock :: new ( || INTERNAL_FEATURES_LIST . iter ( ) . cloned ( ) . collect ( ) ) ;
0 commit comments