]> git.lizzy.rs Git - rust.git/blob - src/librustc_feature/builtin_attrs.rs
Rollup merge of #70546 - lqd:polonius_update, r=nikomatsakis
[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 ];
30
31 /// Find a gated cfg determined by the `pred`icate which is given the cfg's name.
32 pub fn find_gated_cfg(pred: impl Fn(Symbol) -> bool) -> Option<&'static GatedCfg> {
33     GATED_CFGS.iter().find(|(cfg_sym, ..)| pred(*cfg_sym))
34 }
35
36 // If you change this, please modify `src/doc/unstable-book` as well. You must
37 // move that documentation into the relevant place in the other docs, and
38 // remove the chapter on the flag.
39
40 #[derive(Copy, Clone, PartialEq, Debug)]
41 pub enum AttributeType {
42     /// Normal, builtin attribute that is consumed
43     /// by the compiler before the unused_attribute check
44     Normal,
45
46     /// Builtin attribute that may not be consumed by the compiler
47     /// before the unused_attribute check. These attributes
48     /// will be ignored by the unused_attribute lint
49     Whitelisted,
50
51     /// Builtin attribute that is only allowed at the crate level
52     CrateLevel,
53 }
54
55 #[derive(Clone, Copy)]
56 pub enum AttributeGate {
57     /// Is gated by a given feature gate, reason
58     /// and function to check if enabled
59     Gated(Stability, Symbol, &'static str, fn(&Features) -> bool),
60
61     /// Ungated attribute, can be used on all release channels
62     Ungated,
63 }
64
65 // fn() is not Debug
66 impl std::fmt::Debug for AttributeGate {
67     fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
68         match *self {
69             Self::Gated(ref stab, name, expl, _) => {
70                 write!(fmt, "Gated({:?}, {}, {})", stab, name, expl)
71             }
72             Self::Ungated => write!(fmt, "Ungated"),
73         }
74     }
75 }
76
77 impl AttributeGate {
78     fn is_deprecated(&self) -> bool {
79         match *self {
80             Self::Gated(Stability::Deprecated(_, _), ..) => true,
81             _ => false,
82         }
83     }
84 }
85
86 /// A template that the attribute input must match.
87 /// Only top-level shape (`#[attr]` vs `#[attr(...)]` vs `#[attr = ...]`) is considered now.
88 #[derive(Clone, Copy, Default)]
89 pub struct AttributeTemplate {
90     pub word: bool,
91     pub list: Option<&'static str>,
92     pub name_value_str: Option<&'static str>,
93 }
94
95 /// A convenience macro for constructing attribute templates.
96 /// E.g., `template!(Word, List: "description")` means that the attribute
97 /// supports forms `#[attr]` and `#[attr(description)]`.
98 macro_rules! template {
99     (Word) => { template!(@ true, None, None) };
100     (List: $descr: expr) => { template!(@ false, Some($descr), None) };
101     (NameValueStr: $descr: expr) => { template!(@ false, None, Some($descr)) };
102     (Word, List: $descr: expr) => { template!(@ true, Some($descr), None) };
103     (Word, NameValueStr: $descr: expr) => { template!(@ true, None, Some($descr)) };
104     (List: $descr1: expr, NameValueStr: $descr2: expr) => {
105         template!(@ false, Some($descr1), Some($descr2))
106     };
107     (Word, List: $descr1: expr, NameValueStr: $descr2: expr) => {
108         template!(@ true, Some($descr1), Some($descr2))
109     };
110     (@ $word: expr, $list: expr, $name_value_str: expr) => { AttributeTemplate {
111         word: $word, list: $list, name_value_str: $name_value_str
112     } };
113 }
114
115 macro_rules! ungated {
116     ($attr:ident, $typ:expr, $tpl:expr $(,)?) => {
117         (sym::$attr, $typ, $tpl, Ungated)
118     };
119 }
120
121 macro_rules! gated {
122     ($attr:ident, $typ:expr, $tpl:expr, $gate:ident, $msg:expr $(,)?) => {
123         (sym::$attr, $typ, $tpl, Gated(Stability::Unstable, sym::$gate, $msg, cfg_fn!($gate)))
124     };
125     ($attr:ident, $typ:expr, $tpl:expr, $msg:expr $(,)?) => {
126         (sym::$attr, $typ, $tpl, Gated(Stability::Unstable, sym::$attr, $msg, cfg_fn!($attr)))
127     };
128 }
129
130 macro_rules! rustc_attr {
131     (TEST, $attr:ident, $typ:expr, $tpl:expr $(,)?) => {
132         rustc_attr!(
133             $attr,
134             $typ,
135             $tpl,
136             concat!(
137                 "the `#[",
138                 stringify!($attr),
139                 "]` attribute is just used for rustc unit tests \
140                 and will never be stable",
141             ),
142         )
143     };
144     ($attr:ident, $typ:expr, $tpl:expr, $msg:expr $(,)?) => {
145         (
146             sym::$attr,
147             $typ,
148             $tpl,
149             Gated(Stability::Unstable, sym::rustc_attrs, $msg, cfg_fn!(rustc_attrs)),
150         )
151     };
152 }
153
154 macro_rules! experimental {
155     ($attr:ident) => {
156         concat!("the `#[", stringify!($attr), "]` attribute is an experimental feature")
157     };
158 }
159
160 const IMPL_DETAIL: &str = "internal implementation detail";
161 const INTERNAL_UNSTABLE: &str = "this is an internal attribute that will never be stable";
162
163 pub type BuiltinAttribute = (Symbol, AttributeType, AttributeTemplate, AttributeGate);
164
165 /// Attributes that have a special meaning to rustc or rustdoc.
166 #[rustfmt::skip]
167 pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
168     // ==========================================================================
169     // Stable attributes:
170     // ==========================================================================
171
172     // Conditional compilation:
173     ungated!(cfg, Normal, template!(List: "predicate")),
174     ungated!(cfg_attr, Normal, template!(List: "predicate, attr1, attr2, ...")),
175
176     // Testing:
177     ungated!(ignore, Normal, template!(Word, NameValueStr: "reason")),
178     ungated!(
179         should_panic, Normal,
180         template!(Word, List: r#"expected = "reason"#, NameValueStr: "reason"),
181     ),
182     // FIXME(Centril): This can be used on stable but shouldn't.
183     ungated!(reexport_test_harness_main, Normal, template!(NameValueStr: "name")),
184
185     // Macros:
186     ungated!(derive, Normal, template!(List: "Trait1, Trait2, ...")),
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, Whitelisted, 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, Whitelisted,
223         template!(List: r#"name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...""#),
224     ),
225     ungated!(link_name, Whitelisted, template!(NameValueStr: "name")),
226     ungated!(no_link, Normal, template!(Word)),
227     ungated!(repr, Normal, template!(List: "C")),
228     ungated!(export_name, Whitelisted, template!(NameValueStr: "name")),
229     ungated!(link_section, Whitelisted, template!(NameValueStr: "name")),
230     ungated!(no_mangle, Whitelisted, template!(Word)),
231     ungated!(used, Whitelisted, 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
241     // Entry point:
242     ungated!(main, Normal, template!(Word)),
243     ungated!(start, Normal, template!(Word)),
244     ungated!(no_start, CrateLevel, template!(Word)),
245     ungated!(no_main, CrateLevel, template!(Word)),
246
247     // Modules, prelude, and resolution:
248     ungated!(path, Normal, template!(NameValueStr: "file")),
249     ungated!(no_std, CrateLevel, template!(Word)),
250     ungated!(no_implicit_prelude, Normal, template!(Word)),
251     ungated!(non_exhaustive, Whitelisted, template!(Word)),
252
253     // Runtime
254     ungated!(windows_subsystem, Whitelisted, template!(NameValueStr: "windows|console")),
255     ungated!(panic_handler, Normal, template!(Word)), // RFC 2070
256
257     // Code generation:
258     ungated!(inline, Whitelisted, template!(Word, List: "always|never")),
259     ungated!(cold, Whitelisted, template!(Word)),
260     ungated!(no_builtins, Whitelisted, template!(Word)),
261     ungated!(target_feature, Whitelisted, template!(List: r#"enable = "name""#)),
262     gated!(
263         no_sanitize, Whitelisted,
264         template!(List: "address, memory, thread"),
265         experimental!(no_sanitize)
266     ),
267
268     // FIXME: #14408 whitelist docs since rustdoc looks at them
269     ungated!(doc, Whitelisted, template!(List: "hidden|inline|...", NameValueStr: "string")),
270
271     // ==========================================================================
272     // Unstable attributes:
273     // ==========================================================================
274
275     // Linking:
276     gated!(naked, Whitelisted, template!(Word), naked_functions, experimental!(naked)),
277     gated!(
278         link_args, Normal, template!(NameValueStr: "args"),
279         "the `link_args` attribute is experimental and not portable across platforms, \
280         it is recommended to use `#[link(name = \"foo\")] instead",
281     ),
282     gated!(
283         link_ordinal, Whitelisted, template!(List: "ordinal"), raw_dylib,
284         experimental!(link_ordinal)
285     ),
286
287     // Plugins:
288     (
289         sym::plugin_registrar, Normal, template!(Word),
290         Gated(
291             Stability::Deprecated(
292                 "https://github.com/rust-lang/rust/pull/64675",
293                 Some("may be removed in a future compiler version"),
294             ),
295             sym::plugin_registrar,
296             "compiler plugins are deprecated",
297             cfg_fn!(plugin_registrar)
298         )
299     ),
300     (
301         sym::plugin, CrateLevel, template!(List: "name"),
302         Gated(
303             Stability::Deprecated(
304                 "https://github.com/rust-lang/rust/pull/64675",
305                 Some("may be removed in a future compiler version"),
306             ),
307             sym::plugin,
308             "compiler plugins are deprecated",
309             cfg_fn!(plugin)
310         )
311     ),
312
313     // Testing:
314     gated!(allow_fail, Normal, template!(Word), experimental!(allow_fail)),
315     gated!(
316         test_runner, CrateLevel, template!(List: "path"), custom_test_frameworks,
317         "custom test frameworks are an unstable feature",
318     ),
319     // RFC #1268
320     gated!(marker, Normal, template!(Word), marker_trait_attr, experimental!(marker)),
321     gated!(
322         thread_local, Whitelisted, template!(Word),
323         "`#[thread_local]` is an experimental feature, and does not currently handle destructors",
324     ),
325     gated!(no_core, CrateLevel, template!(Word), experimental!(no_core)),
326     // RFC 2412
327     gated!(
328         optimize, Whitelisted, template!(List: "size|speed"), optimize_attribute,
329         experimental!(optimize),
330     ),
331
332     gated!(ffi_returns_twice, Whitelisted, template!(Word), experimental!(ffi_returns_twice)),
333     gated!(track_caller, Whitelisted, template!(Word), experimental!(track_caller)),
334     gated!(
335         register_attr, CrateLevel, template!(List: "attr1, attr2, ..."),
336         experimental!(register_attr),
337     ),
338     gated!(
339         register_tool, CrateLevel, template!(List: "tool1, tool2, ..."),
340         experimental!(register_tool),
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, Whitelisted,
352         template!(List: r#"since = "version", reason = "...""#)
353     ),
354     // FIXME(#14407)
355     ungated!(stable, Whitelisted, template!(List: r#"feature = "name", since = "version""#)),
356     // FIXME(#14407)
357     ungated!(
358         unstable, Whitelisted,
359         template!(List: r#"feature = "name", reason = "...", issue = "N""#),
360     ),
361     // FIXME(#14407)
362     ungated!(rustc_const_unstable, Whitelisted, template!(List: r#"feature = "name""#)),
363     // FIXME(#14407)
364     ungated!(rustc_const_stable, Whitelisted, 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         allow_internal_unsafe, Normal, template!(Word),
371         "allow_internal_unsafe side-steps the unsafe_code lint",
372     ),
373
374     // ==========================================================================
375     // Internal attributes: Type system related:
376     // ==========================================================================
377
378     gated!(fundamental, Whitelisted, template!(Word), experimental!(fundamental)),
379     gated!(
380         may_dangle, Normal, template!(Word), dropck_eyepatch,
381         "`may_dangle` has unstable semantics and may be removed in the future",
382     ),
383
384     // ==========================================================================
385     // Internal attributes: Runtime related:
386     // ==========================================================================
387
388     rustc_attr!(rustc_allocator, Whitelisted, template!(Word), IMPL_DETAIL),
389     rustc_attr!(rustc_allocator_nounwind, Whitelisted, template!(Word), IMPL_DETAIL),
390     gated!(alloc_error_handler, Normal, template!(Word), experimental!(alloc_error_handler)),
391     gated!(
392         default_lib_allocator, Whitelisted, template!(Word), allocator_internals,
393         experimental!(default_lib_allocator),
394     ),
395     gated!(
396         needs_allocator, Normal, template!(Word), allocator_internals,
397         experimental!(needs_allocator),
398     ),
399     gated!(panic_runtime, Whitelisted, template!(Word), experimental!(panic_runtime)),
400     gated!(needs_panic_runtime, Whitelisted, template!(Word), experimental!(needs_panic_runtime)),
401     gated!(
402         unwind, Whitelisted, template!(List: "allowed|aborts"), unwind_attributes,
403         experimental!(unwind),
404     ),
405     gated!(
406         compiler_builtins, Whitelisted, 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, Whitelisted, 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, Whitelisted, template!(NameValueStr: "external|internal|..."),
422         "the `linkage` attribute is experimental and not portable across platforms",
423     ),
424     rustc_attr!(rustc_std_internal_symbol, Whitelisted, template!(Word), INTERNAL_UNSTABLE),
425
426     // ==========================================================================
427     // Internal attributes, Macro related:
428     // ==========================================================================
429
430     rustc_attr!(rustc_builtin_macro, Whitelisted, template!(Word), IMPL_DETAIL),
431     rustc_attr!(rustc_proc_macro_decls, Normal, template!(Word), INTERNAL_UNSTABLE),
432     rustc_attr!(
433         rustc_macro_transparency, Whitelisted,
434         template!(NameValueStr: "transparent|semitransparent|opaque"),
435         "used internally for testing macro hygiene",
436     ),
437
438     // ==========================================================================
439     // Internal attributes, Diagnostics related:
440     // ==========================================================================
441
442     rustc_attr!(
443         rustc_on_unimplemented, Whitelisted,
444         template!(
445             List: r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#,
446             NameValueStr: "message"
447         ),
448         INTERNAL_UNSTABLE
449     ),
450     // Whitelists "identity-like" conversion methods to suggest on type mismatch.
451     rustc_attr!(rustc_conversion_suggestion, Whitelisted, template!(Word), INTERNAL_UNSTABLE),
452
453     // ==========================================================================
454     // Internal attributes, Const related:
455     // ==========================================================================
456
457     rustc_attr!(rustc_promotable, Whitelisted, template!(Word), IMPL_DETAIL),
458     rustc_attr!(rustc_allow_const_fn_ptr, Whitelisted, template!(Word), IMPL_DETAIL),
459     rustc_attr!(rustc_args_required_const, Whitelisted, template!(List: "N"), INTERNAL_UNSTABLE),
460
461     // ==========================================================================
462     // Internal attributes, Layout related:
463     // ==========================================================================
464
465     rustc_attr!(
466         rustc_layout_scalar_valid_range_start, Whitelisted, template!(List: "value"),
467         "the `#[rustc_layout_scalar_valid_range_start]` attribute is just used to enable \
468         niche optimizations in libcore and will never be stable",
469     ),
470     rustc_attr!(
471         rustc_layout_scalar_valid_range_end, Whitelisted, template!(List: "value"),
472         "the `#[rustc_layout_scalar_valid_range_end]` attribute is just used to enable \
473         niche optimizations in libcore and will never be stable",
474     ),
475     rustc_attr!(
476         rustc_nonnull_optimization_guaranteed, Whitelisted, template!(Word),
477         "the `#[rustc_nonnull_optimization_guaranteed]` attribute is just used to enable \
478         niche optimizations in libcore and will never be stable",
479     ),
480
481     // ==========================================================================
482     // Internal attributes, Misc:
483     // ==========================================================================
484     gated!(
485         lang, Normal, template!(NameValueStr: "name"), lang_items,
486         "language items are subject to change",
487     ),
488     (
489         sym::rustc_diagnostic_item,
490         Normal,
491         template!(NameValueStr: "name"),
492         Gated(
493             Stability::Unstable,
494             sym::rustc_attrs,
495             "diagnostic items compiler internal support for linting",
496             cfg_fn!(rustc_attrs),
497         ),
498     ),
499     gated!(
500         // Used in resolve:
501         prelude_import, Whitelisted, template!(Word),
502         "`#[prelude_import]` is for use by rustc only",
503     ),
504     gated!(
505         rustc_paren_sugar, Normal, template!(Word), unboxed_closures,
506         "unboxed_closures are still evolving",
507     ),
508     rustc_attr!(
509         rustc_inherit_overflow_checks, Whitelisted, template!(Word),
510         "the `#[rustc_inherit_overflow_checks]` attribute is just used to control \
511         overflow checking behavior of several libcore functions that are inlined \
512         across crates and will never be stable",
513     ),
514     rustc_attr!(rustc_reservation_impl, Normal, template!(NameValueStr: "reservation message"),
515                 "the `#[rustc_reservation_impl]` attribute is internally used \
516                  for reserving for `for<T> From<!> for T` impl"
517     ),
518     rustc_attr!(
519         rustc_test_marker, Normal, template!(Word),
520         "the `#[rustc_test_marker]` attribute is used internally to track tests",
521     ),
522     rustc_attr!(
523         rustc_unsafe_specialization_marker, Normal, template!(Word),
524         "the `#[rustc_unsafe_specialization_marker]` attribute is used to check specializations"
525     ),
526     rustc_attr!(
527         rustc_specialization_trait, Normal, template!(Word),
528         "the `#[rustc_specialization_trait]` attribute is used to check specializations"
529     ),
530
531     // ==========================================================================
532     // Internal attributes, Testing:
533     // ==========================================================================
534
535     rustc_attr!(TEST, rustc_outlives, Normal, template!(Word)),
536     rustc_attr!(TEST, rustc_variance, Normal, template!(Word)),
537     rustc_attr!(TEST, rustc_layout, Normal, template!(List: "field1, field2, ...")),
538     rustc_attr!(TEST, rustc_regions, Normal, template!(Word)),
539     rustc_attr!(
540         TEST, rustc_error, Whitelisted,
541         template!(Word, List: "delay_span_bug_from_inside_query")
542     ),
543     rustc_attr!(TEST, rustc_dump_user_substs, Whitelisted, template!(Word)),
544     rustc_attr!(TEST, rustc_if_this_changed, Whitelisted, template!(Word, List: "DepNode")),
545     rustc_attr!(TEST, rustc_then_this_would_need, Whitelisted, template!(List: "DepNode")),
546     rustc_attr!(
547         TEST, rustc_dirty, Whitelisted,
548         template!(List: r#"cfg = "...", /*opt*/ label = "...", /*opt*/ except = "...""#),
549     ),
550     rustc_attr!(
551         TEST, rustc_clean, Whitelisted,
552         template!(List: r#"cfg = "...", /*opt*/ label = "...", /*opt*/ except = "...""#),
553     ),
554     rustc_attr!(
555         TEST, rustc_partition_reused, Whitelisted,
556         template!(List: r#"cfg = "...", module = "...""#),
557     ),
558     rustc_attr!(
559         TEST, rustc_partition_codegened, Whitelisted,
560         template!(List: r#"cfg = "...", module = "...""#),
561     ),
562     rustc_attr!(
563         TEST, rustc_expected_cgu_reuse, Whitelisted,
564         template!(List: r#"cfg = "...", module = "...", kind = "...""#),
565     ),
566     rustc_attr!(TEST, rustc_synthetic, Whitelisted, template!(Word)),
567     rustc_attr!(TEST, rustc_symbol_name, Whitelisted, template!(Word)),
568     rustc_attr!(TEST, rustc_def_path, Whitelisted, template!(Word)),
569     rustc_attr!(TEST, rustc_mir, Whitelisted, template!(List: "arg1, arg2, ...")),
570     rustc_attr!(TEST, rustc_dump_program_clauses, Whitelisted, template!(Word)),
571     rustc_attr!(TEST, rustc_dump_env_program_clauses, Whitelisted, template!(Word)),
572     rustc_attr!(TEST, rustc_object_lifetime_default, Whitelisted, template!(Word)),
573     rustc_attr!(TEST, rustc_dummy, Normal, template!(Word /* doesn't matter*/)),
574     gated!(
575         omit_gdb_pretty_printer_section, Whitelisted, template!(Word),
576         "the `#[omit_gdb_pretty_printer_section]` attribute is just used for the Rust test suite",
577     ),
578 ];
579
580 pub fn deprecated_attributes() -> Vec<&'static BuiltinAttribute> {
581     BUILTIN_ATTRIBUTES.iter().filter(|(.., gate)| gate.is_deprecated()).collect()
582 }
583
584 pub fn is_builtin_attr_name(name: Symbol) -> bool {
585     BUILTIN_ATTRIBUTE_MAP.get(&name).is_some()
586 }
587
588 lazy_static! {
589     pub static ref BUILTIN_ATTRIBUTE_MAP: FxHashMap<Symbol, &'static BuiltinAttribute> = {
590         let mut map = FxHashMap::default();
591         for attr in BUILTIN_ATTRIBUTES.iter() {
592             if map.insert(attr.0, attr).is_some() {
593                 panic!("duplicate builtin attribute `{}`", attr.0);
594             }
595         }
596         map
597     };
598 }