]> git.lizzy.rs Git - rust.git/blob - src/librustc_feature/builtin_attrs.rs
Rollup merge of #72033 - XAMPPRocky:relnotes-1.44.0, r=Mark-Simulacrum
[rust.git] / src / librustc_feature / 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 lazy_static::lazy_static;
9 use rustc_data_structures::fx::FxHashMap;
10 use rustc_span::symbol::{sym, Symbol};
11
12 type GateFn = fn(&Features) -> bool;
13
14 macro_rules! cfg_fn {
15     ($field: ident) => {
16         (|features| features.$field) as GateFn
17     };
18 }
19
20 pub type GatedCfg = (Symbol, Symbol, GateFn);
21
22 /// `cfg(...)`'s that are feature gated.
23 const GATED_CFGS: &[GatedCfg] = &[
24     // (name in cfg, feature, function to check if the feature is enabled)
25     (sym::target_thread_local, sym::cfg_target_thread_local, cfg_fn!(cfg_target_thread_local)),
26     (sym::target_has_atomic, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
27     (sym::target_has_atomic_load_store, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
28     (sym::sanitize, sym::cfg_sanitize, cfg_fn!(cfg_sanitize)),
29     (sym::version, sym::cfg_version, cfg_fn!(cfg_version)),
30 ];
31
32 /// Find a gated cfg determined by the `pred`icate which is given the cfg's name.
33 pub fn find_gated_cfg(pred: impl Fn(Symbol) -> bool) -> Option<&'static GatedCfg> {
34     GATED_CFGS.iter().find(|(cfg_sym, ..)| pred(*cfg_sym))
35 }
36
37 // If you change this, please modify `src/doc/unstable-book` as well. You must
38 // move that documentation into the relevant place in the other docs, and
39 // remove the chapter on the flag.
40
41 #[derive(Copy, Clone, PartialEq, Debug)]
42 pub enum AttributeType {
43     /// Normal, builtin attribute that is consumed
44     /// by the compiler before the unused_attribute check
45     Normal,
46
47     /// Builtin attribute that may not be consumed by the compiler
48     /// before the unused_attribute check. These attributes
49     /// will be ignored by the unused_attribute lint
50     Whitelisted,
51
52     /// Builtin attribute that is only allowed at the crate level
53     CrateLevel,
54 }
55
56 #[derive(Clone, Copy)]
57 pub enum AttributeGate {
58     /// Is gated by a given feature gate, reason
59     /// and function to check if enabled
60     Gated(Stability, Symbol, &'static str, fn(&Features) -> bool),
61
62     /// Ungated attribute, can be used on all release channels
63     Ungated,
64 }
65
66 // fn() is not Debug
67 impl std::fmt::Debug for AttributeGate {
68     fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
69         match *self {
70             Self::Gated(ref stab, name, expl, _) => {
71                 write!(fmt, "Gated({:?}, {}, {})", stab, name, expl)
72             }
73             Self::Ungated => write!(fmt, "Ungated"),
74         }
75     }
76 }
77
78 impl AttributeGate {
79     fn is_deprecated(&self) -> bool {
80         match *self {
81             Self::Gated(Stability::Deprecated(_, _), ..) => true,
82             _ => false,
83         }
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, Normal, template!(NameValueStr: "name")),
185
186     // Macros:
187     ungated!(derive, Normal, template!(List: "Trait1, Trait2, ...")),
188     ungated!(automatically_derived, Normal, template!(Word)),
189     // FIXME(#14407)
190     ungated!(macro_use, Normal, template!(Word, List: "name1, name2, ...")),
191     ungated!(macro_escape, Normal, template!(Word)), // Deprecated synonym for `macro_use`.
192     ungated!(macro_export, Normal, template!(Word, List: "local_inner_macros")),
193     ungated!(proc_macro, Normal, template!(Word)),
194     ungated!(
195         proc_macro_derive, Normal,
196         template!(List: "TraitName, /*opt*/ attributes(name1, name2, ...)"),
197     ),
198     ungated!(proc_macro_attribute, Normal, template!(Word)),
199
200     // Lints:
201     ungated!(warn, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)),
202     ungated!(allow, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)),
203     ungated!(forbid, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)),
204     ungated!(deny, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)),
205     ungated!(must_use, Whitelisted, template!(Word, NameValueStr: "reason")),
206     // FIXME(#14407)
207     ungated!(
208         deprecated, Normal,
209         template!(
210             Word,
211             List: r#"/*opt*/ since = "version", /*opt*/ note = "reason""#,
212             NameValueStr: "reason"
213         ),
214     ),
215
216     // Crate properties:
217     ungated!(crate_name, CrateLevel, template!(NameValueStr: "name")),
218     ungated!(crate_type, CrateLevel, template!(NameValueStr: "bin|lib|...")),
219     ungated!(crate_id, CrateLevel, template!(NameValueStr: "ignored")),
220
221     // ABI, linking, symbols, and FFI
222     ungated!(
223         link, Whitelisted,
224         template!(List: r#"name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...""#),
225     ),
226     ungated!(link_name, Whitelisted, template!(NameValueStr: "name")),
227     ungated!(no_link, Normal, template!(Word)),
228     ungated!(repr, Normal, template!(List: "C")),
229     ungated!(export_name, Whitelisted, template!(NameValueStr: "name")),
230     ungated!(link_section, Whitelisted, template!(NameValueStr: "name")),
231     ungated!(no_mangle, Whitelisted, template!(Word)),
232     ungated!(used, Whitelisted, template!(Word)),
233
234     // Limits:
235     ungated!(recursion_limit, CrateLevel, template!(NameValueStr: "N")),
236     ungated!(type_length_limit, CrateLevel, template!(NameValueStr: "N")),
237     gated!(
238         const_eval_limit, CrateLevel, template!(NameValueStr: "N"), const_eval_limit,
239         experimental!(const_eval_limit)
240     ),
241
242     // Entry point:
243     ungated!(main, Normal, template!(Word)),
244     ungated!(start, Normal, template!(Word)),
245     ungated!(no_start, CrateLevel, template!(Word)),
246     ungated!(no_main, CrateLevel, template!(Word)),
247
248     // Modules, prelude, and resolution:
249     ungated!(path, Normal, template!(NameValueStr: "file")),
250     ungated!(no_std, CrateLevel, template!(Word)),
251     ungated!(no_implicit_prelude, Normal, template!(Word)),
252     ungated!(non_exhaustive, Whitelisted, template!(Word)),
253
254     // Runtime
255     ungated!(windows_subsystem, Whitelisted, template!(NameValueStr: "windows|console")),
256     ungated!(panic_handler, Normal, template!(Word)), // RFC 2070
257
258     // Code generation:
259     ungated!(inline, Whitelisted, template!(Word, List: "always|never")),
260     ungated!(cold, Whitelisted, template!(Word)),
261     ungated!(no_builtins, Whitelisted, template!(Word)),
262     ungated!(target_feature, Whitelisted, template!(List: r#"enable = "name""#)),
263     gated!(
264         no_sanitize, Whitelisted,
265         template!(List: "address, memory, thread"),
266         experimental!(no_sanitize)
267     ),
268
269     // FIXME: #14408 whitelist docs since rustdoc looks at them
270     ungated!(doc, Whitelisted, template!(List: "hidden|inline|...", NameValueStr: "string")),
271
272     // ==========================================================================
273     // Unstable attributes:
274     // ==========================================================================
275
276     // Linking:
277     gated!(naked, Whitelisted, template!(Word), naked_functions, experimental!(naked)),
278     gated!(
279         link_args, Normal, template!(NameValueStr: "args"),
280         "the `link_args` attribute is experimental and not portable across platforms, \
281         it is recommended to use `#[link(name = \"foo\")] instead",
282     ),
283     gated!(
284         link_ordinal, Whitelisted, template!(List: "ordinal"), raw_dylib,
285         experimental!(link_ordinal)
286     ),
287
288     // Plugins:
289     (
290         sym::plugin_registrar, Normal, template!(Word),
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_registrar,
297             "compiler plugins are deprecated",
298             cfg_fn!(plugin_registrar)
299         )
300     ),
301     (
302         sym::plugin, CrateLevel, template!(List: "name"),
303         Gated(
304             Stability::Deprecated(
305                 "https://github.com/rust-lang/rust/pull/64675",
306                 Some("may be removed in a future compiler version"),
307             ),
308             sym::plugin,
309             "compiler plugins are deprecated",
310             cfg_fn!(plugin)
311         )
312     ),
313
314     // Testing:
315     gated!(allow_fail, Normal, template!(Word), experimental!(allow_fail)),
316     gated!(
317         test_runner, CrateLevel, template!(List: "path"), custom_test_frameworks,
318         "custom test frameworks are an unstable feature",
319     ),
320     // RFC #1268
321     gated!(marker, Normal, template!(Word), marker_trait_attr, experimental!(marker)),
322     gated!(
323         thread_local, Whitelisted, template!(Word),
324         "`#[thread_local]` is an experimental feature, and does not currently handle destructors",
325     ),
326     gated!(no_core, CrateLevel, template!(Word), experimental!(no_core)),
327     // RFC 2412
328     gated!(
329         optimize, Whitelisted, template!(List: "size|speed"), optimize_attribute,
330         experimental!(optimize),
331     ),
332
333     gated!(ffi_returns_twice, Whitelisted, template!(Word), experimental!(ffi_returns_twice)),
334     gated!(ffi_pure, Whitelisted, template!(Word), experimental!(ffi_pure)),
335     gated!(ffi_const, Whitelisted, template!(Word), experimental!(ffi_const)),
336     gated!(track_caller, Whitelisted, template!(Word), experimental!(track_caller)),
337     gated!(
338         register_attr, CrateLevel, template!(List: "attr1, attr2, ..."),
339         experimental!(register_attr),
340     ),
341     gated!(
342         register_tool, CrateLevel, template!(List: "tool1, tool2, ..."),
343         experimental!(register_tool),
344     ),
345
346     // ==========================================================================
347     // Internal attributes: Stability, deprecation, and unsafe:
348     // ==========================================================================
349
350     ungated!(feature, CrateLevel, template!(List: "name1, name1, ...")),
351     // FIXME(#14407) -- only looked at on-demand so we can't
352     // guarantee they'll have already been checked.
353     ungated!(
354         rustc_deprecated, Whitelisted,
355         template!(List: r#"since = "version", reason = "...""#)
356     ),
357     // FIXME(#14407)
358     ungated!(stable, Whitelisted, template!(List: r#"feature = "name", since = "version""#)),
359     // FIXME(#14407)
360     ungated!(
361         unstable, Whitelisted,
362         template!(List: r#"feature = "name", reason = "...", issue = "N""#),
363     ),
364     // FIXME(#14407)
365     ungated!(rustc_const_unstable, Whitelisted, template!(List: r#"feature = "name""#)),
366     // FIXME(#14407)
367     ungated!(rustc_const_stable, Whitelisted, template!(List: r#"feature = "name""#)),
368     gated!(
369         allow_internal_unstable, Whitelisted, template!(Word, List: "feat1, feat2, ..."),
370         "allow_internal_unstable side-steps feature gating and stability checks",
371     ),
372     gated!(
373         allow_internal_unsafe, Normal, template!(Word),
374         "allow_internal_unsafe side-steps the unsafe_code lint",
375     ),
376
377     // ==========================================================================
378     // Internal attributes: Type system related:
379     // ==========================================================================
380
381     gated!(fundamental, Whitelisted, template!(Word), experimental!(fundamental)),
382     gated!(
383         may_dangle, Normal, template!(Word), dropck_eyepatch,
384         "`may_dangle` has unstable semantics and may be removed in the future",
385     ),
386
387     // ==========================================================================
388     // Internal attributes: Runtime related:
389     // ==========================================================================
390
391     rustc_attr!(rustc_allocator, Whitelisted, template!(Word), IMPL_DETAIL),
392     rustc_attr!(rustc_allocator_nounwind, Whitelisted, template!(Word), IMPL_DETAIL),
393     gated!(alloc_error_handler, Normal, template!(Word), experimental!(alloc_error_handler)),
394     gated!(
395         default_lib_allocator, Whitelisted, template!(Word), allocator_internals,
396         experimental!(default_lib_allocator),
397     ),
398     gated!(
399         needs_allocator, Normal, template!(Word), allocator_internals,
400         experimental!(needs_allocator),
401     ),
402     gated!(panic_runtime, Whitelisted, template!(Word), experimental!(panic_runtime)),
403     gated!(needs_panic_runtime, Whitelisted, template!(Word), experimental!(needs_panic_runtime)),
404     gated!(
405         unwind, Whitelisted, template!(List: "allowed|aborts"), unwind_attributes,
406         experimental!(unwind),
407     ),
408     gated!(
409         compiler_builtins, Whitelisted, template!(Word),
410         "the `#[compiler_builtins]` attribute is used to identify the `compiler_builtins` crate \
411         which contains compiler-rt intrinsics and will never be stable",
412     ),
413     gated!(
414         profiler_runtime, Whitelisted, template!(Word),
415         "the `#[profiler_runtime]` attribute is used to identify the `profiler_builtins` crate \
416         which contains the profiler runtime and will never be stable",
417     ),
418
419     // ==========================================================================
420     // Internal attributes, Linkage:
421     // ==========================================================================
422
423     gated!(
424         linkage, Whitelisted, template!(NameValueStr: "external|internal|..."),
425         "the `linkage` attribute is experimental and not portable across platforms",
426     ),
427     rustc_attr!(rustc_std_internal_symbol, Whitelisted, template!(Word), INTERNAL_UNSTABLE),
428
429     // ==========================================================================
430     // Internal attributes, Macro related:
431     // ==========================================================================
432
433     rustc_attr!(rustc_builtin_macro, Whitelisted, template!(Word), IMPL_DETAIL),
434     rustc_attr!(rustc_proc_macro_decls, Normal, template!(Word), INTERNAL_UNSTABLE),
435     rustc_attr!(
436         rustc_macro_transparency, Whitelisted,
437         template!(NameValueStr: "transparent|semitransparent|opaque"),
438         "used internally for testing macro hygiene",
439     ),
440
441     // ==========================================================================
442     // Internal attributes, Diagnostics related:
443     // ==========================================================================
444
445     rustc_attr!(
446         rustc_on_unimplemented, Whitelisted,
447         template!(
448             List: r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#,
449             NameValueStr: "message"
450         ),
451         INTERNAL_UNSTABLE
452     ),
453     // Whitelists "identity-like" conversion methods to suggest on type mismatch.
454     rustc_attr!(rustc_conversion_suggestion, Whitelisted, template!(Word), INTERNAL_UNSTABLE),
455
456     // ==========================================================================
457     // Internal attributes, Const related:
458     // ==========================================================================
459
460     rustc_attr!(rustc_promotable, Whitelisted, template!(Word), IMPL_DETAIL),
461     rustc_attr!(rustc_allow_const_fn_ptr, Whitelisted, template!(Word), IMPL_DETAIL),
462     rustc_attr!(rustc_args_required_const, Whitelisted, template!(List: "N"), INTERNAL_UNSTABLE),
463
464     // ==========================================================================
465     // Internal attributes, Layout related:
466     // ==========================================================================
467
468     rustc_attr!(
469         rustc_layout_scalar_valid_range_start, Whitelisted, template!(List: "value"),
470         "the `#[rustc_layout_scalar_valid_range_start]` attribute is just used to enable \
471         niche optimizations in libcore and will never be stable",
472     ),
473     rustc_attr!(
474         rustc_layout_scalar_valid_range_end, Whitelisted, template!(List: "value"),
475         "the `#[rustc_layout_scalar_valid_range_end]` attribute is just used to enable \
476         niche optimizations in libcore and will never be stable",
477     ),
478     rustc_attr!(
479         rustc_nonnull_optimization_guaranteed, Whitelisted, template!(Word),
480         "the `#[rustc_nonnull_optimization_guaranteed]` attribute is just used to enable \
481         niche optimizations in libcore and will never be stable",
482     ),
483
484     // ==========================================================================
485     // Internal attributes, Misc:
486     // ==========================================================================
487     gated!(
488         lang, Normal, template!(NameValueStr: "name"), lang_items,
489         "language items are subject to change",
490     ),
491     (
492         sym::rustc_diagnostic_item,
493         Normal,
494         template!(NameValueStr: "name"),
495         Gated(
496             Stability::Unstable,
497             sym::rustc_attrs,
498             "diagnostic items compiler internal support for linting",
499             cfg_fn!(rustc_attrs),
500         ),
501     ),
502     gated!(
503         // Used in resolve:
504         prelude_import, Whitelisted, template!(Word),
505         "`#[prelude_import]` is for use by rustc only",
506     ),
507     gated!(
508         rustc_paren_sugar, Normal, template!(Word), unboxed_closures,
509         "unboxed_closures are still evolving",
510     ),
511     rustc_attr!(
512         rustc_inherit_overflow_checks, Whitelisted, template!(Word),
513         "the `#[rustc_inherit_overflow_checks]` attribute is just used to control \
514         overflow checking behavior of several libcore functions that are inlined \
515         across crates and will never be stable",
516     ),
517     rustc_attr!(rustc_reservation_impl, Normal, template!(NameValueStr: "reservation message"),
518                 "the `#[rustc_reservation_impl]` attribute is internally used \
519                  for reserving for `for<T> From<!> for T` impl"
520     ),
521     rustc_attr!(
522         rustc_test_marker, Normal, template!(Word),
523         "the `#[rustc_test_marker]` attribute is used internally to track tests",
524     ),
525     rustc_attr!(
526         rustc_unsafe_specialization_marker, Normal, template!(Word),
527         "the `#[rustc_unsafe_specialization_marker]` attribute is used to check specializations"
528     ),
529     rustc_attr!(
530         rustc_specialization_trait, Normal, template!(Word),
531         "the `#[rustc_specialization_trait]` attribute is used to check specializations"
532     ),
533
534     // ==========================================================================
535     // Internal attributes, Testing:
536     // ==========================================================================
537
538     rustc_attr!(TEST, rustc_outlives, Normal, template!(Word)),
539     rustc_attr!(TEST, rustc_variance, Normal, template!(Word)),
540     rustc_attr!(TEST, rustc_layout, Normal, template!(List: "field1, field2, ...")),
541     rustc_attr!(TEST, rustc_regions, Normal, template!(Word)),
542     rustc_attr!(
543         TEST, rustc_error, Whitelisted,
544         template!(Word, List: "delay_span_bug_from_inside_query")
545     ),
546     rustc_attr!(TEST, rustc_dump_user_substs, Whitelisted, template!(Word)),
547     rustc_attr!(TEST, rustc_if_this_changed, Whitelisted, template!(Word, List: "DepNode")),
548     rustc_attr!(TEST, rustc_then_this_would_need, Whitelisted, template!(List: "DepNode")),
549     rustc_attr!(
550         TEST, rustc_dirty, Whitelisted,
551         template!(List: r#"cfg = "...", /*opt*/ label = "...", /*opt*/ except = "...""#),
552     ),
553     rustc_attr!(
554         TEST, rustc_clean, Whitelisted,
555         template!(List: r#"cfg = "...", /*opt*/ label = "...", /*opt*/ except = "...""#),
556     ),
557     rustc_attr!(
558         TEST, rustc_partition_reused, Whitelisted,
559         template!(List: r#"cfg = "...", module = "...""#),
560     ),
561     rustc_attr!(
562         TEST, rustc_partition_codegened, Whitelisted,
563         template!(List: r#"cfg = "...", module = "...""#),
564     ),
565     rustc_attr!(
566         TEST, rustc_expected_cgu_reuse, Whitelisted,
567         template!(List: r#"cfg = "...", module = "...", kind = "...""#),
568     ),
569     rustc_attr!(TEST, rustc_synthetic, Whitelisted, template!(Word)),
570     rustc_attr!(TEST, rustc_symbol_name, Whitelisted, template!(Word)),
571     rustc_attr!(TEST, rustc_def_path, Whitelisted, template!(Word)),
572     rustc_attr!(TEST, rustc_mir, Whitelisted, template!(List: "arg1, arg2, ...")),
573     rustc_attr!(TEST, rustc_dump_program_clauses, Whitelisted, template!(Word)),
574     rustc_attr!(TEST, rustc_dump_env_program_clauses, Whitelisted, template!(Word)),
575     rustc_attr!(TEST, rustc_object_lifetime_default, Whitelisted, template!(Word)),
576     rustc_attr!(TEST, rustc_dummy, Normal, template!(Word /* doesn't matter*/)),
577     gated!(
578         omit_gdb_pretty_printer_section, Whitelisted, template!(Word),
579         "the `#[omit_gdb_pretty_printer_section]` attribute is just used for the Rust test suite",
580     ),
581 ];
582
583 pub fn deprecated_attributes() -> Vec<&'static BuiltinAttribute> {
584     BUILTIN_ATTRIBUTES.iter().filter(|(.., gate)| gate.is_deprecated()).collect()
585 }
586
587 pub fn is_builtin_attr_name(name: Symbol) -> bool {
588     BUILTIN_ATTRIBUTE_MAP.get(&name).is_some()
589 }
590
591 lazy_static! {
592     pub static ref BUILTIN_ATTRIBUTE_MAP: FxHashMap<Symbol, &'static BuiltinAttribute> = {
593         let mut map = FxHashMap::default();
594         for attr in BUILTIN_ATTRIBUTES.iter() {
595             if map.insert(attr.0, attr).is_some() {
596                 panic!("duplicate builtin attribute `{}`", attr.0);
597             }
598         }
599         map
600     };
601 }