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