1use std::sync::LazyLock;
4
5use rustc_data_structures::fx::FxHashSet;
6use rustc_span::{Symbol, sym};
7
8use crate::Features;
9
10type GateFn = fn(&Features) -> bool;
11
12pub type GatedCfg = (Symbol, Symbol, GateFn);
13
14const GATED_CFGS: &[GatedCfg] = &[
16 (sym::overflow_checks, sym::cfg_overflow_checks, Features::cfg_overflow_checks),
18 (sym::ub_checks, sym::cfg_ub_checks, Features::cfg_ub_checks),
19 (sym::contract_checks, sym::cfg_contract_checks, Features::cfg_contract_checks),
20 (sym::target_thread_local, sym::cfg_target_thread_local, Features::cfg_target_thread_local),
21 (
22 sym::target_has_atomic_load_store,
23 sym::cfg_target_has_atomic,
24 Features::cfg_target_has_atomic,
25 ),
26 (sym::sanitize, sym::cfg_sanitize, Features::cfg_sanitize),
27 (sym::version, sym::cfg_version, Features::cfg_version),
28 (sym::relocation_model, sym::cfg_relocation_model, Features::cfg_relocation_model),
29 (sym::sanitizer_cfi_generalize_pointers, sym::cfg_sanitizer_cfi, Features::cfg_sanitizer_cfi),
30 (sym::sanitizer_cfi_normalize_integers, sym::cfg_sanitizer_cfi, Features::cfg_sanitizer_cfi),
31 (sym::fmt_debug, sym::fmt_debug, Features::fmt_debug),
33 (
34 sym::target_has_reliable_f16,
35 sym::cfg_target_has_reliable_f16_f128,
36 Features::cfg_target_has_reliable_f16_f128,
37 ),
38 (
39 sym::target_has_reliable_f16_math,
40 sym::cfg_target_has_reliable_f16_f128,
41 Features::cfg_target_has_reliable_f16_f128,
42 ),
43 (
44 sym::target_has_reliable_f16b,
45 sym::cfg_target_has_reliable_f16b,
46 Features::cfg_target_has_reliable_f16b,
47 ),
48 (
49 sym::target_has_reliable_f128,
50 sym::cfg_target_has_reliable_f16_f128,
51 Features::cfg_target_has_reliable_f16_f128,
52 ),
53 (
54 sym::target_has_reliable_f128_math,
55 sym::cfg_target_has_reliable_f16_f128,
56 Features::cfg_target_has_reliable_f16_f128,
57 ),
58 (sym::target_has_threads, sym::cfg_target_has_threads, Features::cfg_target_has_threads),
59 (sym::target_object_format, sym::cfg_target_object_format, Features::cfg_target_object_format),
60];
61
62pub fn find_gated_cfg(name: Symbol) -> Option<&'static GatedCfg> {
64 GATED_CFGS.iter().find(|(cfg_sym, ..)| name == *cfg_sym)
65}
66
67#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for AttributeStability { }
#[automatically_derived]
impl ::core::clone::Clone for AttributeStability {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Symbol>;
let _: ::core::clone::AssertParamIsClone<&'static [&'static str]>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for AttributeStability {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
AttributeStability::Unstable {
gate_name: __self_0, notes: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Unstable", "gate_name", __self_0, "notes", &__self_1),
AttributeStability::Stable =>
::core::fmt::Formatter::write_str(f, "Stable"),
}
}
}Debug, #[automatically_derived]
impl ::core::marker::Copy for AttributeStability { }Copy)]
68pub enum AttributeStability {
69 Unstable {
71 gate_name: Symbol,
73 notes: &'static [&'static str],
76 },
77 Stable,
79}
80
81#[rustfmt::skip]
83pub static BUILTIN_ATTRIBUTES: &[Symbol] = &[
84 sym::cfg,
90 sym::cfg_attr,
91
92 sym::ignore,
94 sym::should_panic,
95
96 sym::automatically_derived,
98 sym::macro_use,
99 sym::macro_escape, sym::macro_export,
101 sym::proc_macro,
102 sym::proc_macro_derive,
103 sym::proc_macro_attribute,
104
105 sym::warn,
107 sym::allow,
108 sym::expect,
109 sym::forbid,
110 sym::deny,
111 sym::must_use,
112 sym::must_not_suspend,
113 sym::deprecated,
114
115 sym::crate_name,
117 sym::crate_type,
118
119 sym::link,
121 sym::link_name,
122 sym::no_link,
123 sym::repr,
124 sym::rustc_align,
126 sym::rustc_align_static,
127 sym::export_name,
128 sym::link_section,
129 sym::no_mangle,
130 sym::used,
131 sym::link_ordinal,
132 sym::naked,
133 sym::rustc_pass_indirectly_in_non_rustic_abis,
135
136 sym::recursion_limit,
138 sym::type_length_limit,
139 sym::move_size_limit,
140
141 sym::no_main,
143
144 sym::path,
146 sym::no_std,
147 sym::no_implicit_prelude,
148 sym::non_exhaustive,
149
150 sym::windows_subsystem,
152 sym::panic_handler, sym::inline,
156 sym::cold,
157 sym::no_builtins,
158 sym::target_feature,
159 sym::track_caller,
160 sym::instruction_set,
161 sym::force_target_feature,
162 sym::sanitize,
163 sym::coverage,
164
165 sym::doc,
166
167 sym::debugger_visualizer,
169 sym::collapse_debuginfo,
170
171 sym::export_stable,
177
178 sym::test_runner,
180
181 sym::reexport_test_harness_main,
182
183 sym::marker,
185 sym::thread_local,
186 sym::no_core,
187 sym::optimize,
189
190 sym::ffi_pure,
191 sym::ffi_const,
192 sym::register_attribute_tool,
193 sym::register_lint_tool,
194 sym::register_tool,
195 sym::cfi_encoding,
197
198 sym::coroutine,
200
201 sym::patchable_function_entry,
204
205 sym::const_continue,
210 sym::loop_match,
211
212 sym::pin_v2,
217
218 sym::rustc_splat,
223
224 sym::rustc_unroll,
230
231 sym::instrument_fn,
236
237 sym::feature,
242 sym::stable,
244 sym::unstable,
245 sym::unstable_feature_bound,
246 sym::unstable_removed,
247 sym::rustc_const_unstable,
248 sym::rustc_const_stable,
249 sym::rustc_default_body_unstable,
250 sym::allow_internal_unstable,
251 sym::allow_internal_unsafe,
252 sym::rustc_eii_foreign_item,
253 sym::rustc_allowed_through_unstable_modules,
254 sym::rustc_deprecated_safe_2024,
255 sym::rustc_pub_transparent,
256
257 sym::fundamental,
262 sym::may_dangle,
263
264 sym::rustc_allocator,
269 sym::rustc_nounwind,
270 sym::rustc_reallocator,
271 sym::rustc_deallocator,
272 sym::rustc_allocator_zeroed,
273 sym::rustc_allocator_zeroed_variant,
274 sym::default_lib_allocator,
275 sym::needs_allocator,
276 sym::panic_runtime,
277 sym::needs_panic_runtime,
278 sym::compiler_builtins,
279 sym::profiler_runtime,
280
281 sym::linkage,
286 sym::rustc_std_internal_symbol,
287 sym::rustc_objc_class,
288 sym::rustc_objc_selector,
289
290 sym::rustc_builtin_macro,
295 sym::rustc_proc_macro_decls,
296 sym::rustc_macro_transparency,
297 sym::rustc_autodiff,
298 sym::rustc_offload_kernel,
299
300 sym::rustc_on_unimplemented,
305 sym::rustc_confusables,
306 sym::rustc_conversion_suggestion,
308 sym::rustc_trivial_field_reads,
311 sym::rustc_lint_query_instability,
314 sym::rustc_lint_untracked_query_information,
317 sym::rustc_lint_opt_ty,
320 sym::rustc_lint_opt_deny_field_access,
323 sym::rustc_diagnostic_opaque,
324
325 sym::rustc_always_gca,
330 sym::rustc_promotable,
331 sym::rustc_legacy_const_generics,
332 sym::rustc_do_not_const_check,
334 sym::rustc_const_stable_indirect,
335 sym::rustc_intrinsic_const_stable_indirect,
336 sym::rustc_allow_const_fn_unstable,
337
338 sym::rustc_simd_monomorphize_lane_limit,
343 sym::rustc_nonnull_optimization_guaranteed,
344
345 sym::lang,
349 sym::rustc_as_ptr,
350 sym::rustc_should_not_be_called_on_const_items,
351 sym::rustc_pass_by_value,
352 sym::rustc_never_returns_null_ptr,
353 sym::rustc_no_implicit_autorefs,
354 sym::rustc_coherence_is_core,
355 sym::rustc_coinductive,
356 sym::rustc_comptime,
357 sym::rustc_allow_incoherent_impl,
358 sym::rustc_preserve_ub_checks,
359 sym::rustc_deny_explicit_impl,
360 sym::rustc_dyn_incompatible_trait,
361 sym::rustc_has_incoherent_inherent_impls,
362 sym::rustc_non_const_trait_method,
363 sym::rustc_panics_when_zero,
364
365 sym::rustc_canonical_symbol,
366 sym::rustc_diagnostic_item,
367 sym::prelude_import,
368 sym::rustc_paren_sugar,
369 sym::rustc_inherit_overflow_checks,
370 sym::rustc_test_marker,
371 sym::rustc_allow_lifetime_dependent_specialization,
372 sym::rustc_specialization_trait,
373 sym::rustc_main,
374 sym::rustc_skip_during_method_dispatch,
375 sym::rustc_must_implement_one_of,
376 sym::rustc_doc_primitive,
377 sym::rustc_intrinsic,
378 sym::rustc_no_mir_inline,
379 sym::rustc_force_inline,
380 sym::rustc_scalable_vector,
381 sym::rustc_must_match_exhaustively,
382 sym::rustc_no_writable,
383
384 sym::rustc_effective_visibility,
389 sym::rustc_dump_inferred_outlives,
390 sym::rustc_capture_analysis,
391 sym::rustc_insignificant_dtor,
392 sym::rustc_no_implicit_bounds,
393 sym::rustc_strict_coherence,
394 sym::rustc_dump_variances,
395 sym::rustc_dump_variances_of_opaques,
396 sym::rustc_dump_generics,
397 sym::rustc_dump_hidden_type_of_opaques,
398 sym::rustc_dump_layout,
399 sym::rustc_abi,
400 sym::rustc_regions,
401 sym::rustc_delayed_bug_from_inside_query,
402 sym::rustc_dump_user_args,
403 sym::rustc_evaluate_where_clauses,
404 sym::rustc_if_this_changed,
405 sym::rustc_then_this_would_need,
406 sym::rustc_clean,
407 sym::rustc_partition_reused,
408 sym::rustc_partition_codegened,
409 sym::rustc_expected_cgu_reuse,
410 sym::rustc_dump_symbol_name,
411 sym::rustc_dump_def_path,
412 sym::rustc_mir,
413 sym::custom_mir,
414 sym::rustc_dump_item_bounds,
415 sym::rustc_dump_clauses,
416 sym::rustc_dump_def_parents,
417 sym::rustc_dump_object_lifetime_defaults,
418 sym::rustc_dump_vtable,
419 sym::rustc_dummy,
420 sym::pattern_complexity_limit,
421];
422
423pub fn is_builtin_attr_name(name: Symbol) -> bool {
424 BUILTIN_ATTRIBUTE_SET.contains(&name)
425}
426
427pub static BUILTIN_ATTRIBUTE_SET: LazyLock<FxHashSet<Symbol>> = LazyLock::new(|| {
428 let mut set = FxHashSet::default();
429 for attr in BUILTIN_ATTRIBUTES.iter() {
430 if !set.insert(*attr) {
431 {
::core::panicking::panic_fmt(format_args!("duplicate builtin attribute `{0}`",
attr));
};panic!("duplicate builtin attribute `{}`", attr);
432 }
433 }
434 set
435});