Skip to content

Commit

Permalink
Add back hint for crate level attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed Jun 8, 2014
1 parent 42a18bd commit 862cd65
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/librustc/middle/lint.rs
Expand Up @@ -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;
Expand All @@ -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);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/lint-misplaced-attr.rs
Expand Up @@ -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

0 comments on commit 862cd65

Please sign in to comment.