1 //! Built-in attributes and `cfg` flag gating.
3 use AttributeDuplicates::*;
7 use crate::{Features, Stability};
9 use rustc_data_structures::fx::FxHashMap;
10 use rustc_span::symbol::{sym, Symbol};
12 use std::lazy::SyncLazy;
14 type GateFn = fn(&Features) -> bool;
18 (|features| features.$field) as GateFn
22 pub type GatedCfg = (Symbol, Symbol, GateFn);
24 /// `cfg(...)`'s that are feature gated.
25 const GATED_CFGS: &[GatedCfg] = &[
26 // (name in cfg, feature, function to check if the feature is enabled)
27 (sym::target_abi, sym::cfg_target_abi, cfg_fn!(cfg_target_abi)),
28 (sym::target_thread_local, sym::cfg_target_thread_local, cfg_fn!(cfg_target_thread_local)),
29 (sym::target_has_atomic, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
30 (sym::target_has_atomic_load_store, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
32 sym::target_has_atomic_equal_alignment,
33 sym::cfg_target_has_atomic,
34 cfg_fn!(cfg_target_has_atomic),
36 (sym::sanitize, sym::cfg_sanitize, cfg_fn!(cfg_sanitize)),
37 (sym::version, sym::cfg_version, cfg_fn!(cfg_version)),
38 (sym::panic, sym::cfg_panic, cfg_fn!(cfg_panic)),
41 /// Find a gated cfg determined by the `pred`icate which is given the cfg's name.
42 pub fn find_gated_cfg(pred: impl Fn(Symbol) -> bool) -> Option<&'static GatedCfg> {
43 GATED_CFGS.iter().find(|(cfg_sym, ..)| pred(*cfg_sym))
46 // If you change this, please modify `src/doc/unstable-book` as well. You must
47 // move that documentation into the relevant place in the other docs, and
48 // remove the chapter on the flag.
50 #[derive(Copy, Clone, PartialEq, Debug)]
51 pub enum AttributeType {
52 /// Normal, builtin attribute that is consumed
53 /// by the compiler before the unused_attribute check
56 /// Builtin attribute that is only allowed at the crate level
60 #[derive(Clone, Copy)]
61 pub enum AttributeGate {
62 /// Is gated by a given feature gate, reason
63 /// and function to check if enabled
64 Gated(Stability, Symbol, &'static str, fn(&Features) -> bool),
66 /// Ungated attribute, can be used on all release channels
71 impl std::fmt::Debug for AttributeGate {
72 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
74 Self::Gated(ref stab, name, expl, _) => {
75 write!(fmt, "Gated({:?}, {}, {})", stab, name, expl)
77 Self::Ungated => write!(fmt, "Ungated"),
83 fn is_deprecated(&self) -> bool {
84 matches!(*self, Self::Gated(Stability::Deprecated(_, _), ..))
88 /// A template that the attribute input must match.
89 /// Only top-level shape (`#[attr]` vs `#[attr(...)]` vs `#[attr = ...]`) is considered now.
90 #[derive(Clone, Copy, Default)]
91 pub struct AttributeTemplate {
92 /// If `true`, the attribute is allowed to be a bare word like `#[test]`.
94 /// If `Some`, the attribute is allowed to take a list of items like `#[allow(..)]`.
95 pub list: Option<&'static str>,
96 /// If `Some`, the attribute is allowed to be a name/value pair where the
97 /// value is a string, like `#[must_use = "reason"]`.
98 pub name_value_str: Option<&'static str>,
101 /// How to handle multiple duplicate attributes on the same item.
102 #[derive(Clone, Copy, Default)]
103 pub enum AttributeDuplicates {
104 /// Duplicates of this attribute are allowed.
106 /// This should only be used with attributes where duplicates have semantic
107 /// meaning, or some kind of "additive" behavior. For example, `#[warn(..)]`
108 /// can be specified multiple times, and it combines all the entries. Or use
109 /// this if there is validation done elsewhere.
112 /// Duplicates after the first attribute will be an unused_attribute warning.
114 /// This is usually used for "word" attributes, where they are used as a
115 /// boolean marker, like `#[used]`. It is not necessarily wrong that there
116 /// are duplicates, but the others should probably be removed.
118 /// Same as `WarnFollowing`, but only issues warnings for word-style attributes.
120 /// This is only for special cases, for example multiple `#[macro_use]` can
121 /// be warned, but multiple `#[macro_use(...)]` should not because the list
122 /// form has different meaning from the word form.
123 WarnFollowingWordOnly,
124 /// Duplicates after the first attribute will be an error.
126 /// This should be used where duplicates would be ignored, but carry extra
127 /// meaning that could cause confusion. For example, `#[stable(since="1.0")]
128 /// #[stable(since="2.0")]`, which version should be used for `stable`?
130 /// Duplicates preceding the last instance of the attribute will be an error.
132 /// This is the same as `ErrorFollowing`, except the last attribute is the
133 /// one that is "used". This is typically used in cases like codegen
134 /// attributes which usually only honor the last attribute.
136 /// Duplicates after the first attribute will be an unused_attribute warning
137 /// with a note that this will be an error in the future.
139 /// This should be used for attributes that should be `ErrorFollowing`, but
140 /// because older versions of rustc silently accepted (and ignored) the
141 /// attributes, this is used to transition.
143 /// Duplicates preceding the last instance of the attribute will be a
144 /// warning, with a note that this will be an error in the future.
146 /// This is the same as `FutureWarnFollowing`, except the last attribute is
147 /// the one that is "used". Ideally these can eventually migrate to
148 /// `ErrorPreceding`.
152 /// A convenience macro for constructing attribute templates.
153 /// E.g., `template!(Word, List: "description")` means that the attribute
154 /// supports forms `#[attr]` and `#[attr(description)]`.
155 macro_rules! template {
156 (Word) => { template!(@ true, None, None) };
157 (List: $descr: expr) => { template!(@ false, Some($descr), None) };
158 (NameValueStr: $descr: expr) => { template!(@ false, None, Some($descr)) };
159 (Word, List: $descr: expr) => { template!(@ true, Some($descr), None) };
160 (Word, NameValueStr: $descr: expr) => { template!(@ true, None, Some($descr)) };
161 (List: $descr1: expr, NameValueStr: $descr2: expr) => {
162 template!(@ false, Some($descr1), Some($descr2))
164 (Word, List: $descr1: expr, NameValueStr: $descr2: expr) => {
165 template!(@ true, Some($descr1), Some($descr2))
167 (@ $word: expr, $list: expr, $name_value_str: expr) => { AttributeTemplate {
168 word: $word, list: $list, name_value_str: $name_value_str
172 macro_rules! ungated {
173 ($attr:ident, $typ:expr, $tpl:expr, $duplicates:expr $(,)?) => {
179 duplicates: $duplicates,
185 ($attr:ident, $typ:expr, $tpl:expr, $duplicates:expr, $gate:ident, $msg:expr $(,)?) => {
190 duplicates: $duplicates,
191 gate: Gated(Stability::Unstable, sym::$gate, $msg, cfg_fn!($gate)),
194 ($attr:ident, $typ:expr, $tpl:expr, $duplicates:expr, $msg:expr $(,)?) => {
199 duplicates: $duplicates,
200 gate: Gated(Stability::Unstable, sym::$attr, $msg, cfg_fn!($attr)),
205 macro_rules! rustc_attr {
206 (TEST, $attr:ident, $typ:expr, $tpl:expr, $duplicate:expr $(,)?) => {
215 "]` attribute is just used for rustc unit tests \
216 and will never be stable",
220 ($attr:ident, $typ:expr, $tpl:expr, $duplicates:expr, $msg:expr $(,)?) => {
225 duplicates: $duplicates,
226 gate: Gated(Stability::Unstable, sym::rustc_attrs, $msg, cfg_fn!(rustc_attrs)),
231 macro_rules! experimental {
233 concat!("the `#[", stringify!($attr), "]` attribute is an experimental feature")
237 const IMPL_DETAIL: &str = "internal implementation detail";
238 const INTERNAL_UNSTABLE: &str = "this is an internal attribute that will never be stable";
240 pub struct BuiltinAttribute {
242 pub type_: AttributeType,
243 pub template: AttributeTemplate,
244 pub duplicates: AttributeDuplicates,
245 pub gate: AttributeGate,
248 /// Attributes that have a special meaning to rustc or rustdoc.
250 pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
251 // ==========================================================================
252 // Stable attributes:
253 // ==========================================================================
255 // Conditional compilation:
256 ungated!(cfg, Normal, template!(List: "predicate"), DuplicatesOk),
257 ungated!(cfg_attr, Normal, template!(List: "predicate, attr1, attr2, ..."), DuplicatesOk),
260 ungated!(ignore, Normal, template!(Word, NameValueStr: "reason"), WarnFollowing),
262 should_panic, Normal,
263 template!(Word, List: r#"expected = "reason"#, NameValueStr: "reason"), FutureWarnFollowing,
265 // FIXME(Centril): This can be used on stable but shouldn't.
266 ungated!(reexport_test_harness_main, CrateLevel, template!(NameValueStr: "name"), ErrorFollowing),
269 ungated!(automatically_derived, Normal, template!(Word), WarnFollowing),
270 ungated!(macro_use, Normal, template!(Word, List: "name1, name2, ..."), WarnFollowingWordOnly),
271 ungated!(macro_escape, Normal, template!(Word), WarnFollowing), // Deprecated synonym for `macro_use`.
272 ungated!(macro_export, Normal, template!(Word, List: "local_inner_macros"), WarnFollowing),
273 ungated!(proc_macro, Normal, template!(Word), ErrorFollowing),
275 proc_macro_derive, Normal,
276 template!(List: "TraitName, /*opt*/ attributes(name1, name2, ...)"), ErrorFollowing,
278 ungated!(proc_macro_attribute, Normal, template!(Word), ErrorFollowing),
282 warn, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), DuplicatesOk
285 allow, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), DuplicatesOk
288 forbid, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), DuplicatesOk
291 deny, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), DuplicatesOk
293 ungated!(must_use, Normal, template!(Word, NameValueStr: "reason"), FutureWarnFollowing),
295 must_not_suspend, Normal, template!(Word, NameValueStr: "reason"), WarnFollowing,
296 must_not_suspend, experimental!(must_not_suspend)
302 List: r#"/*opt*/ since = "version", /*opt*/ note = "reason""#,
303 NameValueStr: "reason"
305 // This has special duplicate handling in E0550 to handle duplicates with rustc_deprecated
310 ungated!(crate_name, CrateLevel, template!(NameValueStr: "name"), FutureWarnFollowing),
311 ungated!(crate_type, CrateLevel, template!(NameValueStr: "bin|lib|..."), FutureWarnFollowing),
312 // crate_id is deprecated
313 ungated!(crate_id, CrateLevel, template!(NameValueStr: "ignored"), FutureWarnFollowing),
315 // ABI, linking, symbols, and FFI
318 template!(List: r#"name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...""#),
321 ungated!(link_name, Normal, template!(NameValueStr: "name"), FutureWarnPreceding),
322 ungated!(no_link, Normal, template!(Word), WarnFollowing),
323 ungated!(repr, Normal, template!(List: "C"), DuplicatesOk),
324 ungated!(export_name, Normal, template!(NameValueStr: "name"), FutureWarnPreceding),
325 ungated!(link_section, Normal, template!(NameValueStr: "name"), FutureWarnPreceding),
326 ungated!(no_mangle, Normal, template!(Word), WarnFollowing),
327 ungated!(used, Normal, template!(Word), WarnFollowing),
330 ungated!(recursion_limit, CrateLevel, template!(NameValueStr: "N"), FutureWarnFollowing),
331 ungated!(type_length_limit, CrateLevel, template!(NameValueStr: "N"), FutureWarnFollowing),
333 const_eval_limit, CrateLevel, template!(NameValueStr: "N"), ErrorFollowing,
334 const_eval_limit, experimental!(const_eval_limit)
337 move_size_limit, CrateLevel, template!(NameValueStr: "N"), ErrorFollowing,
338 large_assignments, experimental!(move_size_limit)
342 ungated!(main, Normal, template!(Word), WarnFollowing),
343 ungated!(start, Normal, template!(Word), WarnFollowing),
344 ungated!(no_start, CrateLevel, template!(Word), WarnFollowing),
345 ungated!(no_main, CrateLevel, template!(Word), WarnFollowing),
347 // Modules, prelude, and resolution:
348 ungated!(path, Normal, template!(NameValueStr: "file"), FutureWarnFollowing),
349 ungated!(no_std, CrateLevel, template!(Word), WarnFollowing),
350 ungated!(no_implicit_prelude, Normal, template!(Word), WarnFollowing),
351 ungated!(non_exhaustive, Normal, template!(Word), WarnFollowing),
355 windows_subsystem, Normal,
356 template!(NameValueStr: "windows|console"), FutureWarnFollowing
358 ungated!(panic_handler, Normal, template!(Word), WarnFollowing), // RFC 2070
361 ungated!(inline, Normal, template!(Word, List: "always|never"), FutureWarnFollowing),
362 ungated!(cold, Normal, template!(Word), WarnFollowing),
363 ungated!(no_builtins, Normal, template!(Word), WarnFollowing),
364 ungated!(target_feature, Normal, template!(List: r#"enable = "name""#), DuplicatesOk),
365 ungated!(track_caller, Normal, template!(Word), WarnFollowing),
368 template!(List: "address, memory, thread"), DuplicatesOk,
369 experimental!(no_sanitize)
371 gated!(no_coverage, Normal, template!(Word), WarnFollowing, experimental!(no_coverage)),
374 doc, Normal, template!(List: "hidden|inline|...", NameValueStr: "string"), DuplicatesOk
377 // ==========================================================================
378 // Unstable attributes:
379 // ==========================================================================
382 gated!(naked, Normal, template!(Word), WarnFollowing, naked_functions, experimental!(naked)),
384 link_ordinal, Normal, template!(List: "ordinal"), ErrorPreceding, raw_dylib,
385 experimental!(link_ordinal)
392 template: template!(List: "name"),
393 duplicates: DuplicatesOk,
395 Stability::Deprecated(
396 "https://github.com/rust-lang/rust/pull/64675",
397 Some("may be removed in a future compiler version"),
400 "compiler plugins are deprecated",
406 gated!(allow_fail, Normal, template!(Word), WarnFollowing, experimental!(allow_fail)),
408 test_runner, CrateLevel, template!(List: "path"), ErrorFollowing, custom_test_frameworks,
409 "custom test frameworks are an unstable feature",
413 marker, Normal, template!(Word), WarnFollowing, marker_trait_attr, experimental!(marker)
416 thread_local, Normal, template!(Word), WarnFollowing,
417 "`#[thread_local]` is an experimental feature, and does not currently handle destructors",
419 gated!(no_core, CrateLevel, template!(Word), WarnFollowing, experimental!(no_core)),
422 optimize, Normal, template!(List: "size|speed"), ErrorPreceding, optimize_attribute,
423 experimental!(optimize),
427 instruction_set, Normal, template!(List: "set"), ErrorPreceding,
428 isa_attribute, experimental!(instruction_set)
432 ffi_returns_twice, Normal, template!(Word), WarnFollowing, experimental!(ffi_returns_twice)
434 gated!(ffi_pure, Normal, template!(Word), WarnFollowing, experimental!(ffi_pure)),
435 gated!(ffi_const, Normal, template!(Word), WarnFollowing, experimental!(ffi_const)),
437 register_attr, CrateLevel, template!(List: "attr1, attr2, ..."), DuplicatesOk,
438 experimental!(register_attr),
441 register_tool, CrateLevel, template!(List: "tool1, tool2, ..."), DuplicatesOk,
442 experimental!(register_tool),
446 cmse_nonsecure_entry, Normal, template!(Word), WarnFollowing,
447 experimental!(cmse_nonsecure_entry)
451 default_method_body_is_const, Normal, template!(Word), WarnFollowing, const_trait_impl,
452 "`default_method_body_is_const` is a temporary placeholder for declaring default bodies \
453 as `const`, which may be removed or renamed in the future."
456 // ==========================================================================
457 // Internal attributes: Stability, deprecation, and unsafe:
458 // ==========================================================================
460 ungated!(feature, CrateLevel, template!(List: "name1, name1, ..."), DuplicatesOk),
461 // DuplicatesOk since it has its own validation
463 rustc_deprecated, Normal,
464 template!(List: r#"since = "version", reason = "...""#), DuplicatesOk // See E0550
466 // DuplicatesOk since it has its own validation
468 stable, Normal, template!(List: r#"feature = "name", since = "version""#), DuplicatesOk
472 template!(List: r#"feature = "name", reason = "...", issue = "N""#), DuplicatesOk,
474 ungated!(rustc_const_unstable, Normal, template!(List: r#"feature = "name""#), DuplicatesOk),
475 ungated!(rustc_const_stable, Normal, template!(List: r#"feature = "name""#), DuplicatesOk),
477 allow_internal_unstable, Normal, template!(Word, List: "feat1, feat2, ..."), DuplicatesOk,
478 "allow_internal_unstable side-steps feature gating and stability checks",
481 rustc_allow_const_fn_unstable, Normal,
482 template!(Word, List: "feat1, feat2, ..."), DuplicatesOk,
483 "rustc_allow_const_fn_unstable side-steps feature gating and stability checks"
486 allow_internal_unsafe, Normal, template!(Word), WarnFollowing,
487 "allow_internal_unsafe side-steps the unsafe_code lint",
490 // ==========================================================================
491 // Internal attributes: Type system related:
492 // ==========================================================================
494 gated!(fundamental, Normal, template!(Word), WarnFollowing, experimental!(fundamental)),
496 may_dangle, Normal, template!(Word), WarnFollowing, dropck_eyepatch,
497 "`may_dangle` has unstable semantics and may be removed in the future",
500 // ==========================================================================
501 // Internal attributes: Runtime related:
502 // ==========================================================================
504 rustc_attr!(rustc_allocator, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
505 rustc_attr!(rustc_allocator_nounwind, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
507 alloc_error_handler, Normal, template!(Word), WarnFollowing,
508 experimental!(alloc_error_handler)
511 default_lib_allocator, Normal, template!(Word), WarnFollowing, allocator_internals,
512 experimental!(default_lib_allocator),
515 needs_allocator, Normal, template!(Word), WarnFollowing, allocator_internals,
516 experimental!(needs_allocator),
518 gated!(panic_runtime, Normal, template!(Word), WarnFollowing, experimental!(panic_runtime)),
520 needs_panic_runtime, Normal, template!(Word), WarnFollowing,
521 experimental!(needs_panic_runtime)
524 compiler_builtins, Normal, template!(Word), WarnFollowing,
525 "the `#[compiler_builtins]` attribute is used to identify the `compiler_builtins` crate \
526 which contains compiler-rt intrinsics and will never be stable",
529 profiler_runtime, Normal, template!(Word), WarnFollowing,
530 "the `#[profiler_runtime]` attribute is used to identify the `profiler_builtins` crate \
531 which contains the profiler runtime and will never be stable",
534 // ==========================================================================
535 // Internal attributes, Linkage:
536 // ==========================================================================
539 linkage, Normal, template!(NameValueStr: "external|internal|..."), ErrorPreceding,
540 "the `linkage` attribute is experimental and not portable across platforms",
543 rustc_std_internal_symbol, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE
546 // ==========================================================================
547 // Internal attributes, Macro related:
548 // ==========================================================================
551 rustc_builtin_macro, Normal,
552 template!(Word, List: "name, /*opt*/ attributes(name1, name2, ...)"), ErrorFollowing,
555 rustc_attr!(rustc_proc_macro_decls, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE),
557 rustc_macro_transparency, Normal,
558 template!(NameValueStr: "transparent|semitransparent|opaque"), ErrorFollowing,
559 "used internally for testing macro hygiene",
562 // ==========================================================================
563 // Internal attributes, Diagnostics related:
564 // ==========================================================================
567 rustc_on_unimplemented, Normal,
569 List: r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#,
570 NameValueStr: "message"
575 // Enumerates "identity-like" conversion methods to suggest on type mismatch.
577 rustc_conversion_suggestion, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE
579 // Prevents field reads in the marked trait or method to be considered
580 // during dead code analysis.
582 rustc_trivial_field_reads, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE
585 // ==========================================================================
586 // Internal attributes, Const related:
587 // ==========================================================================
589 rustc_attr!(rustc_promotable, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
591 rustc_legacy_const_generics, Normal, template!(List: "N"), ErrorFollowing,
594 // Do not const-check this function's body. It will always get replaced during CTFE.
596 rustc_do_not_const_check, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE
599 // ==========================================================================
600 // Internal attributes, Layout related:
601 // ==========================================================================
604 rustc_layout_scalar_valid_range_start, Normal, template!(List: "value"), ErrorFollowing,
605 "the `#[rustc_layout_scalar_valid_range_start]` attribute is just used to enable \
606 niche optimizations in libcore and will never be stable",
609 rustc_layout_scalar_valid_range_end, Normal, template!(List: "value"), ErrorFollowing,
610 "the `#[rustc_layout_scalar_valid_range_end]` attribute is just used to enable \
611 niche optimizations in libcore and will never be stable",
614 rustc_nonnull_optimization_guaranteed, Normal, template!(Word), WarnFollowing,
615 "the `#[rustc_nonnull_optimization_guaranteed]` attribute is just used to enable \
616 niche optimizations in libcore and will never be stable",
619 // ==========================================================================
620 // Internal attributes, Misc:
621 // ==========================================================================
623 lang, Normal, template!(NameValueStr: "name"), DuplicatesOk, lang_items,
624 "language items are subject to change",
627 name: sym::rustc_diagnostic_item,
629 template: template!(NameValueStr: "name"),
630 duplicates: ErrorFollowing,
634 "diagnostic items compiler internal support for linting",
635 cfg_fn!(rustc_attrs),
640 prelude_import, Normal, template!(Word), WarnFollowing,
641 "`#[prelude_import]` is for use by rustc only",
644 rustc_paren_sugar, Normal, template!(Word), WarnFollowing, unboxed_closures,
645 "unboxed_closures are still evolving",
648 rustc_inherit_overflow_checks, Normal, template!(Word), WarnFollowing,
649 "the `#[rustc_inherit_overflow_checks]` attribute is just used to control \
650 overflow checking behavior of several libcore functions that are inlined \
651 across crates and will never be stable",
654 rustc_reservation_impl, Normal,
655 template!(NameValueStr: "reservation message"), ErrorFollowing,
656 "the `#[rustc_reservation_impl]` attribute is internally used \
657 for reserving for `for<T> From<!> for T` impl"
660 rustc_test_marker, Normal, template!(Word), WarnFollowing,
661 "the `#[rustc_test_marker]` attribute is used internally to track tests",
664 rustc_unsafe_specialization_marker, Normal, template!(Word), WarnFollowing,
665 "the `#[rustc_unsafe_specialization_marker]` attribute is used to check specializations"
668 rustc_specialization_trait, Normal, template!(Word), WarnFollowing,
669 "the `#[rustc_specialization_trait]` attribute is used to check specializations"
672 rustc_main, Normal, template!(Word), WarnFollowing,
673 "the `#[rustc_main]` attribute is used internally to specify test entry point function",
676 rustc_skip_array_during_method_dispatch, Normal, template!(Word), WarnFollowing,
677 "the `#[rustc_skip_array_during_method_dispatch]` attribute is used to exclude a trait \
678 from method dispatch when the receiver is an array, for compatibility in editions < 2021."
681 // ==========================================================================
682 // Internal attributes, Testing:
683 // ==========================================================================
685 rustc_attr!(TEST, rustc_outlives, Normal, template!(Word), WarnFollowing),
686 rustc_attr!(TEST, rustc_capture_analysis, Normal, template!(Word), WarnFollowing),
687 rustc_attr!(TEST, rustc_insignificant_dtor, Normal, template!(Word), WarnFollowing),
688 rustc_attr!(TEST, rustc_strict_coherence, Normal, template!(Word), WarnFollowing),
689 rustc_attr!(TEST, rustc_variance, Normal, template!(Word), WarnFollowing),
690 rustc_attr!(TEST, rustc_layout, Normal, template!(List: "field1, field2, ..."), WarnFollowing),
691 rustc_attr!(TEST, rustc_regions, Normal, template!(Word), WarnFollowing),
693 TEST, rustc_error, Normal,
694 template!(Word, List: "delay_span_bug_from_inside_query"), WarnFollowingWordOnly
696 rustc_attr!(TEST, rustc_dump_user_substs, Normal, template!(Word), WarnFollowing),
697 rustc_attr!(TEST, rustc_evaluate_where_clauses, Normal, template!(Word), WarnFollowing),
699 TEST, rustc_if_this_changed, Normal, template!(Word, List: "DepNode"), DuplicatesOk
702 TEST, rustc_then_this_would_need, Normal, template!(List: "DepNode"), DuplicatesOk
705 TEST, rustc_clean, Normal,
706 template!(List: r#"cfg = "...", /*opt*/ label = "...", /*opt*/ except = "...""#),
710 TEST, rustc_partition_reused, Normal,
711 template!(List: r#"cfg = "...", module = "...""#), DuplicatesOk,
714 TEST, rustc_partition_codegened, Normal,
715 template!(List: r#"cfg = "...", module = "...""#), DuplicatesOk,
718 TEST, rustc_expected_cgu_reuse, Normal,
719 template!(List: r#"cfg = "...", module = "...", kind = "...""#), DuplicatesOk,
721 rustc_attr!(TEST, rustc_symbol_name, Normal, template!(Word), WarnFollowing),
722 rustc_attr!(TEST, rustc_polymorphize_error, Normal, template!(Word), WarnFollowing),
723 rustc_attr!(TEST, rustc_def_path, Normal, template!(Word), WarnFollowing),
724 rustc_attr!(TEST, rustc_mir, Normal, template!(List: "arg1, arg2, ..."), DuplicatesOk),
725 rustc_attr!(TEST, rustc_dump_program_clauses, Normal, template!(Word), WarnFollowing),
726 rustc_attr!(TEST, rustc_dump_env_program_clauses, Normal, template!(Word), WarnFollowing),
727 rustc_attr!(TEST, rustc_object_lifetime_default, Normal, template!(Word), WarnFollowing),
728 rustc_attr!(TEST, rustc_dump_vtable, Normal, template!(Word), WarnFollowing),
729 rustc_attr!(TEST, rustc_dummy, Normal, template!(Word /* doesn't matter*/), DuplicatesOk),
731 omit_gdb_pretty_printer_section, Normal, template!(Word), WarnFollowing,
732 "the `#[omit_gdb_pretty_printer_section]` attribute is just used for the Rust test suite",
736 pub fn deprecated_attributes() -> Vec<&'static BuiltinAttribute> {
737 BUILTIN_ATTRIBUTES.iter().filter(|attr| attr.gate.is_deprecated()).collect()
740 pub fn is_builtin_attr_name(name: Symbol) -> bool {
741 BUILTIN_ATTRIBUTE_MAP.get(&name).is_some()
744 pub static BUILTIN_ATTRIBUTE_MAP: SyncLazy<FxHashMap<Symbol, &BuiltinAttribute>> =
746 let mut map = FxHashMap::default();
747 for attr in BUILTIN_ATTRIBUTES.iter() {
748 if map.insert(attr.name, attr).is_some() {
749 panic!("duplicate builtin attribute `{}`", attr.name);