about summary refs log tree commit diff
path: root/src/librustc/plugin
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-05-24 09:38:26 +0000
committerbors <bors@rust-lang.org>2015-05-24 09:38:26 +0000
commitcc56c20ba4ccc12f58e1c844b77168bc4805cbb6 (patch)
treecde59db62a290a198a398b9f686f807e7f4d75db /src/librustc/plugin
parent0fc0476e6ae2bcc5cce75d78548cf037b6692a97 (diff)
parent22b720a920612211d83f7176d7cf2f184c74d294 (diff)
downloadrust-cc56c20ba4ccc12f58e1c844b77168bc4805cbb6.tar.gz
rust-cc56c20ba4ccc12f58e1c844b77168bc4805cbb6.zip
Auto merge of #25168 - Manishearth:register_attr, r=eddyb
This lets plugin authors opt attributes out of the `custom_attribute`
and `unused_attribute` checks.


cc @thepowersgang
Diffstat (limited to 'src/librustc/plugin')
-rw-r--r--src/librustc/plugin/registry.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/librustc/plugin/registry.rs b/src/librustc/plugin/registry.rs
index 04df4641295..5faaa53e4d0 100644
--- a/src/librustc/plugin/registry.rs
+++ b/src/librustc/plugin/registry.rs
@@ -20,6 +20,7 @@ use syntax::codemap::Span;
 use syntax::parse::token;
 use syntax::ptr::P;
 use syntax::ast;
+use syntax::feature_gate::AttributeType;
 
 use std::collections::HashMap;
 use std::borrow::ToOwned;
@@ -54,6 +55,9 @@ pub struct Registry<'a> {
 
     #[doc(hidden)]
     pub llvm_passes: Vec<String>,
+
+    #[doc(hidden)]
+    pub attributes: Vec<(String, AttributeType)>,
 }
 
 impl<'a> Registry<'a> {
@@ -67,6 +71,7 @@ impl<'a> Registry<'a> {
             lint_passes: vec!(),
             lint_groups: HashMap::new(),
             llvm_passes: vec!(),
+            attributes: vec!(),
         }
     }
 
@@ -132,4 +137,19 @@ impl<'a> Registry<'a> {
     pub fn register_llvm_pass(&mut self, name: &str) {
         self.llvm_passes.push(name.to_owned());
     }
+
+
+    /// Register an attribute with an attribute type.
+    ///
+    /// Registered attributes will bypass the `custom_attribute` feature gate.
+    /// `Whitelisted` attributes will additionally not trigger the `unused_attribute`
+    /// lint. `CrateLevel` attributes will not be allowed on anything other than a crate.
+    pub fn register_attribute(&mut self, name: String, ty: AttributeType) {
+        if let AttributeType::Gated(..) = ty {
+            self.sess.span_err(self.krate_span, "plugin tried to register a gated \
+                                                 attribute. Only `Normal`, `Whitelisted`, \
+                                                 and `CrateLevel` attributes are allowed");
+        }
+        self.attributes.push((name, ty));
+    }
 }