use super::{Feature, State};
use rustc_span::edition::Edition;
use rustc_span::symbol::{sym, Symbol};
use rustc_span::Span;
macro_rules! set {
($field: ident) => {{
fn f(features: &mut Features, _: Span) {
features.$field = true;
}
f as fn(&mut Features, Span)
}};
}
macro_rules! declare_features {
($(
$(#[doc = $doc:tt])* (active, $feature:ident, $ver:expr, $issue:expr, $edition:expr),
)+) => {
pub const ACTIVE_FEATURES:
&[Feature] =
&[$(
// (sym::$feature, $ver, $issue, $edition, set!($feature))
Feature {
state: State::Active { set: set!($feature) },
name: sym::$feature,
since: $ver,
issue: $issue,
edition: $edition,
description: concat!($($doc,)*),
}
),+];
#[derive(Clone, Default)]
pub struct Features {
pub declared_lang_features: Vec<(Symbol, Span, Option<Symbol>)>,
pub declared_lib_features: Vec<(Symbol, Span)>,
$(
$(#[doc = $doc])*
pub $feature: bool
),+
}
impl Features {
pub fn walk_feature_fields(&self, mut f: impl FnMut(&str, bool)) {
$(f(stringify!($feature), self.$feature);)+
}
pub fn enabled(&self, feature: Symbol) -> bool {
match feature {
$( sym::$feature => self.$feature, )*
_ => panic!("`{}` was not listed in `declare_features`", feature),
}
}
}
};
}
impl Feature {
pub fn set(&self, features: &mut Features, span: Span) {
match self.state {
State::Active { set } => set(features, span),
_ => panic!("called `set` on feature `{}` which is not `active`", self.name),
}
}
}
#[rustfmt::skip]
declare_features! (
(active, rustc_attrs, "1.0.0", None, None),
(active, rustc_private, "1.0.0", Some(27812), None),
(active, intrinsics, "1.0.0", None, None),
(active, lang_items, "1.0.0", None, None),
(active, staged_api, "1.0.0", None, None),
(active, allow_internal_unstable, "1.0.0", None, None),
(active, allow_internal_unsafe, "1.0.0", None, None),
(active, link_llvm_intrinsics, "1.0.0", Some(29602), None),
(active, box_syntax, "1.0.0", Some(49733), None),
(active, main, "1.0.0", Some(29634), None),
(active, start, "1.0.0", Some(29633), None),
(active, fundamental, "1.0.0", Some(29635), None),
(active, unboxed_closures, "1.0.0", Some(29625), None),
(active, linkage, "1.0.0", Some(29603), None),
(active, optin_builtin_traits, "1.0.0", Some(13231), None),
(active, box_patterns, "1.0.0", Some(29641), None),
(active, prelude_import, "1.2.0", None, None),
(active, omit_gdb_pretty_printer_section, "1.5.0", None, None),
(active, abi_vectorcall, "1.7.0", None, None),
(active, structural_match, "1.8.0", Some(31434), None),
(active, dropck_eyepatch, "1.10.0", Some(34761), None),
(active, panic_runtime, "1.10.0", Some(32837), None),
(active, needs_panic_runtime, "1.10.0", Some(32837), None),
(active, compiler_builtins, "1.13.0", None, None),
(active, abi_unadjusted, "1.16.0", None, None),
(active, profiler_runtime, "1.18.0", None, None),
(active, abi_thiscall, "1.19.0", None, None),
(active, allocator_internals, "1.20.0", None, None),
(active, test_2018_feature, "1.31.0", None, Some(Edition::Edition2018)),
(active, no_niche, "1.42.0", None, None),
(active, arm_target_feature, "1.27.0", Some(44839), None),
(active, aarch64_target_feature, "1.27.0", Some(44839), None),
(active, hexagon_target_feature, "1.27.0", Some(44839), None),
(active, powerpc_target_feature, "1.27.0", Some(44839), None),
(active, mips_target_feature, "1.27.0", Some(44839), None),
(active, avx512_target_feature, "1.27.0", Some(44839), None),
(active, mmx_target_feature, "1.27.0", Some(44839), None),
(active, sse4a_target_feature, "1.27.0", Some(44839), None),
(active, tbm_target_feature, "1.27.0", Some(44839), None),
(active, wasm_target_feature, "1.30.0", Some(44839), None),
(active, adx_target_feature, "1.32.0", Some(44839), None),
(active, cmpxchg16b_target_feature, "1.32.0", Some(44839), None),
(active, movbe_target_feature, "1.34.0", Some(44839), None),
(active, rtm_target_feature, "1.35.0", Some(44839), None),
(active, f16c_target_feature, "1.36.0", Some(44839), None),
(active, link_args, "1.0.0", Some(29596), None),
(active, non_ascii_idents, "1.0.0", Some(55467), None),
(active, plugin_registrar, "1.0.0", Some(29597), None),
(active, plugin, "1.0.0", Some(29597), None),
(active, thread_local, "1.0.0", Some(29594), None),
(active, simd_ffi, "1.0.0", Some(27731), None),
(active, nll, "1.0.0", Some(43234), None),
(active, const_fn, "1.2.0", Some(57563), None),
(active, associated_type_defaults, "1.2.0", Some(29661), None),
(active, no_core, "1.3.0", Some(29639), None),
(active, default_type_parameter_fallback, "1.3.0", Some(27336), None),
(active, repr_simd, "1.4.0", Some(27731), None),
(active, platform_intrinsics, "1.4.0", Some(27731), None),
(active, unwind_attributes, "1.4.0", Some(58760), None),
(active, stmt_expr_attributes, "1.6.0", Some(15701), None),
(active, type_ascription, "1.6.0", Some(23416), None),
(active, cfg_target_thread_local, "1.7.0", Some(29594), None),
(active, specialization, "1.7.0", Some(31844), None),
(active, min_specialization, "1.7.0", Some(31844), None),
(active, naked_functions, "1.9.0", Some(32408), None),
(active, cfg_target_has_atomic, "1.9.0", Some(32976), None),
(active, exclusive_range_pattern, "1.11.0", Some(37854), None),
(active, never_type, "1.13.0", Some(35121), None),
(active, exhaustive_patterns, "1.13.0", Some(51085), None),
(active, untagged_unions, "1.13.0", Some(55149), None),
(active, link_cfg, "1.14.0", Some(37406), None),
(active, abi_ptx, "1.15.0", Some(38788), None),
(active, repr128, "1.16.0", Some(56071), None),
(active, static_nobundle, "1.16.0", Some(37403), None),
(active, abi_msp430_interrupt, "1.16.0", Some(38487), None),
(active, decl_macro, "1.17.0", Some(39412), None),
(active, abi_x86_interrupt, "1.17.0", Some(40180), None),
(active, allow_fail, "1.19.0", Some(46488), None),
(active, unsized_tuple_coercion, "1.20.0", Some(42877), None),
(active, generators, "1.21.0", Some(43122), None),
(active, doc_cfg, "1.21.0", Some(43781), None),
(active, doc_masked, "1.21.0", Some(44027), None),
(active, external_doc, "1.22.0", Some(44732), None),
(active, crate_visibility_modifier, "1.23.0", Some(53120), None),
(active, extern_types, "1.23.0", Some(43467), None),
(active, arbitrary_self_types, "1.23.0", Some(44874), None),
(active, in_band_lifetimes, "1.23.0", Some(44524), None),
(active, generic_associated_types, "1.23.0", Some(44265), None),
(active, trait_alias, "1.24.0", Some(41517), None),
(active, infer_static_outlives_requirements, "1.26.0", Some(54185), None),
(active, const_fn_union, "1.27.0", Some(51909), None),
(active, const_raw_ptr_to_usize_cast, "1.27.0", Some(51910), None),
(active, const_raw_ptr_deref, "1.27.0", Some(51911), None),
(active, const_compare_raw_pointers, "1.27.0", Some(53020), None),
(active, doc_alias, "1.27.0", Some(50146), None),
(active, trivial_bounds, "1.28.0", Some(48214), None),
(active, label_break_value, "1.28.0", Some(48594), None),
(active, doc_keyword, "1.28.0", Some(51315), None),
(active, try_blocks, "1.29.0", Some(31436), None),
(active, alloc_error_handler, "1.29.0", Some(51540), None),
(active, abi_amdgpu_kernel, "1.29.0", Some(51575), None),
(active, const_panic, "1.30.0", Some(51999), None),
(active, marker_trait_attr, "1.30.0", Some(29864), None),
(active, proc_macro_hygiene, "1.30.0", Some(54727), None),
(active, unsized_locals, "1.30.0", Some(48055), None),
(active, custom_test_frameworks, "1.30.0", Some(50297), None),
(active, custom_inner_attributes, "1.30.0", Some(54726), None),
(active, impl_trait_in_bindings, "1.30.0", Some(63065), None),
(active, lint_reasons, "1.31.0", Some(54503), None),
(active, precise_pointer_size_matching, "1.32.0", Some(56354), None),
(active, ffi_returns_twice, "1.34.0", Some(58314), None),
(active, const_generics, "1.34.0", Some(44580), None),
(active, optimize_attribute, "1.34.0", Some(54882), None),
(active, c_variadic, "1.34.0", Some(44930), None),
(active, associated_type_bounds, "1.34.0", Some(52662), None),
(active, let_chains, "1.37.0", Some(53667), None),
(active, transparent_unions, "1.37.0", Some(60405), None),
(active, arbitrary_enum_discriminant, "1.37.0", Some(60553), None),
(active, member_constraints, "1.37.0", Some(61997), None),
(active, async_closure, "1.37.0", Some(62290), None),
(active, const_in_array_repeat_expressions, "1.37.0", Some(49147), None),
(active, type_alias_impl_trait, "1.38.0", Some(63063), None),
(active, or_patterns, "1.38.0", Some(54883), None),
(active, const_extern_fn, "1.40.0", Some(64926), None),
(active, raw_dylib, "1.40.0", Some(58713), None),
(active, track_caller, "1.40.0", Some(47809), None),
(active, object_safe_for_dispatch, "1.40.0", Some(43561), None),
(active, abi_efiapi, "1.40.0", Some(65815), None),
(active, raw_ref_op, "1.41.0", Some(64490), None),
(active, never_type_fallback, "1.41.0", Some(65992), None),
(active, register_attr, "1.41.0", Some(66080), None),
(active, register_tool, "1.41.0", Some(66079), None),
(active, const_if_match, "1.41.0", Some(49146), None),
(active, cfg_sanitize, "1.41.0", Some(39699), None),
(active, half_open_range_patterns, "1.41.0", Some(67264), None),
(active, const_mut_refs, "1.41.0", Some(57349), None),
(active, const_loop, "1.41.0", Some(52000), None),
(active, bindings_after_at, "1.41.0", Some(65490), None),
(active, move_ref_pattern, "1.42.0", Some(68354), None),
(active, const_trait_impl, "1.42.0", Some(67792), None),
(active, const_trait_bound_opt_out, "1.42.0", Some(67794), None),
(active, no_sanitize, "1.42.0", Some(39699), None),
(active, const_eval_limit, "1.43.0", Some(67217), None),
(active, negative_impls, "1.44.0", Some(68318), None),
);
pub const INCOMPLETE_FEATURES: &[Symbol] = &[
sym::impl_trait_in_bindings,
sym::generic_associated_types,
sym::const_generics,
sym::let_chains,
sym::raw_dylib,
sym::const_trait_impl,
sym::const_trait_bound_opt_out,
];