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