]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_feature/src/builtin_attrs.rs
Auto merge of #87515 - crlf0710:trait_upcasting_part2, r=bjorn3
[rust.git] / compiler / rustc_feature / src / builtin_attrs.rs
1 //! Built-in attributes and `cfg` flag gating.
2
3 use AttributeGate::*;
4 use AttributeType::*;
5
6 use crate::{Features, Stability};
7
8 use rustc_data_structures::fx::FxHashMap;
9 use rustc_span::symbol::{sym, Symbol};
10
11 use std::lazy::SyncLazy;
12
13 type GateFn = fn(&Features) -> bool;
14
15 macro_rules! cfg_fn {
16     ($field: ident) => {
17         (|features| features.$field) as GateFn
18     };
19 }
20
21 pub type GatedCfg = (Symbol, Symbol, GateFn);
22
23 /// `cfg(...)`'s that are feature gated.
24 const GATED_CFGS: &[GatedCfg] = &[
25     // (name in cfg, feature, function to check if the feature is enabled)
26     (sym::target_abi, sym::cfg_target_abi, cfg_fn!(cfg_target_abi)),
27     (sym::target_thread_local, sym::cfg_target_thread_local, cfg_fn!(cfg_target_thread_local)),
28     (sym::target_has_atomic, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
29     (sym::target_has_atomic_load_store, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
30     (
31         sym::target_has_atomic_equal_alignment,
32         sym::cfg_target_has_atomic,
33         cfg_fn!(cfg_target_has_atomic),
34     ),
35     (sym::sanitize, sym::cfg_sanitize, cfg_fn!(cfg_sanitize)),
36     (sym::version, sym::cfg_version, cfg_fn!(cfg_version)),
37     (sym::panic, sym::cfg_panic, cfg_fn!(cfg_panic)),
38 ];
39
40 /// Find a gated cfg determined by the `pred`icate which is given the cfg's name.
41 pub fn find_gated_cfg(pred: impl Fn(Symbol) -> bool) -> Option<&'static GatedCfg> {
42     GATED_CFGS.iter().find(|(cfg_sym, ..)| pred(*cfg_sym))
43 }
44
45 // If you change this, please modify `src/doc/unstable-book` as well. You must
46 // move that documentation into the relevant place in the other docs, and
47 // remove the chapter on the flag.
48
49 #[derive(Copy, Clone, PartialEq, Debug)]
50 pub enum AttributeType {
51     /// Normal, builtin attribute that is consumed
52     /// by the compiler before the unused_attribute check
53     Normal,
54
55     /// Builtin attribute that may not be consumed by the compiler
56     /// before the unused_attribute check. These attributes
57     /// will be ignored by the unused_attribute lint
58     AssumedUsed,
59
60     /// Builtin attribute that is only allowed at the crate level
61     CrateLevel,
62 }
63
64 #[derive(Clone, Copy)]
65 pub enum AttributeGate {
66     /// Is gated by a given feature gate, reason
67     /// and function to check if enabled
68     Gated(Stability, Symbol, &'static str, fn(&Features) -> bool),
69
70     /// Ungated attribute, can be used on all release channels
71     Ungated,
72 }
73
74 // fn() is not Debug
75 impl std::fmt::Debug for AttributeGate {
76     fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
77         match *self {
78             Self::Gated(ref stab, name, expl, _) => {
79                 write!(fmt, "Gated({:?}, {}, {})", stab, name, expl)
80             }
81             Self::Ungated => write!(fmt, "Ungated"),
82         }
83     }
84 }
85
86 impl AttributeGate {
87     fn is_deprecated(&self) -> bool {
88         matches!(*self, Self::Gated(Stability::Deprecated(_, _), ..))
89     }
90 }
91
92 /// A template that the attribute input must match.
93 /// Only top-level shape (`#[attr]` vs `#[attr(...)]` vs `#[attr = ...]`) is considered now.
94 #[derive(Clone, Copy, Default)]
95 pub struct AttributeTemplate {
96     pub word: bool,
97     pub list: Option<&'static str>,
98     pub name_value_str: Option<&'static str>,
99 }
100
101 /// A convenience macro for constructing attribute templates.
102 /// E.g., `template!(Word, List: "description")` means that the attribute
103 /// supports forms `#[attr]` and `#[attr(description)]`.
104 macro_rules! template {
105     (Word) => { template!(@ true, None, None) };
106     (List: $descr: expr) => { template!(@ false, Some($descr), None) };
107     (NameValueStr: $descr: expr) => { template!(@ false, None, Some($descr)) };
108     (Word, List: $descr: expr) => { template!(@ true, Some($descr), None) };
109     (Word, NameValueStr: $descr: expr) => { template!(@ true, None, Some($descr)) };
110     (List: $descr1: expr, NameValueStr: $descr2: expr) => {
111         template!(@ false, Some($descr1), Some($descr2))
112     };
113     (Word, List: $descr1: expr, NameValueStr: $descr2: expr) => {
114         template!(@ true, Some($descr1), Some($descr2))
115     };
116     (@ $word: expr, $list: expr, $name_value_str: expr) => { AttributeTemplate {
117         word: $word, list: $list, name_value_str: $name_value_str
118     } };
119 }
120
121 macro_rules! ungated {
122     ($attr:ident, $typ:expr, $tpl:expr $(,)?) => {
123         (sym::$attr, $typ, $tpl, Ungated)
124     };
125 }
126
127 macro_rules! gated {
128     ($attr:ident, $typ:expr, $tpl:expr, $gate:ident, $msg:expr $(,)?) => {
129         (sym::$attr, $typ, $tpl, Gated(Stability::Unstable, sym::$gate, $msg, cfg_fn!($gate)))
130     };
131     ($attr:ident, $typ:expr, $tpl:expr, $msg:expr $(,)?) => {
132         (sym::$attr, $typ, $tpl, Gated(Stability::Unstable, sym::$attr, $msg, cfg_fn!($attr)))
133     };
134 }
135
136 macro_rules! rustc_attr {
137     (TEST, $attr:ident, $typ:expr, $tpl:expr $(,)?) => {
138         rustc_attr!(
139             $attr,
140             $typ,
141             $tpl,
142             concat!(
143                 "the `#[",
144                 stringify!($attr),
145                 "]` attribute is just used for rustc unit tests \
146                 and will never be stable",
147             ),
148         )
149     };
150     ($attr:ident, $typ:expr, $tpl:expr, $msg:expr $(,)?) => {
151         (
152             sym::$attr,
153             $typ,
154             $tpl,
155             Gated(Stability::Unstable, sym::rustc_attrs, $msg, cfg_fn!(rustc_attrs)),
156         )
157     };
158 }
159
160 macro_rules! experimental {
161     ($attr:ident) => {
162         concat!("the `#[", stringify!($attr), "]` attribute is an experimental feature")
163     };
164 }
165
166 const IMPL_DETAIL: &str = "internal implementation detail";
167 const INTERNAL_UNSTABLE: &str = "this is an internal attribute that will never be stable";
168
169 pub type BuiltinAttribute = (Symbol, AttributeType, AttributeTemplate, AttributeGate);
170
171 /// Attributes that have a special meaning to rustc or rustdoc.
172 #[rustfmt::skip]
173 pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
174     // ==========================================================================
175     // Stable attributes:
176     // ==========================================================================
177
178     // Conditional compilation:
179     ungated!(cfg, Normal, template!(List: "predicate")),
180     ungated!(cfg_attr, Normal, template!(List: "predicate, attr1, attr2, ...")),
181
182     // Testing:
183     ungated!(ignore, Normal, template!(Word, NameValueStr: "reason")),
184     ungated!(
185         should_panic, Normal,
186         template!(Word, List: r#"expected = "reason"#, NameValueStr: "reason"),
187     ),
188     // FIXME(Centril): This can be used on stable but shouldn't.
189     ungated!(reexport_test_harness_main, Normal, template!(NameValueStr: "name")),
190
191     // Macros:
192     ungated!(automatically_derived, Normal, template!(Word)),
193     // FIXME(#14407)
194     ungated!(macro_use, Normal, template!(Word, List: "name1, name2, ...")),
195     ungated!(macro_escape, Normal, template!(Word)), // Deprecated synonym for `macro_use`.
196     ungated!(macro_export, Normal, template!(Word, List: "local_inner_macros")),
197     ungated!(proc_macro, Normal, template!(Word)),
198     ungated!(
199         proc_macro_derive, Normal,
200         template!(List: "TraitName, /*opt*/ attributes(name1, name2, ...)"),
201     ),
202     ungated!(proc_macro_attribute, Normal, template!(Word)),
203
204     // Lints:
205     ungated!(warn, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)),
206     ungated!(allow, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)),
207     ungated!(forbid, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)),
208     ungated!(deny, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)),
209     ungated!(must_use, AssumedUsed, template!(Word, NameValueStr: "reason")),
210     // FIXME(#14407)
211     ungated!(
212         deprecated, Normal,
213         template!(
214             Word,
215             List: r#"/*opt*/ since = "version", /*opt*/ note = "reason""#,
216             NameValueStr: "reason"
217         ),
218     ),
219
220     // Crate properties:
221     ungated!(crate_name, CrateLevel, template!(NameValueStr: "name")),
222     ungated!(crate_type, CrateLevel, template!(NameValueStr: "bin|lib|...")),
223     ungated!(crate_id, CrateLevel, template!(NameValueStr: "ignored")),
224
225     // ABI, linking, symbols, and FFI
226     ungated!(
227         link, AssumedUsed,
228         template!(List: r#"name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...""#),
229     ),
230     ungated!(link_name, AssumedUsed, template!(NameValueStr: "name")),
231     ungated!(no_link, AssumedUsed, template!(Word)),
232     ungated!(repr, AssumedUsed, template!(List: "C")),
233     ungated!(export_name, AssumedUsed, template!(NameValueStr: "name")),
234     ungated!(link_section, AssumedUsed, template!(NameValueStr: "name")),
235     ungated!(no_mangle, AssumedUsed, template!(Word)),
236     ungated!(used, AssumedUsed, template!(Word)),
237
238     // Limits:
239     ungated!(recursion_limit, CrateLevel, template!(NameValueStr: "N")),
240     ungated!(type_length_limit, CrateLevel, template!(NameValueStr: "N")),
241     gated!(
242         const_eval_limit, CrateLevel, template!(NameValueStr: "N"), const_eval_limit,
243         experimental!(const_eval_limit)
244     ),
245     gated!(
246         move_size_limit, CrateLevel, template!(NameValueStr: "N"), large_assignments,
247         experimental!(move_size_limit)
248     ),
249
250     // Entry point:
251     ungated!(main, Normal, template!(Word)),
252     ungated!(start, Normal, template!(Word)),
253     ungated!(no_start, CrateLevel, template!(Word)),
254     ungated!(no_main, CrateLevel, template!(Word)),
255
256     // Modules, prelude, and resolution:
257     ungated!(path, Normal, template!(NameValueStr: "file")),
258     ungated!(no_std, CrateLevel, template!(Word)),
259     ungated!(no_implicit_prelude, Normal, template!(Word)),
260     ungated!(non_exhaustive, AssumedUsed, template!(Word)),
261
262     // Runtime
263     ungated!(windows_subsystem, AssumedUsed, template!(NameValueStr: "windows|console")),
264     ungated!(panic_handler, Normal, template!(Word)), // RFC 2070
265
266     // Code generation:
267     ungated!(inline, AssumedUsed, template!(Word, List: "always|never")),
268     ungated!(cold, AssumedUsed, template!(Word)),
269     ungated!(no_builtins, AssumedUsed, template!(Word)),
270     ungated!(target_feature, AssumedUsed, template!(List: r#"enable = "name""#)),
271     ungated!(track_caller, AssumedUsed, template!(Word)),
272     gated!(
273         no_sanitize, AssumedUsed,
274         template!(List: "address, memory, thread"),
275         experimental!(no_sanitize)
276     ),
277     gated!(no_coverage, AssumedUsed, template!(Word), experimental!(no_coverage)),
278
279     // FIXME: #14408 assume docs are used since rustdoc looks at them.
280     ungated!(doc, AssumedUsed, template!(List: "hidden|inline|...", NameValueStr: "string")),
281
282     // ==========================================================================
283     // Unstable attributes:
284     // ==========================================================================
285
286     // Linking:
287     gated!(naked, AssumedUsed, template!(Word), naked_functions, experimental!(naked)),
288     gated!(
289         link_ordinal, AssumedUsed, template!(List: "ordinal"), raw_dylib,
290         experimental!(link_ordinal)
291     ),
292
293     // Plugins:
294     (
295         sym::plugin_registrar, Normal, template!(Word),
296         Gated(
297             Stability::Deprecated(
298                 "https://github.com/rust-lang/rust/pull/64675",
299                 Some("may be removed in a future compiler version"),
300             ),
301             sym::plugin_registrar,
302             "compiler plugins are deprecated",
303             cfg_fn!(plugin_registrar)
304         )
305     ),
306     (
307         sym::plugin, CrateLevel, template!(List: "name"),
308         Gated(
309             Stability::Deprecated(
310                 "https://github.com/rust-lang/rust/pull/64675",
311                 Some("may be removed in a future compiler version"),
312             ),
313             sym::plugin,
314             "compiler plugins are deprecated",
315             cfg_fn!(plugin)
316         )
317     ),
318
319     // Testing:
320     gated!(allow_fail, Normal, template!(Word), experimental!(allow_fail)),
321     gated!(
322         test_runner, CrateLevel, template!(List: "path"), custom_test_frameworks,
323         "custom test frameworks are an unstable feature",
324     ),
325     // RFC #1268
326     gated!(marker, AssumedUsed, template!(Word), marker_trait_attr, experimental!(marker)),
327     gated!(
328         thread_local, AssumedUsed, template!(Word),
329         "`#[thread_local]` is an experimental feature, and does not currently handle destructors",
330     ),
331     gated!(no_core, CrateLevel, template!(Word), experimental!(no_core)),
332     // RFC 2412
333     gated!(
334         optimize, AssumedUsed, template!(List: "size|speed"), optimize_attribute,
335         experimental!(optimize),
336     ),
337     // RFC 2867
338     gated!(instruction_set, AssumedUsed, template!(List: "set"), isa_attribute, experimental!(instruction_set)),
339
340     gated!(ffi_returns_twice, AssumedUsed, template!(Word), experimental!(ffi_returns_twice)),
341     gated!(ffi_pure, AssumedUsed, template!(Word), experimental!(ffi_pure)),
342     gated!(ffi_const, AssumedUsed, template!(Word), experimental!(ffi_const)),
343     gated!(
344         register_attr, CrateLevel, template!(List: "attr1, attr2, ..."),
345         experimental!(register_attr),
346     ),
347     gated!(
348         register_tool, CrateLevel, template!(List: "tool1, tool2, ..."),
349         experimental!(register_tool),
350     ),
351
352     gated!(cmse_nonsecure_entry, AssumedUsed, template!(Word), experimental!(cmse_nonsecure_entry)),
353     // RFC 2632
354     gated!(
355         default_method_body_is_const, AssumedUsed, template!(Word), const_trait_impl,
356         "`default_method_body_is_const` is a temporary placeholder for declaring default bodies \
357         as `const`, which may be removed or renamed in the future."
358     ),
359
360     // ==========================================================================
361     // Internal attributes: Stability, deprecation, and unsafe:
362     // ==========================================================================
363
364     ungated!(feature, CrateLevel, template!(List: "name1, name1, ...")),
365     // FIXME(#14407) -- only looked at on-demand so we can't
366     // guarantee they'll have already been checked.
367     ungated!(
368         rustc_deprecated, AssumedUsed,
369         template!(List: r#"since = "version", reason = "...""#)
370     ),
371     // FIXME(#14407)
372     ungated!(stable, AssumedUsed, template!(List: r#"feature = "name", since = "version""#)),
373     // FIXME(#14407)
374     ungated!(
375         unstable, AssumedUsed,
376         template!(List: r#"feature = "name", reason = "...", issue = "N""#),
377     ),
378     // FIXME(#14407)
379     ungated!(rustc_const_unstable, AssumedUsed, template!(List: r#"feature = "name""#)),
380     // FIXME(#14407)
381     ungated!(rustc_const_stable, AssumedUsed, template!(List: r#"feature = "name""#)),
382     gated!(
383         allow_internal_unstable, AssumedUsed, template!(Word, List: "feat1, feat2, ..."),
384         "allow_internal_unstable side-steps feature gating and stability checks",
385     ),
386     gated!(
387         rustc_allow_const_fn_unstable, AssumedUsed, template!(Word, List: "feat1, feat2, ..."),
388         "rustc_allow_const_fn_unstable side-steps feature gating and stability checks"
389     ),
390     gated!(
391         allow_internal_unsafe, Normal, template!(Word),
392         "allow_internal_unsafe side-steps the unsafe_code lint",
393     ),
394
395     // ==========================================================================
396     // Internal attributes: Type system related:
397     // ==========================================================================
398
399     gated!(fundamental, AssumedUsed, template!(Word), experimental!(fundamental)),
400     gated!(
401         may_dangle, Normal, template!(Word), dropck_eyepatch,
402         "`may_dangle` has unstable semantics and may be removed in the future",
403     ),
404
405     // ==========================================================================
406     // Internal attributes: Runtime related:
407     // ==========================================================================
408
409     rustc_attr!(rustc_allocator, AssumedUsed, template!(Word), IMPL_DETAIL),
410     rustc_attr!(rustc_allocator_nounwind, AssumedUsed, template!(Word), IMPL_DETAIL),
411     gated!(alloc_error_handler, Normal, template!(Word), experimental!(alloc_error_handler)),
412     gated!(
413         default_lib_allocator, AssumedUsed, template!(Word), allocator_internals,
414         experimental!(default_lib_allocator),
415     ),
416     gated!(
417         needs_allocator, Normal, template!(Word), allocator_internals,
418         experimental!(needs_allocator),
419     ),
420     gated!(panic_runtime, AssumedUsed, template!(Word), experimental!(panic_runtime)),
421     gated!(needs_panic_runtime, AssumedUsed, template!(Word), experimental!(needs_panic_runtime)),
422     gated!(
423         unwind, AssumedUsed, template!(List: "allowed|aborts"), unwind_attributes,
424         experimental!(unwind),
425     ),
426     gated!(
427         compiler_builtins, AssumedUsed, template!(Word),
428         "the `#[compiler_builtins]` attribute is used to identify the `compiler_builtins` crate \
429         which contains compiler-rt intrinsics and will never be stable",
430     ),
431     gated!(
432         profiler_runtime, AssumedUsed, template!(Word),
433         "the `#[profiler_runtime]` attribute is used to identify the `profiler_builtins` crate \
434         which contains the profiler runtime and will never be stable",
435     ),
436
437     // ==========================================================================
438     // Internal attributes, Linkage:
439     // ==========================================================================
440
441     gated!(
442         linkage, AssumedUsed, template!(NameValueStr: "external|internal|..."),
443         "the `linkage` attribute is experimental and not portable across platforms",
444     ),
445     rustc_attr!(rustc_std_internal_symbol, AssumedUsed, template!(Word), INTERNAL_UNSTABLE),
446
447     // ==========================================================================
448     // Internal attributes, Macro related:
449     // ==========================================================================
450
451     rustc_attr!(
452         rustc_builtin_macro, AssumedUsed,
453         template!(Word, List: "name, /*opt*/ attributes(name1, name2, ...)"),
454         IMPL_DETAIL,
455     ),
456     rustc_attr!(rustc_proc_macro_decls, Normal, template!(Word), INTERNAL_UNSTABLE),
457     rustc_attr!(
458         rustc_macro_transparency, AssumedUsed,
459         template!(NameValueStr: "transparent|semitransparent|opaque"),
460         "used internally for testing macro hygiene",
461     ),
462
463     // ==========================================================================
464     // Internal attributes, Diagnostics related:
465     // ==========================================================================
466
467     rustc_attr!(
468         rustc_on_unimplemented, AssumedUsed,
469         template!(
470             List: r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#,
471             NameValueStr: "message"
472         ),
473         INTERNAL_UNSTABLE
474     ),
475     // Enumerates "identity-like" conversion methods to suggest on type mismatch.
476     rustc_attr!(rustc_conversion_suggestion, AssumedUsed, template!(Word), INTERNAL_UNSTABLE),
477
478     // ==========================================================================
479     // Internal attributes, Const related:
480     // ==========================================================================
481
482     rustc_attr!(rustc_promotable, AssumedUsed, template!(Word), IMPL_DETAIL),
483     rustc_attr!(rustc_legacy_const_generics, AssumedUsed, template!(List: "N"), INTERNAL_UNSTABLE),
484
485     // ==========================================================================
486     // Internal attributes, Layout related:
487     // ==========================================================================
488
489     rustc_attr!(
490         rustc_layout_scalar_valid_range_start, AssumedUsed, template!(List: "value"),
491         "the `#[rustc_layout_scalar_valid_range_start]` attribute is just used to enable \
492         niche optimizations in libcore and will never be stable",
493     ),
494     rustc_attr!(
495         rustc_layout_scalar_valid_range_end, AssumedUsed, template!(List: "value"),
496         "the `#[rustc_layout_scalar_valid_range_end]` attribute is just used to enable \
497         niche optimizations in libcore and will never be stable",
498     ),
499     rustc_attr!(
500         rustc_nonnull_optimization_guaranteed, AssumedUsed, template!(Word),
501         "the `#[rustc_nonnull_optimization_guaranteed]` attribute is just used to enable \
502         niche optimizations in libcore and will never be stable",
503     ),
504
505     // ==========================================================================
506     // Internal attributes, Misc:
507     // ==========================================================================
508     gated!(
509         lang, Normal, template!(NameValueStr: "name"), lang_items,
510         "language items are subject to change",
511     ),
512     (
513         sym::rustc_diagnostic_item,
514         Normal,
515         template!(NameValueStr: "name"),
516         Gated(
517             Stability::Unstable,
518             sym::rustc_attrs,
519             "diagnostic items compiler internal support for linting",
520             cfg_fn!(rustc_attrs),
521         ),
522     ),
523     gated!(
524         // Used in resolve:
525         prelude_import, AssumedUsed, template!(Word),
526         "`#[prelude_import]` is for use by rustc only",
527     ),
528     gated!(
529         rustc_paren_sugar, Normal, template!(Word), unboxed_closures,
530         "unboxed_closures are still evolving",
531     ),
532     rustc_attr!(
533         rustc_inherit_overflow_checks, AssumedUsed, template!(Word),
534         "the `#[rustc_inherit_overflow_checks]` attribute is just used to control \
535         overflow checking behavior of several libcore functions that are inlined \
536         across crates and will never be stable",
537     ),
538     rustc_attr!(rustc_reservation_impl, Normal, template!(NameValueStr: "reservation message"),
539                 "the `#[rustc_reservation_impl]` attribute is internally used \
540                  for reserving for `for<T> From<!> for T` impl"
541     ),
542     rustc_attr!(
543         rustc_test_marker, Normal, template!(Word),
544         "the `#[rustc_test_marker]` attribute is used internally to track tests",
545     ),
546     rustc_attr!(
547         rustc_unsafe_specialization_marker, Normal, template!(Word),
548         "the `#[rustc_unsafe_specialization_marker]` attribute is used to check specializations"
549     ),
550     rustc_attr!(
551         rustc_specialization_trait, Normal, template!(Word),
552         "the `#[rustc_specialization_trait]` attribute is used to check specializations"
553     ),
554     rustc_attr!(
555         rustc_main, Normal, template!(Word),
556         "the `#[rustc_main]` attribute is used internally to specify test entry point function",
557     ),
558     rustc_attr!(
559         rustc_skip_array_during_method_dispatch, Normal, template!(Word),
560         "the `#[rustc_skip_array_during_method_dispatch]` attribute is used to exclude a trait \
561         from method dispatch when the receiver is an array, for compatibility in editions < 2021."
562     ),
563
564     // ==========================================================================
565     // Internal attributes, Testing:
566     // ==========================================================================
567
568     rustc_attr!(TEST, rustc_outlives, Normal, template!(Word)),
569     rustc_attr!(TEST, rustc_capture_analysis, Normal, template!(Word)),
570     rustc_attr!(TEST, rustc_insignificant_dtor, Normal, template!(Word)),
571     rustc_attr!(TEST, rustc_variance, Normal, template!(Word)),
572     rustc_attr!(TEST, rustc_layout, Normal, template!(List: "field1, field2, ...")),
573     rustc_attr!(TEST, rustc_regions, Normal, template!(Word)),
574     rustc_attr!(
575         TEST, rustc_error, AssumedUsed,
576         template!(Word, List: "delay_span_bug_from_inside_query")
577     ),
578     rustc_attr!(TEST, rustc_dump_user_substs, AssumedUsed, template!(Word)),
579     rustc_attr!(TEST, rustc_evaluate_where_clauses, AssumedUsed, template!(Word)),
580     rustc_attr!(TEST, rustc_if_this_changed, AssumedUsed, template!(Word, List: "DepNode")),
581     rustc_attr!(TEST, rustc_then_this_would_need, AssumedUsed, template!(List: "DepNode")),
582     rustc_attr!(
583         TEST, rustc_clean, AssumedUsed,
584         template!(List: r#"cfg = "...", /*opt*/ label = "...", /*opt*/ except = "...""#),
585     ),
586     rustc_attr!(
587         TEST, rustc_partition_reused, AssumedUsed,
588         template!(List: r#"cfg = "...", module = "...""#),
589     ),
590     rustc_attr!(
591         TEST, rustc_partition_codegened, AssumedUsed,
592         template!(List: r#"cfg = "...", module = "...""#),
593     ),
594     rustc_attr!(
595         TEST, rustc_expected_cgu_reuse, AssumedUsed,
596         template!(List: r#"cfg = "...", module = "...", kind = "...""#),
597     ),
598     rustc_attr!(TEST, rustc_synthetic, AssumedUsed, template!(Word)),
599     rustc_attr!(TEST, rustc_symbol_name, AssumedUsed, template!(Word)),
600     rustc_attr!(TEST, rustc_polymorphize_error, AssumedUsed, template!(Word)),
601     rustc_attr!(TEST, rustc_def_path, AssumedUsed, template!(Word)),
602     rustc_attr!(TEST, rustc_mir, AssumedUsed, template!(List: "arg1, arg2, ...")),
603     rustc_attr!(TEST, rustc_dump_program_clauses, AssumedUsed, template!(Word)),
604     rustc_attr!(TEST, rustc_dump_env_program_clauses, AssumedUsed, template!(Word)),
605     rustc_attr!(TEST, rustc_object_lifetime_default, AssumedUsed, template!(Word)),
606     rustc_attr!(TEST, rustc_dump_vtable, AssumedUsed, template!(Word)),
607     rustc_attr!(TEST, rustc_dummy, Normal, template!(Word /* doesn't matter*/)),
608     gated!(
609         omit_gdb_pretty_printer_section, AssumedUsed, template!(Word),
610         "the `#[omit_gdb_pretty_printer_section]` attribute is just used for the Rust test suite",
611     ),
612 ];
613
614 pub fn deprecated_attributes() -> Vec<&'static BuiltinAttribute> {
615     BUILTIN_ATTRIBUTES.iter().filter(|(.., gate)| gate.is_deprecated()).collect()
616 }
617
618 pub fn is_builtin_attr_name(name: Symbol) -> bool {
619     BUILTIN_ATTRIBUTE_MAP.get(&name).is_some()
620 }
621
622 pub static BUILTIN_ATTRIBUTE_MAP: SyncLazy<FxHashMap<Symbol, &BuiltinAttribute>> =
623     SyncLazy::new(|| {
624         let mut map = FxHashMap::default();
625         for attr in BUILTIN_ATTRIBUTES.iter() {
626             if map.insert(attr.0, attr).is_some() {
627                 panic!("duplicate builtin attribute `{}`", attr.0);
628             }
629         }
630         map
631     });