about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2019-04-05 03:05:30 +0200
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2019-04-15 07:23:02 +0200
commit61a7a60d45fd20bee343a37693969a32e63cb905 (patch)
tree513a5331ee22331761ec27c2f8c7d9cf8262df30 /src/libsyntax
parent10855a36b53d33aa2e4f8b98107ee54a0cca5e9c (diff)
downloadrust-61a7a60d45fd20bee343a37693969a32e63cb905.tar.gz
rust-61a7a60d45fd20bee343a37693969a32e63cb905.zip
Make check_name generic
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/attr/mod.rs36
-rw-r--r--src/libsyntax/feature_gate.rs24
2 files changed, 24 insertions, 36 deletions
diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs
index f34bbc9f35d..e00f91e3952 100644
--- a/src/libsyntax/attr/mod.rs
+++ b/src/libsyntax/attr/mod.rs
@@ -81,15 +81,13 @@ impl NestedMetaItem {
     }
 
     /// Returns `true` if this list item is a MetaItem with a name of `name`.
-    pub fn check_name(&self, name: &str) -> bool {
+    pub fn check_name<T>(&self, name: T) -> bool
+    where
+        Path: PartialEq<T>,
+    {
         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())
@@ -156,19 +154,10 @@ impl Attribute {
     /// attribute is marked as used.
     ///
     /// To check the attribute name without marking it used, use the `path` field directly.
-    pub fn check_name(&self, name: &str) -> bool {
-        let matches = self.path == name;
-        if matches {
-            mark_used(self);
-        }
-        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 {
+    pub fn check_name<T>(&self, name: T) -> bool
+    where
+        Path: PartialEq<T>,
+    {
         let matches = self.path == name;
         if matches {
             mark_used(self);
@@ -261,11 +250,10 @@ impl MetaItem {
         }
     }
 
-    pub fn check_name(&self, name: &str) -> bool {
-        self.path == name
-    }
-
-    pub fn check_name_symbol(&self, name: Symbol) -> bool {
+    pub fn check_name<T>(&self, name: T) -> bool
+    where
+        Path: PartialEq<T>,
+    {
         self.path == name
     }
 
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index b3e5d808a47..ba4380416fb 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -1366,7 +1366,7 @@ impl<'a> Context<'a> {
                     }
                 } else if n == "doc" {
                     if let Some(content) = attr.meta_item_list() {
-                        if content.iter().any(|c| c.check_name_symbol(symbols::include)) {
+                        if content.iter().any(|c| c.check_name(symbols::include)) {
                             gate_feature!(self, external_doc, attr.span,
                                 "#[doc(include = \"...\")] is experimental"
                             );
@@ -1667,25 +1667,25 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
         // check for gated attributes
         self.context.check_attribute(attr, false);
 
-        if attr.check_name_symbol(symbols::doc) {
+        if attr.check_name(symbols::doc) {
             if let Some(content) = attr.meta_item_list() {
-                if content.len() == 1 && content[0].check_name_symbol(symbols::cfg) {
+                if content.len() == 1 && content[0].check_name(symbols::cfg) {
                     gate_feature_post!(&self, doc_cfg, attr.span,
                         "#[doc(cfg(...))] is experimental"
                     );
-                } else if content.iter().any(|c| c.check_name_symbol(symbols::masked)) {
+                } else if content.iter().any(|c| c.check_name(symbols::masked)) {
                     gate_feature_post!(&self, doc_masked, attr.span,
                         "#[doc(masked)] is experimental"
                     );
-                } else if content.iter().any(|c| c.check_name_symbol(symbols::spotlight)) {
+                } else if content.iter().any(|c| c.check_name(symbols::spotlight)) {
                     gate_feature_post!(&self, doc_spotlight, attr.span,
                         "#[doc(spotlight)] is experimental"
                     );
-                } else if content.iter().any(|c| c.check_name_symbol(symbols::alias)) {
+                } else if content.iter().any(|c| c.check_name(symbols::alias)) {
                     gate_feature_post!(&self, doc_alias, attr.span,
                         "#[doc(alias = \"...\")] is experimental"
                     );
-                } else if content.iter().any(|c| c.check_name_symbol(symbols::keyword)) {
+                } else if content.iter().any(|c| c.check_name(symbols::keyword)) {
                     gate_feature_post!(&self, doc_keyword, attr.span,
                         "#[doc(keyword = \"...\")] is experimental"
                     );
@@ -1748,7 +1748,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
             ast::ItemKind::Struct(..) => {
                 for attr in attr::filter_by_name(&i.attrs[..], "repr") {
                     for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
-                        if item.check_name_symbol(symbols::simd) {
+                        if item.check_name(symbols::simd) {
                             gate_feature_post!(&self, repr_simd, attr.span,
                                                "SIMD types are experimental and possibly buggy");
                         }
@@ -1759,7 +1759,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
             ast::ItemKind::Enum(..) => {
                 for attr in attr::filter_by_name(&i.attrs[..], "repr") {
                     for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
-                        if item.check_name_symbol(symbols::align) {
+                        if item.check_name(symbols::align) {
                             gate_feature_post!(&self, repr_align_enum, attr.span,
                                                "`#[repr(align(x))]` on enums is experimental");
                         }
@@ -2083,7 +2083,7 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
     // Process the edition umbrella feature-gates first, to ensure
     // `edition_enabled_features` is completed before it's queried.
     for attr in krate_attrs {
-        if !attr.check_name_symbol(symbols::feature) {
+        if !attr.check_name(symbols::feature) {
             continue
         }
 
@@ -2128,7 +2128,7 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
     }
 
     for attr in krate_attrs {
-        if !attr.check_name_symbol(symbols::feature) {
+        if !attr.check_name(symbols::feature) {
             continue
         }
 
@@ -2258,7 +2258,7 @@ fn maybe_stage_features(span_handler: &Handler, krate: &ast::Crate,
     };
     if !allow_features {
         for attr in &krate.attrs {
-            if attr.check_name_symbol(symbols::feature) {
+            if attr.check_name(symbols::feature) {
                 let release_channel = option_env!("CFG_RELEASE_CHANNEL").unwrap_or("(unknown)");
                 span_err!(span_handler, attr.span, E0554,
                           "#![feature] may not be used on the {} release channel",