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