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