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