about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorSteven Fackler <sfackler@gmail.com>2014-06-08 00:21:15 -0700
committerSteven Fackler <sfackler@gmail.com>2014-06-08 00:21:15 -0700
commit862cd65dcadf34b5ab59063be151ab801fc7bfe1 (patch)
treed21421206166a936e4dedc788a87ab57aa6ba764 /src
parent42a18bd985e103484abbe801082b0593f1a43019 (diff)
downloadrust-862cd65dcadf34b5ab59063be151ab801fc7bfe1.tar.gz
rust-862cd65dcadf34b5ab59063be151ab801fc7bfe1.zip
Add back hint for crate level attributes
Diffstat (limited to 'src')
-rw-r--r--src/librustc/middle/lint.rs23
-rw-r--r--src/test/compile-fail/lint-misplaced-attr.rs2
2 files changed, 25 insertions, 0 deletions
diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs
index 8d76535af7f..9500f4d7cee 100644
--- a/src/librustc/middle/lint.rs
+++ b/src/librustc/middle/lint.rs
@@ -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);
+        }
     }
 }
 
diff --git a/src/test/compile-fail/lint-misplaced-attr.rs b/src/test/compile-fail/lint-misplaced-attr.rs
index 9af48527435..dea712e976b 100644
--- a/src/test/compile-fail/lint-misplaced-attr.rs
+++ b/src/test/compile-fail/lint-misplaced-attr.rs
@@ -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