about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSeiichi Uchida <seuchida@gmail.com>2018-01-30 19:28:55 +0900
committerflip1995 <uwdkn@student.kit.edu>2018-05-02 11:48:11 +0200
commit6c28f84e37c48faa63488ada95242282cf1a09e9 (patch)
treea10f997856387056201b25ef08963716f3e8022c
parent9b3aea602c37d53bbecf8bff8c77ccbfbefc23d0 (diff)
downloadrust-6c28f84e37c48faa63488ada95242282cf1a09e9.tar.gz
rust-6c28f84e37c48faa63488ada95242282cf1a09e9.zip
Gate tool_attributes feature
-rw-r--r--src/libsyntax/attr.rs10
-rw-r--r--src/libsyntax/diagnostic_list.rs1
-rw-r--r--src/libsyntax/ext/expand.rs6
-rw-r--r--src/libsyntax/feature_gate.rs5
4 files changed, 20 insertions, 2 deletions
diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs
index f805ba80885..12360e55c71 100644
--- a/src/libsyntax/attr.rs
+++ b/src/libsyntax/attr.rs
@@ -107,6 +107,12 @@ pub fn is_known(attr: &Attribute) -> bool {
     })
 }
 
+const RUST_KNOWN_TOOL: &[&str] = &["clippy", "rustfmt"];
+
+pub fn is_known_tool(attr: &Attribute) -> bool {
+    RUST_KNOWN_TOOL.contains(&attr.name().as_str().as_ref())
+}
+
 impl NestedMetaItem {
     /// Returns the MetaItem if self is a NestedMetaItemKind::MetaItem.
     pub fn meta_item(&self) -> Option<&MetaItem> {
@@ -250,6 +256,10 @@ impl Attribute {
     pub fn is_value_str(&self) -> bool {
         self.value_str().is_some()
     }
+
+    pub fn is_scoped(&self) -> bool {
+        self.path.segments.len() > 1
+    }
 }
 
 impl MetaItem {
diff --git a/src/libsyntax/diagnostic_list.rs b/src/libsyntax/diagnostic_list.rs
index c9cac1b1142..dee63b7085e 100644
--- a/src/libsyntax/diagnostic_list.rs
+++ b/src/libsyntax/diagnostic_list.rs
@@ -325,4 +325,5 @@ register_diagnostics! {
     E0629, // missing 'feature' (rustc_const_unstable)
     E0630, // rustc_const_unstable attribute must be paired with stable/unstable attribute
     E0693, // incorrect `repr(align)` attribute format
+    E0694, // an unknown tool name found in scoped attributes
 }
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index 1d16a7eb091..41cd9c595d2 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -1017,7 +1017,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
     fn check_attributes(&mut self, attrs: &[ast::Attribute]) {
         let features = self.cx.ecfg.features.unwrap();
         for attr in attrs.iter() {
-            feature_gate::check_attribute(attr, self.cx.parse_sess, features);
+            self.check_attribute_inner(attr, features);
 
             // macros are expanded before any lint passes so this warning has to be hardcoded
             if attr.path == "derive" {
@@ -1030,6 +1030,10 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
 
     fn check_attribute(&mut self, at: &ast::Attribute) {
         let features = self.cx.ecfg.features.unwrap();
+        self.check_attribute_inner(at, features);
+    }
+
+    fn check_attribute_inner(&mut self, at: &ast::Attribute, features: &Features) {
         feature_gate::check_attribute(at, self.cx.parse_sess, features);
     }
 }
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index 9bae8e73c7f..4405c1a2658 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -460,6 +460,9 @@ declare_features! (
 
     // Access to crate names passed via `--extern` through prelude
     (active, extern_prelude, "1.27.0", Some(44660), Some(Edition::Edition2018)),
+    
+    // Scoped attributes
+    (active, tool_attributes, "1.25.0", Some(44690)),
 );
 
 declare_features! (
@@ -1079,7 +1082,7 @@ pub struct GatedCfg {
 
 impl GatedCfg {
     pub fn gate(cfg: &ast::MetaItem) -> Option<GatedCfg> {
-        let name = cfg.ident.name.as_str();
+        let name = cfg.name().as_str();
         GATED_CFGS.iter()
                   .position(|info| info.0 == name)
                   .map(|idx| {