@@ -717,6 +717,8 @@ pub enum AttributeGate {
717
717
Ungated,
718
718
}
719
719
720
+ /// A template that the attribute input must match.
721
+ /// Only top-level shape (`#[attr]` vs `#[attr(...)]` vs `#[attr = ...]`) is considered now.
720
722
#[derive(Clone, Copy)]
721
723
pub struct AttributeTemplate {
722
724
word: bool,
@@ -725,6 +727,7 @@ pub struct AttributeTemplate {
725
727
}
726
728
727
729
impl AttributeTemplate {
730
+ /// Check that the given meta-item is compatible with this template.
728
731
fn compatible(&self, meta_item_kind: &ast::MetaItemKind) -> bool {
729
732
match meta_item_kind {
730
733
ast::MetaItemKind::Word => self.word,
@@ -735,10 +738,10 @@ impl AttributeTemplate {
735
738
}
736
739
}
737
740
741
+ /// A convenience macro for constructing attribute templates.
742
+ /// E.g. `template!(Word, List: "description")` means that the attribute
743
+ /// supports forms `#[attr]` and `#[attr(description)]`.
738
744
macro_rules! template {
739
- (@ $word: expr, $list: expr, $name_value_str: expr) => { AttributeTemplate {
740
- word: $word, list: $list, name_value_str: $name_value_str
741
- } };
742
745
(Word) => { template!(@ true, None, None) };
743
746
(List: $descr: expr) => { template!(@ false, Some($descr), None) };
744
747
(NameValueStr: $descr: expr) => { template!(@ false, None, Some($descr)) };
@@ -750,6 +753,9 @@ macro_rules! template {
750
753
(Word, List: $descr1: expr, NameValueStr: $descr2: expr) => {
751
754
template!(@ true, Some($descr1), Some($descr2))
752
755
};
756
+ (@ $word: expr, $list: expr, $name_value_str: expr) => { AttributeTemplate {
757
+ word: $word, list: $list, name_value_str: $name_value_str
758
+ } };
753
759
}
754
760
755
761
impl AttributeGate {
@@ -1084,7 +1090,8 @@ pub const BUILTIN_ATTRIBUTES: &[(&str, AttributeType, AttributeTemplate, Attribu
1084
1090
is an experimental feature",
1085
1091
cfg_fn!(fundamental))),
1086
1092
1087
- ("proc_macro_derive", Normal, template!(List: "TraitName, attributes(name1, name2, ...)"),
1093
+ ("proc_macro_derive", Normal, template!(List: "TraitName, \
1094
+ /*opt*/ attributes(name1, name2, ...)"),
1088
1095
Ungated),
1089
1096
1090
1097
("rustc_copy_clone_marker", Whitelisted, template!(Word), Gated(Stability::Unstable,
0 commit comments