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
This commit is contained in:
Manish Goregaokar
2015-02-15 16:37:36 +05:30
parent 38542cca29
commit 99e39f4927

View File

@@ -36,7 +36,6 @@ use visit;
use visit::Visitor; use visit::Visitor;
use parse::token::{self, InternedString}; use parse::token::{self, InternedString};
use std::slice;
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
// If you change this list without updating src/doc/reference.md, @cmr will be sad // 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) { fn visit_attribute(&mut self, attr: &ast::Attribute) {
if attr.check_name("staged_api") { match &*attr.name() {
self.gate_feature("staged_api", attr.span, "staged_api" => self.gate_feature("staged_api", attr.span,
"staged_api is for use by rustc only"); "staged_api is for use by rustc only"),
} else if attr.check_name("plugin") { "plugin" => self.gate_feature("plugin", attr.span,
self.gate_feature("plugin", attr.span, "compiler plugins are experimental \
"compiler plugins are experimental \ and possibly buggy"),
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,
if attr::contains_name(slice::ref_slice(attr), "lang") { "unsafe_no_drop_flag has unstable \
self.gate_feature("lang_items", semantics and may be removed \
attr.span, in the future"),
"language items are subject to change"); "lang" => self.gate_feature("lang_items",
} attr.span,
"language items are subject to change"),
if attr.check_name("no_std") { name => {
self.gate_feature("no_std", attr.span, // Custom attribute check
"no_std is experimental"); if KNOWN_ATTRIBUTES.iter().all(|&(n, _)| n != name) {
} self.gate_feature("custom_attribute", attr.span,
format!("The attribute `{}` is currently \
if attr.check_name("unsafe_no_drop_flag") { unknown to the the compiler and \
self.gate_feature("unsafe_no_drop_flag", attr.span, may have meaning \
"unsafe_no_drop_flag has unstable semantics \ added to it in the future",
and may be removed in the future"); attr.name()).as_slice());
} }
}
// 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());
} }
} }