Skip to content

Commit 9605d87

Browse files
committed
---
yaml --- r: 118309 b: refs/heads/try c: 862cd65 h: refs/heads/master i: 118307: 8d0091a v: v3
1 parent 9381f28 commit 9605d87

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 3770c42a4959cbabc73da52abc7e3db96657974e
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: d6736a1440d42f6af967a8a20ab8d73522112b72
5-
refs/heads/try: 42a18bd985e103484abbe801082b0593f1a43019
5+
refs/heads/try: 862cd65dcadf34b5ab59063be151ab801fc7bfe1
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/librustc/middle/lint.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,20 @@ fn check_unused_attribute(cx: &Context, attr: &ast::Attribute) {
11241124
"unstable",
11251125
];
11261126

1127+
static CRATE_ATTRS: &'static [&'static str] = &'static [
1128+
"crate_type",
1129+
"feature",
1130+
"no_start",
1131+
"no_main",
1132+
"no_std",
1133+
"crate_id",
1134+
"desc",
1135+
"comment",
1136+
"license",
1137+
"copyright",
1138+
"no_builtins",
1139+
];
1140+
11271141
for &name in ATTRIBUTE_WHITELIST.iter() {
11281142
if attr.check_name(name) {
11291143
break;
@@ -1132,6 +1146,15 @@ fn check_unused_attribute(cx: &Context, attr: &ast::Attribute) {
11321146

11331147
if !attr::is_used(attr) {
11341148
cx.span_lint(UnusedAttribute, attr.span, "unused attribute");
1149+
if CRATE_ATTRS.contains(&attr.name().get()) {
1150+
let msg = match attr.node.style {
1151+
ast::AttrOuter => "crate-level attribute should be an inner \
1152+
attribute: add an exclamation mark: #![foo]",
1153+
ast::AttrInner => "crate-level attribute should be in the \
1154+
root module",
1155+
};
1156+
cx.span_lint(UnusedAttribute, attr.span, msg);
1157+
}
11351158
}
11361159
}
11371160

branches/try/src/test/compile-fail/lint-misplaced-attr.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
mod a {
1717
#![crate_type = "bin"] //~ ERROR unused attribute
18+
//~^ ERROR should be in the root module
1819
}
1920

2021
#[crate_type = "bin"] fn main() {} //~ ERROR unused attribute
22+
//~^ ERROR should be an inner

0 commit comments

Comments
 (0)