Changes from feedback
This commit is contained in:
parent
864c5016ae
commit
3347993264
@ -1146,39 +1146,46 @@ fn check_attrs_usage(cx: &Context, attrs: &[ast::Attribute]) {
|
||||
}
|
||||
|
||||
fn check_unused_attribute(cx: &Context, attrs: &[ast::Attribute]) {
|
||||
for attr in attrs.iter() {
|
||||
// whitelist docs since rustdoc looks at them
|
||||
attr.check_name("automatically_derived");
|
||||
attr.check_name("doc");
|
||||
static ATTRIBUTE_WHITELIST: &'static [&'static str] = &'static [
|
||||
// FIXME: #14408 whitelist docs since rustdoc looks at them
|
||||
"doc",
|
||||
|
||||
// these are processed in trans, which happens after the lint pass
|
||||
attr.check_name("address_insignificant");
|
||||
attr.check_name("cold");
|
||||
attr.check_name("inline");
|
||||
attr.check_name("link");
|
||||
attr.check_name("link_name");
|
||||
attr.check_name("link_section");
|
||||
attr.check_name("no_builtins");
|
||||
attr.check_name("no_mangle");
|
||||
attr.check_name("no_split_stack");
|
||||
attr.check_name("packed");
|
||||
attr.check_name("static_assert");
|
||||
attr.check_name("thread_local");
|
||||
// FIXME: #14406 these are processed in trans, which happens after the
|
||||
// lint pass
|
||||
"address_insignificant",
|
||||
"cold",
|
||||
"inline",
|
||||
"link",
|
||||
"link_name",
|
||||
"link_section",
|
||||
"no_builtins",
|
||||
"no_mangle",
|
||||
"no_split_stack",
|
||||
"packed",
|
||||
"static_assert",
|
||||
"thread_local",
|
||||
|
||||
// not used anywhere (!?) but apparently we want to keep them around
|
||||
attr.check_name("comment");
|
||||
attr.check_name("desc");
|
||||
attr.check_name("license");
|
||||
"comment",
|
||||
"desc",
|
||||
"license",
|
||||
|
||||
// these are only looked at on-demand so we can't guarantee they'll have
|
||||
// already been checked
|
||||
attr.check_name("deprecated");
|
||||
attr.check_name("experimental");
|
||||
attr.check_name("frozen");
|
||||
attr.check_name("locked");
|
||||
attr.check_name("must_use");
|
||||
attr.check_name("stable");
|
||||
attr.check_name("unstable");
|
||||
// FIXME: #14407 these are only looked at on-demand so we can't
|
||||
// guarantee they'll have already been checked
|
||||
"deprecated",
|
||||
"experimental",
|
||||
"frozen",
|
||||
"locked",
|
||||
"must_use",
|
||||
"stable",
|
||||
"unstable",
|
||||
];
|
||||
for attr in attrs.iter() {
|
||||
for &name in ATTRIBUTE_WHITELIST.iter() {
|
||||
if attr.check_name(name) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if !attr::is_used(attr) {
|
||||
cx.span_lint(UnusedAttribute, attr.span, "unused attribute");
|
||||
|
@ -21,17 +21,20 @@ use parse::token;
|
||||
use crateid::CrateId;
|
||||
|
||||
use collections::HashSet;
|
||||
use collections::bitv::BitvSet;
|
||||
|
||||
local_data_key!(used_attrs: HashSet<AttrId>)
|
||||
local_data_key!(used_attrs: BitvSet)
|
||||
|
||||
pub fn mark_used(attr: &Attribute) {
|
||||
let mut used = used_attrs.replace(None).unwrap_or_else(|| HashSet::new());
|
||||
used.insert(attr.node.id);
|
||||
let mut used = used_attrs.replace(None).unwrap_or_else(|| BitvSet::new());
|
||||
let AttrId(id) = attr.node.id;
|
||||
used.insert(id);
|
||||
used_attrs.replace(Some(used));
|
||||
}
|
||||
|
||||
pub fn is_used(attr: &Attribute) -> bool {
|
||||
used_attrs.get().map_or(false, |used| used.contains(&attr.node.id))
|
||||
let AttrId(id) = attr.node.id;
|
||||
used_attrs.get().map_or(false, |used| used.contains(&id))
|
||||
}
|
||||
|
||||
pub trait AttrMetaMethods {
|
||||
@ -60,12 +63,11 @@ pub trait AttrMetaMethods {
|
||||
|
||||
impl AttrMetaMethods for Attribute {
|
||||
fn check_name(&self, name: &str) -> bool {
|
||||
if name == self.name().get() {
|
||||
let matches = name == self.name().get();
|
||||
if matches {
|
||||
mark_used(self);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
matches
|
||||
}
|
||||
fn name(&self) -> InternedString { self.meta().name() }
|
||||
fn value_str(&self) -> Option<InternedString> {
|
||||
@ -465,7 +467,6 @@ pub fn require_unique_names(diagnostic: &SpanHandler, metas: &[@MetaItem]) {
|
||||
pub fn find_repr_attr(diagnostic: &SpanHandler, attr: &Attribute, acc: ReprAttr)
|
||||
-> ReprAttr {
|
||||
let mut acc = acc;
|
||||
info!("{}", ::print::pprust::attribute_to_str(attr));
|
||||
match attr.node.value.node {
|
||||
ast::MetaList(ref s, ref items) if s.equiv(&("repr")) => {
|
||||
mark_used(attr);
|
||||
|
@ -12,6 +12,7 @@ use abi;
|
||||
use ast::{P, Ident};
|
||||
use ast;
|
||||
use ast_util;
|
||||
use attr;
|
||||
use codemap::{Span, respan, Spanned, DUMMY_SP};
|
||||
use ext::base::ExtCtxt;
|
||||
use ext::quote::rt::*;
|
||||
@ -231,7 +232,7 @@ pub trait AstBuilder {
|
||||
generics: Generics) -> @ast::Item;
|
||||
fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> @ast::Item;
|
||||
|
||||
fn attribute(&self, id: AttrId, sp: Span, mi: @ast::MetaItem) -> ast::Attribute;
|
||||
fn attribute(&self, sp: Span, mi: @ast::MetaItem) -> ast::Attribute;
|
||||
|
||||
fn meta_word(&self, sp: Span, w: InternedString) -> @ast::MetaItem;
|
||||
fn meta_list(&self,
|
||||
@ -925,10 +926,9 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||
self.item_ty_poly(span, name, ty, ast_util::empty_generics())
|
||||
}
|
||||
|
||||
fn attribute(&self, id: ast::AttrId, sp: Span, mi: @ast::MetaItem)
|
||||
-> ast::Attribute {
|
||||
fn attribute(&self, sp: Span, mi: @ast::MetaItem) -> ast::Attribute {
|
||||
respan(sp, ast::Attribute_ {
|
||||
id: id,
|
||||
id: attr::mk_attr_id(),
|
||||
style: ast::AttrOuter,
|
||||
value: mi,
|
||||
is_sugared_doc: false,
|
||||
|
@ -8,7 +8,6 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use attr;
|
||||
use ast::{MetaItem, Item, Expr};
|
||||
use codemap::Span;
|
||||
use ext::base::ExtCtxt;
|
||||
@ -22,7 +21,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt,
|
||||
item: @Item,
|
||||
push: |@Item|) {
|
||||
let inline = cx.meta_word(span, InternedString::new("inline"));
|
||||
let attrs = vec!(cx.attribute(attr::mk_attr_id(), span, inline));
|
||||
let attrs = vec!(cx.attribute(span, inline));
|
||||
let trait_def = TraitDef {
|
||||
span: span,
|
||||
attributes: Vec::new(),
|
||||
|
@ -9,7 +9,6 @@
|
||||
// except according to those terms.
|
||||
|
||||
use ast::{MetaItem, Item, Expr};
|
||||
use attr;
|
||||
use codemap::Span;
|
||||
use ext::base::ExtCtxt;
|
||||
use ext::build::AstBuilder;
|
||||
@ -35,7 +34,7 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt,
|
||||
macro_rules! md (
|
||||
($name:expr, $f:ident) => { {
|
||||
let inline = cx.meta_word(span, InternedString::new("inline"));
|
||||
let attrs = vec!(cx.attribute(attr::mk_attr_id(), span, inline));
|
||||
let attrs = vec!(cx.attribute(span, inline));
|
||||
MethodDef {
|
||||
name: $name,
|
||||
generics: LifetimeBounds::empty(),
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
use ast;
|
||||
use ast::{MetaItem, Item, Expr};
|
||||
use attr;
|
||||
use codemap::Span;
|
||||
use ext::base::ExtCtxt;
|
||||
use ext::build::AstBuilder;
|
||||
@ -25,7 +24,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt,
|
||||
macro_rules! md (
|
||||
($name:expr, $op:expr, $equal:expr) => { {
|
||||
let inline = cx.meta_word(span, InternedString::new("inline"));
|
||||
let attrs = vec!(cx.attribute(attr::mk_attr_id(), span, inline));
|
||||
let attrs = vec!(cx.attribute(span, inline));
|
||||
MethodDef {
|
||||
name: $name,
|
||||
generics: LifetimeBounds::empty(),
|
||||
|
@ -9,7 +9,6 @@
|
||||
// except according to those terms.
|
||||
|
||||
use ast::{MetaItem, Item, Expr};
|
||||
use attr;
|
||||
use codemap::Span;
|
||||
use ext::base::ExtCtxt;
|
||||
use ext::build::AstBuilder;
|
||||
@ -38,8 +37,8 @@ pub fn expand_deriving_totaleq(cx: &mut ExtCtxt,
|
||||
let inline = cx.meta_word(span, InternedString::new("inline"));
|
||||
let hidden = cx.meta_word(span, InternedString::new("hidden"));
|
||||
let doc = cx.meta_list(span, InternedString::new("doc"), vec!(hidden));
|
||||
let attrs = vec!(cx.attribute(attr::mk_attr_id(), span, inline),
|
||||
cx.attribute(attr::mk_attr_id(), span, doc));
|
||||
let attrs = vec!(cx.attribute(span, inline),
|
||||
cx.attribute(span, doc));
|
||||
let trait_def = TraitDef {
|
||||
span: span,
|
||||
attributes: Vec::new(),
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
use ast;
|
||||
use ast::{MetaItem, Item, Expr};
|
||||
use attr;
|
||||
use codemap::Span;
|
||||
use ext::base::ExtCtxt;
|
||||
use ext::build::AstBuilder;
|
||||
@ -25,7 +24,7 @@ pub fn expand_deriving_totalord(cx: &mut ExtCtxt,
|
||||
item: @Item,
|
||||
push: |@Item|) {
|
||||
let inline = cx.meta_word(span, InternedString::new("inline"));
|
||||
let attrs = vec!(cx.attribute(attr::mk_attr_id(), span, inline));
|
||||
let attrs = vec!(cx.attribute(span, inline));
|
||||
let trait_def = TraitDef {
|
||||
span: span,
|
||||
attributes: Vec::new(),
|
||||
|
@ -9,7 +9,6 @@
|
||||
// except according to those terms.
|
||||
|
||||
use ast::{MetaItem, Item, Expr};
|
||||
use attr;
|
||||
use codemap::Span;
|
||||
use ext::base::ExtCtxt;
|
||||
use ext::build::AstBuilder;
|
||||
@ -22,7 +21,7 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt,
|
||||
item: @Item,
|
||||
push: |@Item|) {
|
||||
let inline = cx.meta_word(span, InternedString::new("inline"));
|
||||
let attrs = vec!(cx.attribute(attr::mk_attr_id(), span, inline));
|
||||
let attrs = vec!(cx.attribute(span, inline));
|
||||
let trait_def = TraitDef {
|
||||
span: span,
|
||||
attributes: Vec::new(),
|
||||
|
@ -428,10 +428,11 @@ impl<'a> TraitDef<'a> {
|
||||
self_ty_params.into_vec()), None);
|
||||
|
||||
let attr = cx.attribute(
|
||||
attr::mk_attr_id(),
|
||||
self.span,
|
||||
cx.meta_word(self.span,
|
||||
InternedString::new("automatically_derived")));
|
||||
// Just mark it now since we know that it'll end up used downstream
|
||||
attr::mark_used(&attr);
|
||||
let opt_trait_ref = Some(trait_ref);
|
||||
let ident = ast_util::impl_pretty_name(&opt_trait_ref, self_type);
|
||||
cx.item(
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
use ast;
|
||||
use ast::{MetaItem, Item, Expr, MutMutable};
|
||||
use attr;
|
||||
use codemap::Span;
|
||||
use ext::base::ExtCtxt;
|
||||
use ext::build::AstBuilder;
|
||||
@ -38,7 +37,7 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt,
|
||||
Path::new(vec!("std", "hash", "sip", "SipState")))
|
||||
};
|
||||
let inline = cx.meta_word(span, InternedString::new("inline"));
|
||||
let attrs = vec!(cx.attribute(attr::mk_attr_id(), span, inline));
|
||||
let attrs = vec!(cx.attribute(span, inline));
|
||||
let hash_trait_def = TraitDef {
|
||||
span: span,
|
||||
attributes: Vec::new(),
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
use ast::{MetaItem, Item, Expr};
|
||||
use ast;
|
||||
use attr;
|
||||
use codemap::Span;
|
||||
use ext::base::ExtCtxt;
|
||||
use ext::build::AstBuilder;
|
||||
@ -23,7 +22,7 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt,
|
||||
item: @Item,
|
||||
push: |@Item|) {
|
||||
let inline = cx.meta_word(span, InternedString::new("inline"));
|
||||
let attrs = vec!(cx.attribute(attr::mk_attr_id(), span, inline));
|
||||
let attrs = vec!(cx.attribute(span, inline));
|
||||
let trait_def = TraitDef {
|
||||
span: span,
|
||||
attributes: Vec::new(),
|
||||
|
@ -9,7 +9,6 @@
|
||||
// except according to those terms.
|
||||
|
||||
use ast::{MetaItem, Item, Expr};
|
||||
use attr;
|
||||
use codemap::Span;
|
||||
use ext::base::ExtCtxt;
|
||||
use ext::build::AstBuilder;
|
||||
@ -22,7 +21,7 @@ pub fn expand_deriving_zero(cx: &mut ExtCtxt,
|
||||
item: @Item,
|
||||
push: |@Item|) {
|
||||
let inline = cx.meta_word(span, InternedString::new("inline"));
|
||||
let attrs = vec!(cx.attribute(attr::mk_attr_id(), span, inline));
|
||||
let attrs = vec!(cx.attribute(span, inline));
|
||||
let trait_def = TraitDef {
|
||||
span: span,
|
||||
attributes: Vec::new(),
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
use ast;
|
||||
use ast::P;
|
||||
use attr;
|
||||
use codemap::{Span, respan};
|
||||
use ext::base::*;
|
||||
use ext::base;
|
||||
@ -383,8 +382,7 @@ impl<'a, 'b> Context<'a, 'b> {
|
||||
.meta_word(self.fmtsp,
|
||||
InternedString::new(
|
||||
"address_insignificant"));
|
||||
let unnamed = self.ecx.attribute(attr::mk_attr_id(), self.fmtsp,
|
||||
unnamed);
|
||||
let unnamed = self.ecx.attribute(self.fmtsp, unnamed);
|
||||
|
||||
// Do not warn format string as dead code
|
||||
let dead_code = self.ecx.meta_word(self.fmtsp,
|
||||
@ -392,8 +390,7 @@ impl<'a, 'b> Context<'a, 'b> {
|
||||
let allow_dead_code = self.ecx.meta_list(self.fmtsp,
|
||||
InternedString::new("allow"),
|
||||
vec!(dead_code));
|
||||
let allow_dead_code = self.ecx.attribute(attr::mk_attr_id(), self.fmtsp,
|
||||
allow_dead_code);
|
||||
let allow_dead_code = self.ecx.attribute(self.fmtsp, allow_dead_code);
|
||||
return vec!(unnamed, allow_dead_code);
|
||||
}
|
||||
|
||||
|
@ -135,10 +135,10 @@ impl<'a> ParserAttr for Parser<'a> {
|
||||
// we need to get the position of this token before we bump.
|
||||
let Span { lo, hi, .. } = self.span;
|
||||
self.bump();
|
||||
::attr::mk_sugared_doc_attr(attr::mk_attr_id(),
|
||||
self.id_to_interned_str(s),
|
||||
lo,
|
||||
hi)
|
||||
attr::mk_sugared_doc_attr(attr::mk_attr_id(),
|
||||
self.id_to_interned_str(s),
|
||||
lo,
|
||||
hi)
|
||||
}
|
||||
_ => {
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user