Skip to content

Commit 3347993

Browse files
committed
Changes from feedback
1 parent 864c501 commit 3347993

File tree

15 files changed

+70
-73
lines changed

15 files changed

+70
-73
lines changed

src/librustc/middle/lint.rs

+38-31
Original file line numberDiff line numberDiff line change
@@ -1146,39 +1146,46 @@ fn check_attrs_usage(cx: &Context, attrs: &[ast::Attribute]) {
11461146
}
11471147

11481148
fn check_unused_attribute(cx: &Context, attrs: &[ast::Attribute]) {
1149-
for attr in attrs.iter() {
1150-
// whitelist docs since rustdoc looks at them
1151-
attr.check_name("automatically_derived");
1152-
attr.check_name("doc");
1153-
1154-
// these are processed in trans, which happens after the lint pass
1155-
attr.check_name("address_insignificant");
1156-
attr.check_name("cold");
1157-
attr.check_name("inline");
1158-
attr.check_name("link");
1159-
attr.check_name("link_name");
1160-
attr.check_name("link_section");
1161-
attr.check_name("no_builtins");
1162-
attr.check_name("no_mangle");
1163-
attr.check_name("no_split_stack");
1164-
attr.check_name("packed");
1165-
attr.check_name("static_assert");
1166-
attr.check_name("thread_local");
1149+
static ATTRIBUTE_WHITELIST: &'static [&'static str] = &'static [
1150+
// FIXME: #14408 whitelist docs since rustdoc looks at them
1151+
"doc",
1152+
1153+
// FIXME: #14406 these are processed in trans, which happens after the
1154+
// lint pass
1155+
"address_insignificant",
1156+
"cold",
1157+
"inline",
1158+
"link",
1159+
"link_name",
1160+
"link_section",
1161+
"no_builtins",
1162+
"no_mangle",
1163+
"no_split_stack",
1164+
"packed",
1165+
"static_assert",
1166+
"thread_local",
11671167

11681168
// not used anywhere (!?) but apparently we want to keep them around
1169-
attr.check_name("comment");
1170-
attr.check_name("desc");
1171-
attr.check_name("license");
1172-
1173-
// these are only looked at on-demand so we can't guarantee they'll have
1174-
// already been checked
1175-
attr.check_name("deprecated");
1176-
attr.check_name("experimental");
1177-
attr.check_name("frozen");
1178-
attr.check_name("locked");
1179-
attr.check_name("must_use");
1180-
attr.check_name("stable");
1181-
attr.check_name("unstable");
1169+
"comment",
1170+
"desc",
1171+
"license",
1172+
1173+
// FIXME: #14407 these are only looked at on-demand so we can't
1174+
// guarantee they'll have already been checked
1175+
"deprecated",
1176+
"experimental",
1177+
"frozen",
1178+
"locked",
1179+
"must_use",
1180+
"stable",
1181+
"unstable",
1182+
];
1183+
for attr in attrs.iter() {
1184+
for &name in ATTRIBUTE_WHITELIST.iter() {
1185+
if attr.check_name(name) {
1186+
break;
1187+
}
1188+
}
11821189

11831190
if !attr::is_used(attr) {
11841191
cx.span_lint(UnusedAttribute, attr.span, "unused attribute");

src/libsyntax/attr.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,20 @@ use parse::token;
2121
use crateid::CrateId;
2222

2323
use collections::HashSet;
24+
use collections::bitv::BitvSet;
2425

25-
local_data_key!(used_attrs: HashSet<AttrId>)
26+
local_data_key!(used_attrs: BitvSet)
2627

2728
pub fn mark_used(attr: &Attribute) {
28-
let mut used = used_attrs.replace(None).unwrap_or_else(|| HashSet::new());
29-
used.insert(attr.node.id);
29+
let mut used = used_attrs.replace(None).unwrap_or_else(|| BitvSet::new());
30+
let AttrId(id) = attr.node.id;
31+
used.insert(id);
3032
used_attrs.replace(Some(used));
3133
}
3234

3335
pub fn is_used(attr: &Attribute) -> bool {
34-
used_attrs.get().map_or(false, |used| used.contains(&attr.node.id))
36+
let AttrId(id) = attr.node.id;
37+
used_attrs.get().map_or(false, |used| used.contains(&id))
3538
}
3639

3740
pub trait AttrMetaMethods {
@@ -60,12 +63,11 @@ pub trait AttrMetaMethods {
6063

6164
impl AttrMetaMethods for Attribute {
6265
fn check_name(&self, name: &str) -> bool {
63-
if name == self.name().get() {
66+
let matches = name == self.name().get();
67+
if matches {
6468
mark_used(self);
65-
true
66-
} else {
67-
false
6869
}
70+
matches
6971
}
7072
fn name(&self) -> InternedString { self.meta().name() }
7173
fn value_str(&self) -> Option<InternedString> {
@@ -465,7 +467,6 @@ pub fn require_unique_names(diagnostic: &SpanHandler, metas: &[@MetaItem]) {
465467
pub fn find_repr_attr(diagnostic: &SpanHandler, attr: &Attribute, acc: ReprAttr)
466468
-> ReprAttr {
467469
let mut acc = acc;
468-
info!("{}", ::print::pprust::attribute_to_str(attr));
469470
match attr.node.value.node {
470471
ast::MetaList(ref s, ref items) if s.equiv(&("repr")) => {
471472
mark_used(attr);

src/libsyntax/ext/build.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use abi;
1212
use ast::{P, Ident};
1313
use ast;
1414
use ast_util;
15+
use attr;
1516
use codemap::{Span, respan, Spanned, DUMMY_SP};
1617
use ext::base::ExtCtxt;
1718
use ext::quote::rt::*;
@@ -231,7 +232,7 @@ pub trait AstBuilder {
231232
generics: Generics) -> @ast::Item;
232233
fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> @ast::Item;
233234

234-
fn attribute(&self, id: AttrId, sp: Span, mi: @ast::MetaItem) -> ast::Attribute;
235+
fn attribute(&self, sp: Span, mi: @ast::MetaItem) -> ast::Attribute;
235236

236237
fn meta_word(&self, sp: Span, w: InternedString) -> @ast::MetaItem;
237238
fn meta_list(&self,
@@ -925,10 +926,9 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
925926
self.item_ty_poly(span, name, ty, ast_util::empty_generics())
926927
}
927928

928-
fn attribute(&self, id: ast::AttrId, sp: Span, mi: @ast::MetaItem)
929-
-> ast::Attribute {
929+
fn attribute(&self, sp: Span, mi: @ast::MetaItem) -> ast::Attribute {
930930
respan(sp, ast::Attribute_ {
931-
id: id,
931+
id: attr::mk_attr_id(),
932932
style: ast::AttrOuter,
933933
value: mi,
934934
is_sugared_doc: false,

src/libsyntax/ext/deriving/clone.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use attr;
1211
use ast::{MetaItem, Item, Expr};
1312
use codemap::Span;
1413
use ext::base::ExtCtxt;
@@ -22,7 +21,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt,
2221
item: @Item,
2322
push: |@Item|) {
2423
let inline = cx.meta_word(span, InternedString::new("inline"));
25-
let attrs = vec!(cx.attribute(attr::mk_attr_id(), span, inline));
24+
let attrs = vec!(cx.attribute(span, inline));
2625
let trait_def = TraitDef {
2726
span: span,
2827
attributes: Vec::new(),

src/libsyntax/ext/deriving/cmp/eq.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use ast::{MetaItem, Item, Expr};
12-
use attr;
1312
use codemap::Span;
1413
use ext::base::ExtCtxt;
1514
use ext::build::AstBuilder;
@@ -35,7 +34,7 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt,
3534
macro_rules! md (
3635
($name:expr, $f:ident) => { {
3736
let inline = cx.meta_word(span, InternedString::new("inline"));
38-
let attrs = vec!(cx.attribute(attr::mk_attr_id(), span, inline));
37+
let attrs = vec!(cx.attribute(span, inline));
3938
MethodDef {
4039
name: $name,
4140
generics: LifetimeBounds::empty(),

src/libsyntax/ext/deriving/cmp/ord.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use ast;
1212
use ast::{MetaItem, Item, Expr};
13-
use attr;
1413
use codemap::Span;
1514
use ext::base::ExtCtxt;
1615
use ext::build::AstBuilder;
@@ -25,7 +24,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt,
2524
macro_rules! md (
2625
($name:expr, $op:expr, $equal:expr) => { {
2726
let inline = cx.meta_word(span, InternedString::new("inline"));
28-
let attrs = vec!(cx.attribute(attr::mk_attr_id(), span, inline));
27+
let attrs = vec!(cx.attribute(span, inline));
2928
MethodDef {
3029
name: $name,
3130
generics: LifetimeBounds::empty(),

src/libsyntax/ext/deriving/cmp/totaleq.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use ast::{MetaItem, Item, Expr};
12-
use attr;
1312
use codemap::Span;
1413
use ext::base::ExtCtxt;
1514
use ext::build::AstBuilder;
@@ -38,8 +37,8 @@ pub fn expand_deriving_totaleq(cx: &mut ExtCtxt,
3837
let inline = cx.meta_word(span, InternedString::new("inline"));
3938
let hidden = cx.meta_word(span, InternedString::new("hidden"));
4039
let doc = cx.meta_list(span, InternedString::new("doc"), vec!(hidden));
41-
let attrs = vec!(cx.attribute(attr::mk_attr_id(), span, inline),
42-
cx.attribute(attr::mk_attr_id(), span, doc));
40+
let attrs = vec!(cx.attribute(span, inline),
41+
cx.attribute(span, doc));
4342
let trait_def = TraitDef {
4443
span: span,
4544
attributes: Vec::new(),

src/libsyntax/ext/deriving/cmp/totalord.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use ast;
1212
use ast::{MetaItem, Item, Expr};
13-
use attr;
1413
use codemap::Span;
1514
use ext::base::ExtCtxt;
1615
use ext::build::AstBuilder;
@@ -25,7 +24,7 @@ pub fn expand_deriving_totalord(cx: &mut ExtCtxt,
2524
item: @Item,
2625
push: |@Item|) {
2726
let inline = cx.meta_word(span, InternedString::new("inline"));
28-
let attrs = vec!(cx.attribute(attr::mk_attr_id(), span, inline));
27+
let attrs = vec!(cx.attribute(span, inline));
2928
let trait_def = TraitDef {
3029
span: span,
3130
attributes: Vec::new(),

src/libsyntax/ext/deriving/default.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use ast::{MetaItem, Item, Expr};
12-
use attr;
1312
use codemap::Span;
1413
use ext::base::ExtCtxt;
1514
use ext::build::AstBuilder;
@@ -22,7 +21,7 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt,
2221
item: @Item,
2322
push: |@Item|) {
2423
let inline = cx.meta_word(span, InternedString::new("inline"));
25-
let attrs = vec!(cx.attribute(attr::mk_attr_id(), span, inline));
24+
let attrs = vec!(cx.attribute(span, inline));
2625
let trait_def = TraitDef {
2726
span: span,
2827
attributes: Vec::new(),

src/libsyntax/ext/deriving/generic/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,11 @@ impl<'a> TraitDef<'a> {
428428
self_ty_params.into_vec()), None);
429429

430430
let attr = cx.attribute(
431-
attr::mk_attr_id(),
432431
self.span,
433432
cx.meta_word(self.span,
434433
InternedString::new("automatically_derived")));
434+
// Just mark it now since we know that it'll end up used downstream
435+
attr::mark_used(&attr);
435436
let opt_trait_ref = Some(trait_ref);
436437
let ident = ast_util::impl_pretty_name(&opt_trait_ref, self_type);
437438
cx.item(

src/libsyntax/ext/deriving/hash.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use ast;
1212
use ast::{MetaItem, Item, Expr, MutMutable};
13-
use attr;
1413
use codemap::Span;
1514
use ext::base::ExtCtxt;
1615
use ext::build::AstBuilder;
@@ -38,7 +37,7 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt,
3837
Path::new(vec!("std", "hash", "sip", "SipState")))
3938
};
4039
let inline = cx.meta_word(span, InternedString::new("inline"));
41-
let attrs = vec!(cx.attribute(attr::mk_attr_id(), span, inline));
40+
let attrs = vec!(cx.attribute(span, inline));
4241
let hash_trait_def = TraitDef {
4342
span: span,
4443
attributes: Vec::new(),

src/libsyntax/ext/deriving/primitive.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use ast::{MetaItem, Item, Expr};
1212
use ast;
13-
use attr;
1413
use codemap::Span;
1514
use ext::base::ExtCtxt;
1615
use ext::build::AstBuilder;
@@ -23,7 +22,7 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt,
2322
item: @Item,
2423
push: |@Item|) {
2524
let inline = cx.meta_word(span, InternedString::new("inline"));
26-
let attrs = vec!(cx.attribute(attr::mk_attr_id(), span, inline));
25+
let attrs = vec!(cx.attribute(span, inline));
2726
let trait_def = TraitDef {
2827
span: span,
2928
attributes: Vec::new(),

src/libsyntax/ext/deriving/zero.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use ast::{MetaItem, Item, Expr};
12-
use attr;
1312
use codemap::Span;
1413
use ext::base::ExtCtxt;
1514
use ext::build::AstBuilder;
@@ -22,7 +21,7 @@ pub fn expand_deriving_zero(cx: &mut ExtCtxt,
2221
item: @Item,
2322
push: |@Item|) {
2423
let inline = cx.meta_word(span, InternedString::new("inline"));
25-
let attrs = vec!(cx.attribute(attr::mk_attr_id(), span, inline));
24+
let attrs = vec!(cx.attribute(span, inline));
2625
let trait_def = TraitDef {
2726
span: span,
2827
attributes: Vec::new(),

src/libsyntax/ext/format.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use ast;
1212
use ast::P;
13-
use attr;
1413
use codemap::{Span, respan};
1514
use ext::base::*;
1615
use ext::base;
@@ -383,17 +382,15 @@ impl<'a, 'b> Context<'a, 'b> {
383382
.meta_word(self.fmtsp,
384383
InternedString::new(
385384
"address_insignificant"));
386-
let unnamed = self.ecx.attribute(attr::mk_attr_id(), self.fmtsp,
387-
unnamed);
385+
let unnamed = self.ecx.attribute(self.fmtsp, unnamed);
388386

389387
// Do not warn format string as dead code
390388
let dead_code = self.ecx.meta_word(self.fmtsp,
391389
InternedString::new("dead_code"));
392390
let allow_dead_code = self.ecx.meta_list(self.fmtsp,
393391
InternedString::new("allow"),
394392
vec!(dead_code));
395-
let allow_dead_code = self.ecx.attribute(attr::mk_attr_id(), self.fmtsp,
396-
allow_dead_code);
393+
let allow_dead_code = self.ecx.attribute(self.fmtsp, allow_dead_code);
397394
return vec!(unnamed, allow_dead_code);
398395
}
399396

src/libsyntax/parse/attr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ impl<'a> ParserAttr for Parser<'a> {
135135
// we need to get the position of this token before we bump.
136136
let Span { lo, hi, .. } = self.span;
137137
self.bump();
138-
::attr::mk_sugared_doc_attr(attr::mk_attr_id(),
139-
self.id_to_interned_str(s),
140-
lo,
141-
hi)
138+
attr::mk_sugared_doc_attr(attr::mk_attr_id(),
139+
self.id_to_interned_str(s),
140+
lo,
141+
hi)
142142
}
143143
_ => {
144144
break;

0 commit comments

Comments
 (0)