about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2015-02-15 16:37:36 +0530
committerManish Goregaokar <manishsmail@gmail.com>2015-02-16 11:49:09 +0530
commit99e39f4927408d25c8b9033f33738b672d870bb6 (patch)
tree876c42bb7bcbbc6bcd51e6b367059608f5f5cd26 /src/libsyntax
parent38542cca29a0ed6f62b18d543386852e5a544adc (diff)
downloadrust-99e39f4927408d25c8b9033f33738b672d870bb6.tar.gz
rust-99e39f4927408d25c8b9033f33738b672d870bb6.zip
Clean up visit_attribute in feature_gate.rs
 - We shouldn't be using `check_name` here at all
 - `contains_name(ref_slice(foo), bar)` is redundant, `contains_name` just iterates over its first arg and calls `check_name`
 - match would be better than a bunch of ifs
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/feature_gate.rs63
1 files changed, 26 insertions, 37 deletions
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index 5af9ca307de..62eb5badb77 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -36,7 +36,6 @@ use visit;
 use visit::Visitor;
 use parse::token::{self, InternedString};
 
-use std::slice;
 use std::ascii::AsciiExt;
 
 // If you change this list without updating src/doc/reference.md, @cmr will be sad
@@ -574,42 +573,32 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
     }
 
     fn visit_attribute(&mut self, attr: &ast::Attribute) {
-        if attr.check_name("staged_api") {
-            self.gate_feature("staged_api", attr.span,
-                              "staged_api is for use by rustc only");
-        } else if attr.check_name("plugin") {
-            self.gate_feature("plugin", attr.span,
-                              "compiler plugins are experimental \
-                               and possibly buggy");
-        }
-
-        if attr::contains_name(slice::ref_slice(attr), "lang") {
-            self.gate_feature("lang_items",
-                              attr.span,
-                              "language items are subject to change");
-        }
-
-        if attr.check_name("no_std") {
-            self.gate_feature("no_std", attr.span,
-                              "no_std is experimental");
-        }
-
-        if attr.check_name("unsafe_no_drop_flag") {
-            self.gate_feature("unsafe_no_drop_flag", attr.span,
-                              "unsafe_no_drop_flag has unstable semantics \
-                               and may be removed in the future");
-        }
-
-        // Custom attribute check
-        let name = attr.name();
-
-        if KNOWN_ATTRIBUTES.iter().all(|&(n, _)| n != name) {
-            self.gate_feature("custom_attribute", attr.span,
-                       format!("The attribute `{}` is currently \
-                                unknown to the the compiler and \
-                                may have meaning \
-                                added to it in the future",
-                                attr.name()).as_slice());
+        match &*attr.name() {
+            "staged_api" => self.gate_feature("staged_api", attr.span,
+                                              "staged_api is for use by rustc only"),
+            "plugin" => self.gate_feature("plugin", attr.span,
+                                          "compiler plugins are experimental \
+                                           and possibly buggy"),
+            "no_std" => self.gate_feature("no_std", attr.span,
+                                          "no_std is experimental"),
+            "unsafe_no_drop_flag" => self.gate_feature("unsafe_no_drop_flag", attr.span,
+                                                       "unsafe_no_drop_flag has unstable \
+                                                        semantics and may be removed \
+                                                        in the future"),
+            "lang" => self.gate_feature("lang_items",
+                                        attr.span,
+                                        "language items are subject to change"),
+            name => {
+                // Custom attribute check
+                if KNOWN_ATTRIBUTES.iter().all(|&(n, _)| n != name) {
+                    self.gate_feature("custom_attribute", attr.span,
+                               format!("The attribute `{}` is currently \
+                                        unknown to the the compiler and \
+                                        may have meaning \
+                                        added to it in the future",
+                                        attr.name()).as_slice());
+                }
+            }
         }
     }