Skip to content

Commit 99e39f4

Browse files
committed
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
1 parent 38542cc commit 99e39f4

File tree

1 file changed

+26
-37
lines changed

1 file changed

+26
-37
lines changed

src/libsyntax/feature_gate.rs

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use visit;
3636
use visit::Visitor;
3737
use parse::token::{self, InternedString};
3838

39-
use std::slice;
4039
use std::ascii::AsciiExt;
4140

4241
// 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> {
574573
}
575574

576575
fn visit_attribute(&mut self, attr: &ast::Attribute) {
577-
if attr.check_name("staged_api") {
578-
self.gate_feature("staged_api", attr.span,
579-
"staged_api is for use by rustc only");
580-
} else if attr.check_name("plugin") {
581-
self.gate_feature("plugin", attr.span,
582-
"compiler plugins are experimental \
583-
and possibly buggy");
584-
}
585-
586-
if attr::contains_name(slice::ref_slice(attr), "lang") {
587-
self.gate_feature("lang_items",
588-
attr.span,
589-
"language items are subject to change");
590-
}
591-
592-
if attr.check_name("no_std") {
593-
self.gate_feature("no_std", attr.span,
594-
"no_std is experimental");
595-
}
596-
597-
if attr.check_name("unsafe_no_drop_flag") {
598-
self.gate_feature("unsafe_no_drop_flag", attr.span,
599-
"unsafe_no_drop_flag has unstable semantics \
600-
and may be removed in the future");
601-
}
602-
603-
// Custom attribute check
604-
let name = attr.name();
605-
606-
if KNOWN_ATTRIBUTES.iter().all(|&(n, _)| n != name) {
607-
self.gate_feature("custom_attribute", attr.span,
608-
format!("The attribute `{}` is currently \
609-
unknown to the the compiler and \
610-
may have meaning \
611-
added to it in the future",
612-
attr.name()).as_slice());
576+
match &*attr.name() {
577+
"staged_api" => self.gate_feature("staged_api", attr.span,
578+
"staged_api is for use by rustc only"),
579+
"plugin" => self.gate_feature("plugin", attr.span,
580+
"compiler plugins are experimental \
581+
and possibly buggy"),
582+
"no_std" => self.gate_feature("no_std", attr.span,
583+
"no_std is experimental"),
584+
"unsafe_no_drop_flag" => self.gate_feature("unsafe_no_drop_flag", attr.span,
585+
"unsafe_no_drop_flag has unstable \
586+
semantics and may be removed \
587+
in the future"),
588+
"lang" => self.gate_feature("lang_items",
589+
attr.span,
590+
"language items are subject to change"),
591+
name => {
592+
// Custom attribute check
593+
if KNOWN_ATTRIBUTES.iter().all(|&(n, _)| n != name) {
594+
self.gate_feature("custom_attribute", attr.span,
595+
format!("The attribute `{}` is currently \
596+
unknown to the the compiler and \
597+
may have meaning \
598+
added to it in the future",
599+
attr.name()).as_slice());
600+
}
601+
}
613602
}
614603
}
615604

0 commit comments

Comments
 (0)