Skip to content

Commit 531a06e

Browse files
committed
Move ATTRIBUTE_WHITELIST and CRATE_ATTRS to KNOWN_ATTRIBUTES in syntax::feature_gate
1 parent c5db290 commit 531a06e

File tree

2 files changed

+73
-55
lines changed

2 files changed

+73
-55
lines changed

src/librustc/lint/builtin.rs

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ use syntax::{abi, ast, ast_map};
4747
use syntax::ast_util::is_shift_binop;
4848
use syntax::attr::{self, AttrMetaMethods};
4949
use syntax::codemap::{self, Span};
50+
use syntax::feature_gate::{KNOWN_ATTRIBUTES, AttributeType};
5051
use syntax::parse::token;
5152
use syntax::ast::{TyIs, TyUs, TyI8, TyU8, TyI16, TyU16, TyI32, TyU32, TyI64, TyU64};
5253
use syntax::ast_util;
@@ -640,67 +641,15 @@ impl LintPass for UnusedAttributes {
640641
}
641642

642643
fn check_attribute(&mut self, cx: &Context, attr: &ast::Attribute) {
643-
static ATTRIBUTE_WHITELIST: &'static [&'static str] = &[
644-
// FIXME: #14408 whitelist docs since rustdoc looks at them
645-
"doc",
646-
647-
// FIXME: #14406 these are processed in trans, which happens after the
648-
// lint pass
649-
"cold",
650-
"export_name",
651-
"inline",
652-
"link",
653-
"link_name",
654-
"link_section",
655-
"linkage",
656-
"no_builtins",
657-
"no_mangle",
658-
"no_split_stack",
659-
"no_stack_check",
660-
"packed",
661-
"static_assert",
662-
"thread_local",
663-
"no_debug",
664-
"omit_gdb_pretty_printer_section",
665-
"unsafe_no_drop_flag",
666-
667-
// used in resolve
668-
"prelude_import",
669-
670-
// FIXME: #14407 these are only looked at on-demand so we can't
671-
// guarantee they'll have already been checked
672-
"deprecated",
673-
"must_use",
674-
"stable",
675-
"unstable",
676-
"rustc_on_unimplemented",
677-
"rustc_error",
678-
679-
// FIXME: #19470 this shouldn't be needed forever
680-
"old_orphan_check",
681-
"old_impl_check",
682-
"rustc_paren_sugar", // FIXME: #18101 temporary unboxed closure hack
683-
];
684-
685-
static CRATE_ATTRS: &'static [&'static str] = &[
686-
"crate_name",
687-
"crate_type",
688-
"feature",
689-
"no_start",
690-
"no_main",
691-
"no_std",
692-
"no_builtins",
693-
];
694-
695-
for &name in ATTRIBUTE_WHITELIST {
696-
if attr.check_name(name) {
644+
for &(ref name, ty) in KNOWN_ATTRIBUTES {
645+
if ty == AttributeType::Whitelisted && attr.check_name(name) {
697646
break;
698647
}
699648
}
700649

701650
if !attr::is_used(attr) {
702651
cx.span_lint(UNUSED_ATTRIBUTES, attr.span, "unused attribute");
703-
if CRATE_ATTRS.contains(&&attr.name()[]) {
652+
if KNOWN_ATTRIBUTES.contains(&(&attr.name()[], AttributeType::CrateLevel)) {
704653
let msg = match attr.node.style {
705654
ast::AttrOuter => "crate-level attribute should be an inner \
706655
attribute: add an exclamation mark: #![foo]",

src/libsyntax/feature_gate.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
//! becomes stable.
2424
2525
use self::Status::*;
26+
use self::AttributeType::*;
2627

2728
use abi::RustIntrinsic;
2829
use ast::NodeId;
@@ -152,6 +153,74 @@ enum Status {
152153
Accepted,
153154
}
154155

156+
// Attributes that have a special meaning to rustc or rustdoc
157+
pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[
158+
159+
// FIXME: #14408 whitelist docs since rustdoc looks at them
160+
("doc", Whitelisted),
161+
162+
// FIXME: #14406 these are processed in trans, which happens after the
163+
// lint pass
164+
("cold", Whitelisted),
165+
("export_name", Whitelisted),
166+
("inline", Whitelisted),
167+
("link", Whitelisted),
168+
("link_name", Whitelisted),
169+
("link_section", Whitelisted),
170+
("linkage", Whitelisted),
171+
("no_builtins", Whitelisted),
172+
("no_mangle", Whitelisted),
173+
("no_split_stack", Whitelisted),
174+
("no_stack_check", Whitelisted),
175+
("packed", Whitelisted),
176+
("static_assert", Whitelisted),
177+
("thread_local", Whitelisted),
178+
("no_debug", Whitelisted),
179+
("omit_gdb_pretty_printer_section", Whitelisted),
180+
("unsafe_no_drop_flag", Whitelisted),
181+
182+
// used in resolve
183+
("prelude_import", Whitelisted),
184+
185+
// FIXME: #14407 these are only looked at on-demand so we can't
186+
// guarantee they'll have already been checked
187+
("deprecated", Whitelisted),
188+
("must_use", Whitelisted),
189+
("stable", Whitelisted),
190+
("unstable", Whitelisted),
191+
("rustc_on_unimplemented", Whitelisted),
192+
("rustc_error", Whitelisted),
193+
194+
// FIXME: #19470 this shouldn't be needed forever
195+
("old_orphan_check", Whitelisted),
196+
("old_impl_check", Whitelisted),
197+
("rustc_paren_sugar", Whitelisted), // FIXME: #18101 temporary unboxed closure hack
198+
199+
// Crate level attributes
200+
("crate_name", CrateLevel),
201+
("crate_type", CrateLevel),
202+
("feature", CrateLevel),
203+
("no_start", CrateLevel),
204+
("no_main", CrateLevel),
205+
("no_std", CrateLevel),
206+
("no_builtins", CrateLevel),
207+
];
208+
209+
#[derive(PartialEq, Copy)]
210+
pub enum AttributeType {
211+
/// Normal, builtin attribute that is consumed
212+
/// by the compiler before the unused_attribute check
213+
Normal,
214+
215+
/// Builtin attribute that may not be consumed by the compiler
216+
/// before the unused_attribute check. These attributes
217+
/// will be ignored by the unused_attribute lint
218+
Whitelisted,
219+
220+
/// Builtin attribute that is only allowed at the crate level
221+
CrateLevel,
222+
}
223+
155224
/// A set of features to be used by later passes.
156225
pub struct Features {
157226
pub unboxed_closures: bool,

0 commit comments

Comments
 (0)