rustc_feature/
unstable.rs

1//! List of the unstable feature gates.
2
3use std::path::PathBuf;
4
5use rustc_data_structures::fx::FxHashSet;
6use rustc_span::{Span, Symbol, sym};
7
8use super::{Feature, to_nonzero};
9
10#[derive(PartialEq)]
11enum FeatureStatus {
12    Default,
13    Incomplete,
14    Internal,
15}
16
17macro_rules! status_to_enum {
18    (unstable) => {
19        FeatureStatus::Default
20    };
21    (incomplete) => {
22        FeatureStatus::Incomplete
23    };
24    (internal) => {
25        FeatureStatus::Internal
26    };
27}
28
29/// A set of features to be used by later passes.
30///
31/// There are two ways to check if a language feature `foo` is enabled:
32/// - Directly with the `foo` method, e.g. `if tcx.features().foo() { ... }`.
33/// - With the `enabled` method, e.g. `if tcx.features.enabled(sym::foo) { ... }`.
34///
35/// The former is preferred. `enabled` should only be used when the feature symbol is not a
36/// constant, e.g. a parameter, or when the feature is a library feature.
37#[derive(Clone, Default, Debug)]
38pub struct Features {
39    /// `#![feature]` attrs for language features, for error reporting.
40    enabled_lang_features: Vec<EnabledLangFeature>,
41    /// `#![feature]` attrs for non-language (library) features.
42    enabled_lib_features: Vec<EnabledLibFeature>,
43    /// `enabled_lang_features` + `enabled_lib_features`.
44    enabled_features: FxHashSet<Symbol>,
45}
46
47/// Information about an enabled language feature.
48#[derive(Debug, Copy, Clone)]
49pub struct EnabledLangFeature {
50    /// Name of the feature gate guarding the language feature.
51    pub gate_name: Symbol,
52    /// Span of the `#[feature(...)]` attribute.
53    pub attr_sp: Span,
54    /// If the lang feature is stable, the version number when it was stabilized.
55    pub stable_since: Option<Symbol>,
56}
57
58/// Information about an enabled library feature.
59#[derive(Debug, Copy, Clone)]
60pub struct EnabledLibFeature {
61    pub gate_name: Symbol,
62    pub attr_sp: Span,
63}
64
65impl Features {
66    /// `since` should be set for stable features that are nevertheless enabled with a `#[feature]`
67    /// attribute, indicating since when they are stable.
68    pub fn set_enabled_lang_feature(&mut self, lang_feat: EnabledLangFeature) {
69        self.enabled_lang_features.push(lang_feat);
70        self.enabled_features.insert(lang_feat.gate_name);
71    }
72
73    pub fn set_enabled_lib_feature(&mut self, lib_feat: EnabledLibFeature) {
74        self.enabled_lib_features.push(lib_feat);
75        self.enabled_features.insert(lib_feat.gate_name);
76    }
77
78    /// Returns a list of [`EnabledLangFeature`] with info about:
79    ///
80    /// - Feature gate name.
81    /// - The span of the `#[feature]` attribute.
82    /// - For stable language features, version info for when it was stabilized.
83    pub fn enabled_lang_features(&self) -> &Vec<EnabledLangFeature> {
84        &self.enabled_lang_features
85    }
86
87    pub fn enabled_lib_features(&self) -> &Vec<EnabledLibFeature> {
88        &self.enabled_lib_features
89    }
90
91    pub fn enabled_features(&self) -> &FxHashSet<Symbol> {
92        &self.enabled_features
93    }
94
95    /// Is the given feature enabled (via `#[feature(...)]`)?
96    pub fn enabled(&self, feature: Symbol) -> bool {
97        self.enabled_features.contains(&feature)
98    }
99}
100
101macro_rules! declare_features {
102    ($(
103        $(#[doc = $doc:tt])* ($status:ident, $feature:ident, $ver:expr, $issue:expr),
104    )+) => {
105        /// Unstable language features that are being implemented or being
106        /// considered for acceptance (stabilization) or removal.
107        pub static UNSTABLE_LANG_FEATURES: &[Feature] = &[
108            $(Feature {
109                name: sym::$feature,
110                since: $ver,
111                issue: to_nonzero($issue),
112            }),+
113        ];
114
115        impl Features {
116            $(
117                pub fn $feature(&self) -> bool {
118                    self.enabled_features.contains(&sym::$feature)
119                }
120            )*
121
122            /// Some features are known to be incomplete and using them is likely to have
123            /// unanticipated results, such as compiler crashes. We warn the user about these
124            /// to alert them.
125            pub fn incomplete(&self, feature: Symbol) -> bool {
126                match feature {
127                    $(
128                        sym::$feature => status_to_enum!($status) == FeatureStatus::Incomplete,
129                    )*
130                    _ if self.enabled_features.contains(&feature) => {
131                        // Accepted/removed features and library features aren't in this file but
132                        // are never incomplete.
133                        false
134                    }
135                    _ => panic!("`{}` was not listed in `declare_features`", feature),
136                }
137            }
138
139            /// Some features are internal to the compiler and standard library and should not
140            /// be used in normal projects. We warn the user about these to alert them.
141            pub fn internal(&self, feature: Symbol) -> bool {
142                match feature {
143                    $(
144                        sym::$feature => status_to_enum!($status) == FeatureStatus::Internal,
145                    )*
146                    _ if self.enabled_features.contains(&feature) => {
147                        // This could be accepted/removed, or a libs feature.
148                        // Accepted/removed features aren't in this file but are never internal
149                        // (a removed feature might have been internal, but that's now irrelevant).
150                        // Libs features are internal if they end in `_internal` or `_internals`.
151                        // As a special exception we also consider `core_intrinsics` internal;
152                        // renaming that age-old feature is just not worth the hassle.
153                        // We just always test the name; it's not a big deal if we accidentally hit
154                        // an accepted/removed lang feature that way.
155                        let name = feature.as_str();
156                        name == "core_intrinsics" || name.ends_with("_internal") || name.ends_with("_internals")
157                    }
158                    _ => panic!("`{}` was not listed in `declare_features`", feature),
159                }
160            }
161        }
162    };
163}
164
165// See https://rustc-dev-guide.rust-lang.org/feature-gates.html#feature-gates for more
166// documentation about handling feature gates.
167//
168// If you change this, please modify `src/doc/unstable-book` as well.
169//
170// Don't ever remove anything from this list; move them to `accepted.rs` if
171// accepted or `removed.rs` if removed.
172//
173// The version numbers here correspond to the version in which the current status
174// was set.
175//
176// Note that the features are grouped into internal/user-facing and then
177// sorted alphabetically inside those groups. This is enforced with tidy.
178//
179// N.B., `tools/tidy/src/features.rs` parses this information directly out of the
180// source, so take care when modifying it.
181
182#[rustfmt::skip]
183declare_features! (
184    // -------------------------------------------------------------------------
185    // feature-group-start: internal feature gates (no tracking issue)
186    // -------------------------------------------------------------------------
187    // no-tracking-issue-start
188
189    /// Allows using the `unadjusted` ABI; perma-unstable.
190    (internal, abi_unadjusted, "1.16.0", None),
191    /// Allows using `#![needs_allocator]`, an implementation detail of `#[global_allocator]`.
192    (internal, allocator_internals, "1.20.0", None),
193    /// Allows using `#[allow_internal_unsafe]`. This is an
194    /// attribute on `macro_rules!` and can't use the attribute handling
195    /// below (it has to be checked before expansion possibly makes
196    /// macros disappear).
197    (internal, allow_internal_unsafe, "1.0.0", None),
198    /// Allows using `#[allow_internal_unstable]`. This is an
199    /// attribute on `macro_rules!` and can't use the attribute handling
200    /// below (it has to be checked before expansion possibly makes
201    /// macros disappear).
202    (internal, allow_internal_unstable, "1.0.0", None),
203    /// Allows using anonymous lifetimes in argument-position impl-trait.
204    (unstable, anonymous_lifetime_in_impl_trait, "1.63.0", None),
205    /// Allows access to the emscripten_wasm_eh config, used by panic_unwind and unwind
206    (internal, cfg_emscripten_wasm_eh, "1.86.0", None),
207    /// Allows identifying the `compiler_builtins` crate.
208    (internal, compiler_builtins, "1.13.0", None),
209    /// Allows writing custom MIR
210    (internal, custom_mir, "1.65.0", None),
211    /// Outputs useful `assert!` messages
212    (unstable, generic_assert, "1.63.0", None),
213    /// Allows using the `rust-intrinsic`'s "ABI".
214    (internal, intrinsics, "1.0.0", None),
215    /// Allows using `#[lang = ".."]` attribute for linking items to special compiler logic.
216    (internal, lang_items, "1.0.0", None),
217    /// Changes `impl Trait` to capture all lifetimes in scope.
218    (unstable, lifetime_capture_rules_2024, "1.76.0", None),
219    /// Allows `#[link(..., cfg(..))]`; perma-unstable per #37406
220    (internal, link_cfg, "1.14.0", None),
221    /// Allows using `?Trait` trait bounds in more contexts.
222    (internal, more_maybe_bounds, "1.82.0", None),
223    /// Allows the `multiple_supertrait_upcastable` lint.
224    (unstable, multiple_supertrait_upcastable, "1.69.0", None),
225    /// Allow negative trait bounds. This is an internal-only feature for testing the trait solver!
226    (internal, negative_bounds, "1.71.0", None),
227    /// Allows using `#[omit_gdb_pretty_printer_section]`.
228    (internal, omit_gdb_pretty_printer_section, "1.5.0", None),
229    /// Set the maximum pattern complexity allowed (not limited by default).
230    (internal, pattern_complexity, "1.78.0", None),
231    /// Allows using pattern types.
232    (internal, pattern_types, "1.79.0", Some(123646)),
233    /// Allows using `#[prelude_import]` on glob `use` items.
234    (internal, prelude_import, "1.2.0", None),
235    /// Used to identify crates that contain the profiler runtime.
236    (internal, profiler_runtime, "1.18.0", None),
237    /// Allows using `rustc_*` attributes (RFC 572).
238    (internal, rustc_attrs, "1.0.0", None),
239    /// Allows using the `#[stable]` and `#[unstable]` attributes.
240    (internal, staged_api, "1.0.0", None),
241    /// Added for testing unstable lints; perma-unstable.
242    (internal, test_unstable_lint, "1.60.0", None),
243    /// Helps with formatting for `group_imports = "StdExternalCrate"`.
244    (unstable, unqualified_local_imports, "1.83.0", None),
245    /// Use for stable + negative coherence and strict coherence depending on trait's
246    /// rustc_strict_coherence value.
247    (unstable, with_negative_coherence, "1.60.0", None),
248    // !!!!    !!!!    !!!!    !!!!   !!!!    !!!!    !!!!    !!!!    !!!!    !!!!    !!!!
249    // Features are listed in alphabetical order. Tidy will fail if you don't keep it this way.
250    // !!!!    !!!!    !!!!    !!!!   !!!!    !!!!    !!!!    !!!!    !!!!    !!!!    !!!!
251
252    // no-tracking-issue-end
253    // -------------------------------------------------------------------------
254    // feature-group-end: internal feature gates (no tracking issue)
255    // -------------------------------------------------------------------------
256
257    // -------------------------------------------------------------------------
258    // feature-group-start: internal feature gates
259    // -------------------------------------------------------------------------
260
261    /// Allows using the `vectorcall` ABI.
262    (unstable, abi_vectorcall, "1.7.0", Some(124485)),
263    /// Allows features specific to auto traits.
264    /// Renamed from `optin_builtin_traits`.
265    (unstable, auto_traits, "1.50.0", Some(13231)),
266    /// Allows using `box` in patterns (RFC 469).
267    (unstable, box_patterns, "1.0.0", Some(29641)),
268    /// Allows builtin # foo() syntax
269    (internal, builtin_syntax, "1.71.0", Some(110680)),
270    /// Allows `#[doc(notable_trait)]`.
271    /// Renamed from `doc_spotlight`.
272    (unstable, doc_notable_trait, "1.52.0", Some(45040)),
273    /// Allows using the `may_dangle` attribute (RFC 1327).
274    (unstable, dropck_eyepatch, "1.10.0", Some(34761)),
275    /// Allows making `dyn Trait` well-formed even if `Trait` is not dyn compatible[^1].
276    /// In that case, `dyn Trait: Trait` does not hold. Moreover, coercions and
277    /// casts in safe Rust to `dyn Trait` for such a `Trait` is also forbidden.
278    ///
279    /// Renamed from `object_safe_for_dispatch`.
280    ///
281    /// [^1]: Formerly known as "object safe".
282    (unstable, dyn_compatible_for_dispatch, "1.83.0", Some(43561)),
283    /// Allows using the `#[fundamental]` attribute.
284    (unstable, fundamental, "1.0.0", Some(29635)),
285    /// Allows using `#[link_name="llvm.*"]`.
286    (internal, link_llvm_intrinsics, "1.0.0", Some(29602)),
287    /// Allows using the `#[linkage = ".."]` attribute.
288    (unstable, linkage, "1.0.0", Some(29603)),
289    /// Allows declaring with `#![needs_panic_runtime]` that a panic runtime is needed.
290    (internal, needs_panic_runtime, "1.10.0", Some(32837)),
291    /// Allows using the `#![panic_runtime]` attribute.
292    (internal, panic_runtime, "1.10.0", Some(32837)),
293    /// Allows using `#[rustc_allow_const_fn_unstable]`.
294    /// This is an attribute on `const fn` for the same
295    /// purpose as `#[allow_internal_unstable]`.
296    (internal, rustc_allow_const_fn_unstable, "1.49.0", Some(69399)),
297    /// Allows using compiler's own crates.
298    (unstable, rustc_private, "1.0.0", Some(27812)),
299    /// Allows using internal rustdoc features like `doc(keyword)`.
300    (internal, rustdoc_internals, "1.58.0", Some(90418)),
301    /// Allows using the `rustdoc::missing_doc_code_examples` lint
302    (unstable, rustdoc_missing_doc_code_examples, "1.31.0", Some(101730)),
303    /// Allows using `#[structural_match]` which indicates that a type is structurally matchable.
304    /// FIXME: Subsumed by trait `StructuralPartialEq`, cannot move to removed until a library
305    /// feature with the same name exists.
306    (unstable, structural_match, "1.8.0", Some(31434)),
307    /// Allows using the `rust-call` ABI.
308    (unstable, unboxed_closures, "1.0.0", Some(29625)),
309    // !!!!    !!!!    !!!!    !!!!   !!!!    !!!!    !!!!    !!!!    !!!!    !!!!    !!!!
310    // Features are listed in alphabetical order. Tidy will fail if you don't keep it this way.
311    // !!!!    !!!!    !!!!    !!!!   !!!!    !!!!    !!!!    !!!!    !!!!    !!!!    !!!!
312
313    // -------------------------------------------------------------------------
314    // feature-group-end: internal feature gates
315    // -------------------------------------------------------------------------
316
317    // -------------------------------------------------------------------------
318    // feature-group-start: actual feature gates (target features)
319    // -------------------------------------------------------------------------
320
321    // FIXME: Document these and merge with the list below.
322
323    // Unstable `#[target_feature]` directives.
324    (unstable, aarch64_unstable_target_feature, "1.82.0", Some(44839)),
325    (unstable, aarch64_ver_target_feature, "1.27.0", Some(44839)),
326    (unstable, arm_target_feature, "1.27.0", Some(44839)),
327    (unstable, avx512_target_feature, "1.27.0", Some(44839)),
328    (unstable, bpf_target_feature, "1.54.0", Some(44839)),
329    (unstable, csky_target_feature, "1.73.0", Some(44839)),
330    (unstable, ermsb_target_feature, "1.49.0", Some(44839)),
331    (unstable, hexagon_target_feature, "1.27.0", Some(44839)),
332    (unstable, lahfsahf_target_feature, "1.78.0", Some(44839)),
333    (unstable, loongarch_target_feature, "1.73.0", Some(44839)),
334    (unstable, m68k_target_feature, "1.85.0", Some(134328)),
335    (unstable, mips_target_feature, "1.27.0", Some(44839)),
336    (unstable, powerpc_target_feature, "1.27.0", Some(44839)),
337    (unstable, prfchw_target_feature, "1.78.0", Some(44839)),
338    (unstable, riscv_target_feature, "1.45.0", Some(44839)),
339    (unstable, rtm_target_feature, "1.35.0", Some(44839)),
340    (unstable, s390x_target_feature, "1.82.0", Some(44839)),
341    (unstable, sparc_target_feature, "1.84.0", Some(132783)),
342    (unstable, sse4a_target_feature, "1.27.0", Some(44839)),
343    (unstable, tbm_target_feature, "1.27.0", Some(44839)),
344    (unstable, wasm_target_feature, "1.30.0", Some(44839)),
345    (unstable, x87_target_feature, "1.85.0", Some(44839)),
346    // !!!!    !!!!    !!!!    !!!!   !!!!    !!!!    !!!!    !!!!    !!!!    !!!!    !!!!
347    // Features are listed in alphabetical order. Tidy will fail if you don't keep it this way.
348    // !!!!    !!!!    !!!!    !!!!   !!!!    !!!!    !!!!    !!!!    !!!!    !!!!    !!!!
349
350    // -------------------------------------------------------------------------
351    // feature-group-end: actual feature gates (target features)
352    // -------------------------------------------------------------------------
353
354    // -------------------------------------------------------------------------
355    // feature-group-start: actual feature gates
356    // -------------------------------------------------------------------------
357
358    /// Allows `extern "avr-interrupt" fn()` and `extern "avr-non-blocking-interrupt" fn()`.
359    (unstable, abi_avr_interrupt, "1.45.0", Some(69664)),
360    /// Allows `extern "C-cmse-nonsecure-call" fn()`.
361    (unstable, abi_c_cmse_nonsecure_call, "1.51.0", Some(81391)),
362    /// Allows `extern "gpu-kernel" fn()`.
363    (unstable, abi_gpu_kernel, "1.86.0", Some(135467)),
364    /// Allows `extern "msp430-interrupt" fn()`.
365    (unstable, abi_msp430_interrupt, "1.16.0", Some(38487)),
366    /// Allows `extern "ptx-*" fn()`.
367    (unstable, abi_ptx, "1.15.0", Some(38788)),
368    /// Allows `extern "riscv-interrupt-m" fn()` and `extern "riscv-interrupt-s" fn()`.
369    (unstable, abi_riscv_interrupt, "1.73.0", Some(111889)),
370    /// Allows `extern "x86-interrupt" fn()`.
371    (unstable, abi_x86_interrupt, "1.17.0", Some(40180)),
372    /// Allows additional const parameter types, such as `[u8; 10]` or user defined types
373    (unstable, adt_const_params, "1.56.0", Some(95174)),
374    /// Allows defining an `#[alloc_error_handler]`.
375    (unstable, alloc_error_handler, "1.29.0", Some(51540)),
376    /// Allows inherent and trait methods with arbitrary self types.
377    (unstable, arbitrary_self_types, "1.23.0", Some(44874)),
378    /// Allows inherent and trait methods with arbitrary self types that are raw pointers.
379    (unstable, arbitrary_self_types_pointers, "1.83.0", Some(44874)),
380    /// Enables experimental inline assembly support for additional architectures.
381    (unstable, asm_experimental_arch, "1.58.0", Some(93335)),
382    /// Enables experimental register support in inline assembly.
383    (unstable, asm_experimental_reg, "1.85.0", Some(133416)),
384    /// Allows using `label` operands in inline assembly.
385    (unstable, asm_goto, "1.78.0", Some(119364)),
386    /// Allows using `label` operands in inline assembly together with output operands.
387    (unstable, asm_goto_with_outputs, "1.85.0", Some(119364)),
388    /// Allows the `may_unwind` option in inline assembly.
389    (unstable, asm_unwind, "1.58.0", Some(93334)),
390    /// Allows users to enforce equality of associated constants `TraitImpl<AssocConst=3>`.
391    (unstable, associated_const_equality, "1.58.0", Some(92827)),
392    /// Allows associated type defaults.
393    (unstable, associated_type_defaults, "1.2.0", Some(29661)),
394    /// Allows async functions to be called from `dyn Trait`.
395    (incomplete, async_fn_in_dyn_trait, "1.85.0", Some(133119)),
396    /// Allows `#[track_caller]` on async functions.
397    (unstable, async_fn_track_caller, "1.73.0", Some(110011)),
398    /// Allows `for await` loops.
399    (unstable, async_for_loop, "1.77.0", Some(118898)),
400    /// Allows `async` trait bound modifier.
401    (unstable, async_trait_bounds, "1.85.0", Some(62290)),
402    /// Allows using C-variadics.
403    (unstable, c_variadic, "1.34.0", Some(44930)),
404    /// Allows the use of `#[cfg(<true/false>)]`.
405    (unstable, cfg_boolean_literals, "1.83.0", Some(131204)),
406    /// Allows the use of `#[cfg(contract_checks)` to check if contract checks are enabled.
407    (unstable, cfg_contract_checks, "1.86.0", Some(128044)),
408    /// Allows the use of `#[cfg(overflow_checks)` to check if integer overflow behaviour.
409    (unstable, cfg_overflow_checks, "1.71.0", Some(111466)),
410    /// Provides the relocation model information as cfg entry
411    (unstable, cfg_relocation_model, "1.73.0", Some(114929)),
412    /// Allows the use of `#[cfg(sanitize = "option")]`; set when -Zsanitizer is used.
413    (unstable, cfg_sanitize, "1.41.0", Some(39699)),
414    /// Allows `cfg(sanitizer_cfi_generalize_pointers)` and `cfg(sanitizer_cfi_normalize_integers)`.
415    (unstable, cfg_sanitizer_cfi, "1.77.0", Some(89653)),
416    /// Allows `cfg(target(abi = "..."))`.
417    (unstable, cfg_target_compact, "1.63.0", Some(96901)),
418    /// Allows `cfg(target_has_atomic_load_store = "...")`.
419    (unstable, cfg_target_has_atomic, "1.60.0", Some(94039)),
420    /// Allows `cfg(target_has_atomic_equal_alignment = "...")`.
421    (unstable, cfg_target_has_atomic_equal_alignment, "1.60.0", Some(93822)),
422    /// Allows `cfg(target_thread_local)`.
423    (unstable, cfg_target_thread_local, "1.7.0", Some(29594)),
424    /// Allows the use of `#[cfg(ub_checks)` to check if UB checks are enabled.
425    (unstable, cfg_ub_checks, "1.79.0", Some(123499)),
426    /// Allow conditional compilation depending on rust version
427    (unstable, cfg_version, "1.45.0", Some(64796)),
428    /// Allows to use the `#[cfi_encoding = ""]` attribute.
429    (unstable, cfi_encoding, "1.71.0", Some(89653)),
430    /// Allows `for<...>` on closures and coroutines.
431    (unstable, closure_lifetime_binder, "1.64.0", Some(97362)),
432    /// Allows `#[track_caller]` on closures and coroutines.
433    (unstable, closure_track_caller, "1.57.0", Some(87417)),
434    /// Allows `extern "C-cmse-nonsecure-entry" fn()`.
435    (unstable, cmse_nonsecure_entry, "1.48.0", Some(75835)),
436    /// Allows `async {}` expressions in const contexts.
437    (unstable, const_async_blocks, "1.53.0", Some(85368)),
438    /// Allows `const || {}` closures in const contexts.
439    (incomplete, const_closures, "1.68.0", Some(106003)),
440    /// Allows using `~const Destruct` bounds and calling drop impls in const contexts.
441    (unstable, const_destruct, "1.85.0", Some(133214)),
442    /// Allows `for _ in _` loops in const contexts.
443    (unstable, const_for, "1.56.0", Some(87575)),
444    /// Be more precise when looking for live drops in a const context.
445    (unstable, const_precise_live_drops, "1.46.0", Some(73255)),
446    /// Allows `impl const Trait for T` syntax.
447    (unstable, const_trait_impl, "1.42.0", Some(67792)),
448    /// Allows the `?` operator in const contexts.
449    (unstable, const_try, "1.56.0", Some(74935)),
450    /// Allows use of contracts attributes.
451    (incomplete, contracts, "1.86.0", Some(128044)),
452    /// Allows access to internal machinery used to implement contracts.
453    (internal, contracts_internals, "1.86.0", Some(128044)),
454    /// Allows coroutines to be cloned.
455    (unstable, coroutine_clone, "1.65.0", Some(95360)),
456    /// Allows defining coroutines.
457    (unstable, coroutines, "1.21.0", Some(43122)),
458    /// Allows function attribute `#[coverage(on/off)]`, to control coverage
459    /// instrumentation of that function.
460    (unstable, coverage_attribute, "1.74.0", Some(84605)),
461    /// Allows non-builtin attributes in inner attribute position.
462    (unstable, custom_inner_attributes, "1.30.0", Some(54726)),
463    /// Allows custom test frameworks with `#![test_runner]` and `#[test_case]`.
464    (unstable, custom_test_frameworks, "1.30.0", Some(50297)),
465    /// Allows declarative macros 2.0 (`macro`).
466    (unstable, decl_macro, "1.17.0", Some(39412)),
467    /// Allows the use of default values on struct definitions and the construction of struct
468    /// literals with the functional update syntax without a base.
469    (unstable, default_field_values, "1.85.0", Some(132162)),
470    /// Allows using `#[deprecated_safe]` to deprecate the safeness of a function or trait
471    (unstable, deprecated_safe, "1.61.0", Some(94978)),
472    /// Allows having using `suggestion` in the `#[deprecated]` attribute.
473    (unstable, deprecated_suggestion, "1.61.0", Some(94785)),
474    /// Allows deref patterns.
475    (incomplete, deref_patterns, "1.79.0", Some(87121)),
476    /// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.
477    (unstable, doc_auto_cfg, "1.58.0", Some(43781)),
478    /// Allows `#[doc(cfg(...))]`.
479    (unstable, doc_cfg, "1.21.0", Some(43781)),
480    /// Allows `#[doc(cfg_hide(...))]`.
481    (unstable, doc_cfg_hide, "1.57.0", Some(43781)),
482    /// Allows `#[doc(masked)]`.
483    (unstable, doc_masked, "1.21.0", Some(44027)),
484    /// Allows `dyn* Trait` objects.
485    (incomplete, dyn_star, "1.65.0", Some(102425)),
486    /// Allows exhaustive pattern matching on types that contain uninhabited types.
487    (unstable, exhaustive_patterns, "1.13.0", Some(51085)),
488    /// Allows explicit tail calls via `become` expression.
489    (incomplete, explicit_tail_calls, "1.72.0", Some(112788)),
490    /// Allows using `aapcs`, `efiapi`, `sysv64` and `win64` as calling conventions
491    /// for functions with varargs.
492    (unstable, extended_varargs_abi_support, "1.65.0", Some(100189)),
493    /// Allows using `system` as a calling convention with varargs.
494    (unstable, extern_system_varargs, "1.86.0", Some(136946)),
495    /// Allows defining `extern type`s.
496    (unstable, extern_types, "1.23.0", Some(43467)),
497    /// Allow using 128-bit (quad precision) floating point numbers.
498    (unstable, f128, "1.78.0", Some(116909)),
499    /// Allow using 16-bit (half precision) floating point numbers.
500    (unstable, f16, "1.78.0", Some(116909)),
501    /// Allows the use of `#[ffi_const]` on foreign functions.
502    (unstable, ffi_const, "1.45.0", Some(58328)),
503    /// Allows the use of `#[ffi_pure]` on foreign functions.
504    (unstable, ffi_pure, "1.45.0", Some(58329)),
505    /// Controlling the behavior of fmt::Debug
506    (unstable, fmt_debug, "1.82.0", Some(129709)),
507    /// Allows using `#[repr(align(...))]` on function items
508    (unstable, fn_align, "1.53.0", Some(82232)),
509    /// Support delegating implementation of functions to other already implemented functions.
510    (incomplete, fn_delegation, "1.76.0", Some(118212)),
511    /// Allows impls for the Freeze trait.
512    (internal, freeze_impls, "1.78.0", Some(121675)),
513    /// Allows defining gen blocks and `gen fn`.
514    (unstable, gen_blocks, "1.75.0", Some(117078)),
515    /// Infer generic args for both consts and types.
516    (unstable, generic_arg_infer, "1.55.0", Some(85077)),
517    /// Allows non-trivial generic constants which have to have wfness manually propagated to callers
518    (incomplete, generic_const_exprs, "1.56.0", Some(76560)),
519    /// Allows generic parameters and where-clauses on free & associated const items.
520    (incomplete, generic_const_items, "1.73.0", Some(113521)),
521    /// Allows any generic constants being used as pattern type range ends
522    (incomplete, generic_pattern_types, "1.86.0", Some(136574)),
523    /// Allows registering static items globally, possibly across crates, to iterate over at runtime.
524    (unstable, global_registration, "1.80.0", Some(125119)),
525    /// Allows using guards in patterns.
526    (incomplete, guard_patterns, "1.85.0", Some(129967)),
527    /// Allows using `..=X` as a patterns in slices.
528    (unstable, half_open_range_patterns_in_slices, "1.66.0", Some(67264)),
529    /// Allows `if let` guard in match arms.
530    (unstable, if_let_guard, "1.47.0", Some(51114)),
531    /// Allows `impl Trait` to be used inside associated types (RFC 2515).
532    (unstable, impl_trait_in_assoc_type, "1.70.0", Some(63063)),
533    /// Allows `impl Trait` in bindings (`let`).
534    (unstable, impl_trait_in_bindings, "1.64.0", Some(63065)),
535    /// Allows `impl Trait` as output type in `Fn` traits in return position of functions.
536    (unstable, impl_trait_in_fn_trait_return, "1.64.0", Some(99697)),
537    /// Allows `use` associated functions from traits.
538    (unstable, import_trait_associated_functions, "1.86.0", Some(134691)),
539    /// Allows associated types in inherent impls.
540    (incomplete, inherent_associated_types, "1.52.0", Some(8995)),
541    /// Allow anonymous constants from an inline `const` block in pattern position
542    (unstable, inline_const_pat, "1.58.0", Some(76001)),
543    /// Allows using `pointer` and `reference` in intra-doc links
544    (unstable, intra_doc_pointers, "1.51.0", Some(80896)),
545    // Allows using the `kl` and `widekl` target features and the associated intrinsics
546    (unstable, keylocker_x86, "1.86.0", Some(134813)),
547    // Allows setting the threshold for the `large_assignments` lint.
548    (unstable, large_assignments, "1.52.0", Some(83518)),
549    /// Allow to have type alias types for inter-crate use.
550    (incomplete, lazy_type_alias, "1.72.0", Some(112792)),
551    /// Allows `if/while p && let q = r && ...` chains.
552    (unstable, let_chains, "1.37.0", Some(53667)),
553    /// Allows using `#[link(kind = "link-arg", name = "...")]`
554    /// to pass custom arguments to the linker.
555    (unstable, link_arg_attribute, "1.76.0", Some(99427)),
556    /// Give access to additional metadata about declarative macro meta-variables.
557    (unstable, macro_metavar_expr, "1.61.0", Some(83527)),
558    /// Provides a way to concatenate identifiers using metavariable expressions.
559    (unstable, macro_metavar_expr_concat, "1.81.0", Some(124225)),
560    /// Allows `#[marker]` on certain traits allowing overlapping implementations.
561    (unstable, marker_trait_attr, "1.30.0", Some(29864)),
562    /// Enables the generic const args MVP (only bare paths, not arbitrary computation).
563    (incomplete, min_generic_const_args, "1.84.0", Some(132980)),
564    /// A minimal, sound subset of specialization intended to be used by the
565    /// standard library until the soundness issues with specialization
566    /// are fixed.
567    (unstable, min_specialization, "1.7.0", Some(31844)),
568    /// Allows qualified paths in struct expressions, struct patterns and tuple struct patterns.
569    (unstable, more_qualified_paths, "1.54.0", Some(86935)),
570    /// Allows the `#[must_not_suspend]` attribute.
571    (unstable, must_not_suspend, "1.57.0", Some(83310)),
572    /// Allows `mut ref` and `mut ref mut` identifier patterns.
573    (incomplete, mut_ref, "1.79.0", Some(123076)),
574    /// Allows using `#[naked]` on functions.
575    (unstable, naked_functions, "1.9.0", Some(90957)),
576    /// Allows specifying the as-needed link modifier
577    (unstable, native_link_modifiers_as_needed, "1.53.0", Some(81490)),
578    /// Allow negative trait implementations.
579    (unstable, negative_impls, "1.44.0", Some(68318)),
580    /// Allows the `!` pattern.
581    (incomplete, never_patterns, "1.76.0", Some(118155)),
582    /// Allows the `!` type. Does not imply 'exhaustive_patterns' (below) any more.
583    (unstable, never_type, "1.13.0", Some(35121)),
584    /// Allows diverging expressions to fall back to `!` rather than `()`.
585    (unstable, never_type_fallback, "1.41.0", Some(65992)),
586    /// Switch `..` syntax to use the new (`Copy + IntoIterator`) range types.
587    (unstable, new_range, "1.86.0", Some(123741)),
588    /// Allows `#![no_core]`.
589    (unstable, no_core, "1.3.0", Some(29639)),
590    /// Allows the use of `no_sanitize` attribute.
591    (unstable, no_sanitize, "1.42.0", Some(39699)),
592    /// Allows using the `non_exhaustive_omitted_patterns` lint.
593    (unstable, non_exhaustive_omitted_patterns_lint, "1.57.0", Some(89554)),
594    /// Allows `for<T>` binders in where-clauses
595    (incomplete, non_lifetime_binders, "1.69.0", Some(108185)),
596    /// Allows using enums in offset_of!
597    (unstable, offset_of_enum, "1.75.0", Some(120141)),
598    /// Allows using fields with slice type in offset_of!
599    (unstable, offset_of_slice, "1.81.0", Some(126151)),
600    /// Allows using `#[optimize(X)]`.
601    (unstable, optimize_attribute, "1.34.0", Some(54882)),
602    /// Allows specifying nop padding on functions for dynamic patching.
603    (unstable, patchable_function_entry, "1.81.0", Some(123115)),
604    /// Experimental features that make `Pin` more ergonomic.
605    (incomplete, pin_ergonomics, "1.83.0", Some(130494)),
606    /// Allows postfix match `expr.match { ... }`
607    (unstable, postfix_match, "1.79.0", Some(121618)),
608    /// Allows `use<..>` precise capturign on impl Trait in traits.
609    (unstable, precise_capturing_in_traits, "1.83.0", Some(130044)),
610    /// Allows macro attributes on expressions, statements and non-inline modules.
611    (unstable, proc_macro_hygiene, "1.30.0", Some(54727)),
612    /// Makes `&` and `&mut` patterns eat only one layer of references in Rust 2024.
613    (incomplete, ref_pat_eat_one_layer_2024, "1.79.0", Some(123076)),
614    /// Makes `&` and `&mut` patterns eat only one layer of references in Rust 2024—structural variant
615    (incomplete, ref_pat_eat_one_layer_2024_structural, "1.81.0", Some(123076)),
616    /// Allows using the `#[register_tool]` attribute.
617    (unstable, register_tool, "1.41.0", Some(66079)),
618    /// Allows the `#[repr(i128)]` attribute for enums.
619    (incomplete, repr128, "1.16.0", Some(56071)),
620    /// Allows `repr(simd)` and importing the various simd intrinsics.
621    (unstable, repr_simd, "1.4.0", Some(27731)),
622    /// Allows bounding the return type of AFIT/RPITIT.
623    (unstable, return_type_notation, "1.70.0", Some(109417)),
624    /// Allows `extern "rust-cold"`.
625    (unstable, rust_cold_cc, "1.63.0", Some(97544)),
626    /// Allows use of x86 SHA512, SM3 and SM4 target-features and intrinsics
627    (unstable, sha512_sm_x86, "1.82.0", Some(126624)),
628    /// Allows the use of SIMD types in functions declared in `extern` blocks.
629    (unstable, simd_ffi, "1.0.0", Some(27731)),
630    /// Allows specialization of implementations (RFC 1210).
631    (incomplete, specialization, "1.7.0", Some(31844)),
632    /// Allows attributes on expressions and non-item statements.
633    (unstable, stmt_expr_attributes, "1.6.0", Some(15701)),
634    /// Allows lints part of the strict provenance effort.
635    (unstable, strict_provenance_lints, "1.61.0", Some(130351)),
636    /// Allows string patterns to dereference values to match them.
637    (unstable, string_deref_patterns, "1.67.0", Some(87121)),
638    /// Allows subtrait items to shadow supertrait items.
639    (unstable, supertrait_item_shadowing, "1.86.0", Some(89151)),
640    /// Allows using `#[thread_local]` on `static` items.
641    (unstable, thread_local, "1.0.0", Some(29594)),
642    /// Allows defining `trait X = A + B;` alias items.
643    (unstable, trait_alias, "1.24.0", Some(41517)),
644    /// Allows for transmuting between arrays with sizes that contain generic consts.
645    (unstable, transmute_generic_consts, "1.70.0", Some(109929)),
646    /// Allows #[repr(transparent)] on unions (RFC 2645).
647    (unstable, transparent_unions, "1.37.0", Some(60405)),
648    /// Allows inconsistent bounds in where clauses.
649    (unstable, trivial_bounds, "1.28.0", Some(48214)),
650    /// Allows using `try {...}` expressions.
651    (unstable, try_blocks, "1.29.0", Some(31436)),
652    /// Allows `impl Trait` to be used inside type aliases (RFC 2515).
653    (unstable, type_alias_impl_trait, "1.38.0", Some(63063)),
654    /// Allows creation of instances of a struct by moving fields that have
655    /// not changed from prior instances of the same struct (RFC #2528)
656    (unstable, type_changing_struct_update, "1.58.0", Some(86555)),
657    /// Allows using `unsafe<'a> &'a T` unsafe binder types.
658    (incomplete, unsafe_binders, "1.85.0", Some(130516)),
659    /// Allows declaring fields `unsafe`.
660    (incomplete, unsafe_fields, "1.85.0", Some(132922)),
661    /// Allows const generic parameters to be defined with types that
662    /// are not `Sized`, e.g. `fn foo<const N: [u8]>() {`.
663    (incomplete, unsized_const_params, "1.82.0", Some(95174)),
664    /// Allows unsized fn parameters.
665    (internal, unsized_fn_params, "1.49.0", Some(48055)),
666    /// Allows unsized rvalues at arguments and parameters.
667    (incomplete, unsized_locals, "1.30.0", Some(48055)),
668    /// Allows unsized tuple coercion.
669    (unstable, unsized_tuple_coercion, "1.20.0", Some(42877)),
670    /// Allows using the `#[used(linker)]` (or `#[used(compiler)]`) attribute.
671    (unstable, used_with_arg, "1.60.0", Some(93798)),
672    /// Allows use of x86 `AMX` target-feature attributes and intrinsics
673    (unstable, x86_amx_intrinsics, "1.81.0", Some(126622)),
674    /// Allows use of the `xop` target-feature
675    (unstable, xop_target_feature, "1.81.0", Some(127208)),
676    /// Allows `do yeet` expressions
677    (unstable, yeet_expr, "1.62.0", Some(96373)),
678    // !!!!    !!!!    !!!!    !!!!   !!!!    !!!!    !!!!    !!!!    !!!!    !!!!    !!!!
679    // Features are listed in alphabetical order. Tidy will fail if you don't keep it this way.
680    // !!!!    !!!!    !!!!    !!!!   !!!!    !!!!    !!!!    !!!!    !!!!    !!!!    !!!!
681
682    // -------------------------------------------------------------------------
683    // feature-group-end: actual feature gates
684    // -------------------------------------------------------------------------
685);
686
687impl Features {
688    pub fn dump_feature_usage_metrics(
689        &self,
690        metrics_path: PathBuf,
691    ) -> Result<(), Box<dyn std::error::Error>> {
692        #[derive(serde::Serialize)]
693        struct LibFeature {
694            symbol: String,
695        }
696
697        #[derive(serde::Serialize)]
698        struct LangFeature {
699            symbol: String,
700            since: Option<String>,
701        }
702
703        #[derive(serde::Serialize)]
704        struct FeatureUsage {
705            lib_features: Vec<LibFeature>,
706            lang_features: Vec<LangFeature>,
707        }
708
709        let metrics_file = std::fs::File::create(metrics_path)?;
710        let metrics_file = std::io::BufWriter::new(metrics_file);
711
712        let lib_features = self
713            .enabled_lib_features
714            .iter()
715            .map(|EnabledLibFeature { gate_name, .. }| LibFeature { symbol: gate_name.to_string() })
716            .collect();
717
718        let lang_features = self
719            .enabled_lang_features
720            .iter()
721            .map(|EnabledLangFeature { gate_name, stable_since, .. }| LangFeature {
722                symbol: gate_name.to_string(),
723                since: stable_since.map(|since| since.to_string()),
724            })
725            .collect();
726
727        let feature_usage = FeatureUsage { lib_features, lang_features };
728
729        serde_json::to_writer(metrics_file, &feature_usage)?;
730
731        Ok(())
732    }
733}
734
735/// Some features are not allowed to be used together at the same time, if
736/// the two are present, produce an error.
737pub const INCOMPATIBLE_FEATURES: &[(Symbol, Symbol)] = &[
738    // Experimental match ergonomics rulesets are incompatible with each other, to simplify the
739    // boolean logic required to tell which typing rules to use.
740    (sym::ref_pat_eat_one_layer_2024, sym::ref_pat_eat_one_layer_2024_structural),
741];