]> git.lizzy.rs Git - rust.git/commitdiff
Add back hint for crate level attributes
authorSteven Fackler <sfackler@gmail.com>
Sun, 8 Jun 2014 07:21:15 +0000 (00:21 -0700)
committerSteven Fackler <sfackler@gmail.com>
Sun, 8 Jun 2014 07:21:15 +0000 (00:21 -0700)
src/librustc/middle/lint.rs
src/test/compile-fail/lint-misplaced-attr.rs

index 8d76535af7f99dfdcbd6c9ad4fa8b9465e5c20b6..9500f4d7ceebace551f0e5e87b3900ed2d8f48e0 100644 (file)
@@ -1124,6 +1124,20 @@ fn check_unused_attribute(cx: &Context, attr: &ast::Attribute) {
         "unstable",
     ];
 
+    static CRATE_ATTRS: &'static [&'static str] = &'static [
+        "crate_type",
+        "feature",
+        "no_start",
+        "no_main",
+        "no_std",
+        "crate_id",
+        "desc",
+        "comment",
+        "license",
+        "copyright",
+        "no_builtins",
+    ];
+
     for &name in ATTRIBUTE_WHITELIST.iter() {
         if attr.check_name(name) {
             break;
@@ -1132,6 +1146,15 @@ fn check_unused_attribute(cx: &Context, attr: &ast::Attribute) {
 
     if !attr::is_used(attr) {
         cx.span_lint(UnusedAttribute, attr.span, "unused attribute");
+        if CRATE_ATTRS.contains(&attr.name().get()) {
+            let msg = match attr.node.style {
+                ast::AttrOuter => "crate-level attribute should be an inner \
+                                  attribute: add an exclamation mark: #![foo]",
+                ast::AttrInner => "crate-level attribute should be in the \
+                                   root module",
+            };
+            cx.span_lint(UnusedAttribute, attr.span, msg);
+        }
     }
 }
 
index 9af48527435c576ff057c297883c9668ef23199c..dea712e976b35b8c5bfc48f093a141a63bc08823 100644 (file)
@@ -15,6 +15,8 @@
 
 mod a {
     #![crate_type = "bin"] //~ ERROR unused attribute
+                           //~^ ERROR should be in the root module
 }
 
 #[crate_type = "bin"] fn main() {} //~ ERROR unused attribute
+                                   //~^ ERROR should be an inner