about summary refs log tree commit diff
path: root/src/libsyntax/attr
diff options
context:
space:
mode:
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2019-04-03 02:43:49 +0200
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2019-04-15 07:23:01 +0200
commit10855a36b53d33aa2e4f8b98107ee54a0cca5e9c (patch)
treeeb06422719e2b2f7098d8b658f2ebd835eb04bb2 /src/libsyntax/attr
parenta55f6be4286991437659acb8506466e8d637ac51 (diff)
downloadrust-10855a36b53d33aa2e4f8b98107ee54a0cca5e9c.tar.gz
rust-10855a36b53d33aa2e4f8b98107ee54a0cca5e9c.zip
Use a proc macro to declare preallocated symbols
Diffstat (limited to 'src/libsyntax/attr')
-rw-r--r--src/libsyntax/attr/mod.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs
index c0bd5c79b1d..f34bbc9f35d 100644
--- a/src/libsyntax/attr/mod.rs
+++ b/src/libsyntax/attr/mod.rs
@@ -85,6 +85,11 @@ impl NestedMetaItem {
         self.meta_item().map_or(false, |meta_item| meta_item.check_name(name))
     }
 
+    /// Returns `true` if this list item is a MetaItem with a name of `name`.
+    pub fn check_name_symbol(&self, name: Symbol) -> bool {
+        self.meta_item().map_or(false, |meta_item| meta_item.check_name_symbol(name))
+    }
+
     /// For a single-segment meta-item returns its name, otherwise returns `None`.
     pub fn ident(&self) -> Option<Ident> {
         self.meta_item().and_then(|meta_item| meta_item.ident())
@@ -159,6 +164,18 @@ impl Attribute {
         matches
     }
 
+    /// Returns `true` if the attribute's path matches the argument. If it matches, then the
+    /// attribute is marked as used.
+    ///
+    /// To check the attribute name without marking it used, use the `path` field directly.
+    pub fn check_name_symbol(&self, name: Symbol) -> bool {
+        let matches = self.path == name;
+        if matches {
+            mark_used(self);
+        }
+        matches
+    }
+
     /// For a single-segment attribute returns its name, otherwise returns `None`.
     pub fn ident(&self) -> Option<Ident> {
         if self.path.segments.len() == 1 {
@@ -248,6 +265,10 @@ impl MetaItem {
         self.path == name
     }
 
+    pub fn check_name_symbol(&self, name: Symbol) -> bool {
+        self.path == name
+    }
+
     pub fn is_value_str(&self) -> bool {
         self.value_str().is_some()
     }