rustc_feature/
unstable.rs

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