Prefer to use attr::contains_name() and attr::find_by_name()
This commit is contained in:
parent
18da3c671b
commit
d882691046
13 changed files with 25 additions and 29 deletions
|
@ -1571,7 +1571,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
bounds,
|
bounds,
|
||||||
default: tp.default.as_ref().map(|x| self.lower_ty(x, ImplTraitContext::Disallowed)),
|
default: tp.default.as_ref().map(|x| self.lower_ty(x, ImplTraitContext::Disallowed)),
|
||||||
span: tp.span,
|
span: tp.span,
|
||||||
pure_wrt_drop: tp.attrs.iter().any(|attr| attr.check_name("may_dangle")),
|
pure_wrt_drop: attr::contains_name(&tp.attrs, "may_dangle"),
|
||||||
synthetic: tp.attrs.iter()
|
synthetic: tp.attrs.iter()
|
||||||
.filter(|attr| attr.check_name("rustc_synthetic"))
|
.filter(|attr| attr.check_name("rustc_synthetic"))
|
||||||
.map(|_| hir::SyntheticTyParamKind::ImplTrait)
|
.map(|_| hir::SyntheticTyParamKind::ImplTrait)
|
||||||
|
@ -1611,7 +1611,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
let def = hir::LifetimeDef {
|
let def = hir::LifetimeDef {
|
||||||
lifetime: self.lower_lifetime(&l.lifetime),
|
lifetime: self.lower_lifetime(&l.lifetime),
|
||||||
bounds: self.lower_lifetimes(&l.bounds),
|
bounds: self.lower_lifetimes(&l.bounds),
|
||||||
pure_wrt_drop: l.attrs.iter().any(|attr| attr.check_name("may_dangle")),
|
pure_wrt_drop: attr::contains_name(&l.attrs, "may_dangle"),
|
||||||
in_band: false,
|
in_band: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2331,7 +2331,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
let mut vis = self.lower_visibility(&i.vis, None);
|
let mut vis = self.lower_visibility(&i.vis, None);
|
||||||
let attrs = self.lower_attrs(&i.attrs);
|
let attrs = self.lower_attrs(&i.attrs);
|
||||||
if let ItemKind::MacroDef(ref def) = i.node {
|
if let ItemKind::MacroDef(ref def) = i.node {
|
||||||
if !def.legacy || i.attrs.iter().any(|attr| attr.path == "macro_export") {
|
if !def.legacy || attr::contains_name(&i.attrs, "macro_export") {
|
||||||
let body = self.lower_token_stream(def.stream());
|
let body = self.lower_token_stream(def.stream());
|
||||||
self.exported_macros.push(hir::MacroDef {
|
self.exported_macros.push(hir::MacroDef {
|
||||||
name,
|
name,
|
||||||
|
|
|
@ -140,9 +140,7 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedDirective {
|
||||||
{
|
{
|
||||||
let attrs = tcx.get_attrs(impl_def_id);
|
let attrs = tcx.get_attrs(impl_def_id);
|
||||||
|
|
||||||
let attr = if let Some(item) =
|
let attr = if let Some(item) = attr::find_by_name(&attrs, "rustc_on_unimplemented") {
|
||||||
attrs.into_iter().find(|a| a.check_name("rustc_on_unimplemented"))
|
|
||||||
{
|
|
||||||
item
|
item
|
||||||
} else {
|
} else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
|
|
|
@ -2402,7 +2402,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||||
|
|
||||||
/// Determine whether an item is annotated with an attribute
|
/// Determine whether an item is annotated with an attribute
|
||||||
pub fn has_attr(self, did: DefId, attr: &str) -> bool {
|
pub fn has_attr(self, did: DefId, attr: &str) -> bool {
|
||||||
self.get_attrs(did).iter().any(|item| item.check_name(attr))
|
attr::contains_name(&self.get_attrs(did), attr)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this is an `auto trait`.
|
/// Returns true if this is an `auto trait`.
|
||||||
|
|
|
@ -3,7 +3,7 @@ compiler as a whole, see
|
||||||
[the README.md file found in `librustc`](../librustc/README.md).
|
[the README.md file found in `librustc`](../librustc/README.md).
|
||||||
|
|
||||||
The `driver` crate is effectively the "main" function for the rust
|
The `driver` crate is effectively the "main" function for the rust
|
||||||
compiler. It orchstrates the compilation process and "knits together"
|
compiler. It orchestrates the compilation process and "knits together"
|
||||||
the code from the other crates within rustc. This crate itself does
|
the code from the other crates within rustc. This crate itself does
|
||||||
not contain any of the "main logic" of the compiler (though it does
|
not contain any of the "main logic" of the compiler (though it does
|
||||||
have some code related to pretty printing or other minor compiler
|
have some code related to pretty printing or other minor compiler
|
||||||
|
|
|
@ -221,9 +221,7 @@ impl LintPass for NonSnakeCase {
|
||||||
|
|
||||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
|
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
|
||||||
fn check_crate(&mut self, cx: &LateContext, cr: &hir::Crate) {
|
fn check_crate(&mut self, cx: &LateContext, cr: &hir::Crate) {
|
||||||
let attr_crate_name = cr.attrs
|
let attr_crate_name = attr::find_by_name(&cr.attrs, "crate_name")
|
||||||
.iter()
|
|
||||||
.find(|at| at.check_name("crate_name"))
|
|
||||||
.and_then(|at| at.value_str().map(|s| (at, s)));
|
.and_then(|at| at.value_str().map(|s| (at, s)));
|
||||||
if let Some(ref name) = cx.tcx.sess.opts.crate_name {
|
if let Some(ref name) = cx.tcx.sess.opts.crate_name {
|
||||||
self.check_snake_case(cx, "crate", name, None);
|
self.check_snake_case(cx, "crate", name, None);
|
||||||
|
|
|
@ -27,6 +27,7 @@ use rustc::ty::subst::Subst;
|
||||||
use rustc::ty::{self, Ty, TyCtxt};
|
use rustc::ty::{self, Ty, TyCtxt};
|
||||||
use rustc::ty::subst::Substs;
|
use rustc::ty::subst::Substs;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
|
use syntax::attr;
|
||||||
use syntax::symbol::Symbol;
|
use syntax::symbol::Symbol;
|
||||||
use rustc::hir;
|
use rustc::hir;
|
||||||
use rustc_const_math::{ConstInt, ConstUsize};
|
use rustc_const_math::{ConstInt, ConstUsize};
|
||||||
|
@ -78,8 +79,7 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
|
||||||
// Some functions always have overflow checks enabled,
|
// Some functions always have overflow checks enabled,
|
||||||
// however, they may not get codegen'd, depending on
|
// however, they may not get codegen'd, depending on
|
||||||
// the settings for the crate they are translated in.
|
// the settings for the crate they are translated in.
|
||||||
let mut check_overflow = attrs.iter()
|
let mut check_overflow = attr::contains_name(attrs, "rustc_inherit_overflow_checks");
|
||||||
.any(|item| item.check_name("rustc_inherit_overflow_checks"));
|
|
||||||
|
|
||||||
// Respect -C overflow-checks.
|
// Respect -C overflow-checks.
|
||||||
check_overflow |= tcx.sess.overflow_checks();
|
check_overflow |= tcx.sess.overflow_checks();
|
||||||
|
|
|
@ -51,8 +51,7 @@ impl<'a> AstValidator<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn invalid_non_exhaustive_attribute(&self, variant: &Variant) {
|
fn invalid_non_exhaustive_attribute(&self, variant: &Variant) {
|
||||||
let has_non_exhaustive = variant.node.attrs.iter()
|
let has_non_exhaustive = attr::contains_name(&variant.node.attrs, "non_exhaustive");
|
||||||
.any(|attr| attr.check_name("non_exhaustive"));
|
|
||||||
if has_non_exhaustive {
|
if has_non_exhaustive {
|
||||||
self.err_handler().span_err(variant.span,
|
self.err_handler().span_err(variant.span,
|
||||||
"#[non_exhaustive] is not yet supported on variants");
|
"#[non_exhaustive] is not yet supported on variants");
|
||||||
|
@ -308,7 +307,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||||
ItemKind::Mod(_) => {
|
ItemKind::Mod(_) => {
|
||||||
// Ensure that `path` attributes on modules are recorded as used (c.f. #35584).
|
// Ensure that `path` attributes on modules are recorded as used (c.f. #35584).
|
||||||
attr::first_attr_value_str_by_name(&item.attrs, "path");
|
attr::first_attr_value_str_by_name(&item.attrs, "path");
|
||||||
if item.attrs.iter().any(|attr| attr.check_name("warn_directory_ownership")) {
|
if attr::contains_name(&item.attrs, "warn_directory_ownership") {
|
||||||
let lint = lint::builtin::LEGACY_DIRECTORY_OWNERSHIP;
|
let lint = lint::builtin::LEGACY_DIRECTORY_OWNERSHIP;
|
||||||
let msg = "cannot declare a new module at this location";
|
let msg = "cannot declare a new module at this location";
|
||||||
self.session.buffer_lint(lint, item.id, item.span, msg);
|
self.session.buffer_lint(lint, item.id, item.span, msg);
|
||||||
|
|
|
@ -358,8 +358,7 @@ impl<'a> Resolver<'a> {
|
||||||
|
|
||||||
let mut ctor_vis = vis;
|
let mut ctor_vis = vis;
|
||||||
|
|
||||||
let has_non_exhaustive = item.attrs.iter()
|
let has_non_exhaustive = attr::contains_name(&item.attrs, "non_exhaustive");
|
||||||
.any(|item| item.check_name("non_exhaustive"));
|
|
||||||
|
|
||||||
// If the structure is marked as non_exhaustive then lower the visibility
|
// If the structure is marked as non_exhaustive then lower the visibility
|
||||||
// to within the crate.
|
// to within the crate.
|
||||||
|
|
|
@ -13,7 +13,7 @@ use rustc::session::Session;
|
||||||
use rustc::middle::cstore::{self, LinkMeta};
|
use rustc::middle::cstore::{self, LinkMeta};
|
||||||
use rustc::hir::svh::Svh;
|
use rustc::hir::svh::Svh;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use syntax::ast;
|
use syntax::{ast, attr};
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
|
|
||||||
pub fn out_filename(sess: &Session,
|
pub fn out_filename(sess: &Session,
|
||||||
|
@ -69,7 +69,7 @@ pub fn find_crate_name(sess: Option<&Session>,
|
||||||
// as used. After doing this, however, we still prioritize a crate name from
|
// as used. After doing this, however, we still prioritize a crate name from
|
||||||
// the command line over one found in the #[crate_name] attribute. If we
|
// the command line over one found in the #[crate_name] attribute. If we
|
||||||
// find both we ensure that they're the same later on as well.
|
// find both we ensure that they're the same later on as well.
|
||||||
let attr_crate_name = attrs.iter().find(|at| at.check_name("crate_name"))
|
let attr_crate_name = attr::find_by_name(attrs, "crate_name")
|
||||||
.and_then(|at| at.value_str().map(|s| (at, s)));
|
.and_then(|at| at.value_str().map(|s| (at, s)));
|
||||||
|
|
||||||
if let Some(sess) = sess {
|
if let Some(sess) = sess {
|
||||||
|
|
|
@ -386,15 +386,15 @@ fn is_bench_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_ignored(i: &ast::Item) -> bool {
|
fn is_ignored(i: &ast::Item) -> bool {
|
||||||
i.attrs.iter().any(|attr| attr.check_name("ignore"))
|
attr::contains_name(&i.attrs, "ignore")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_allowed_fail(i: &ast::Item) -> bool {
|
fn is_allowed_fail(i: &ast::Item) -> bool {
|
||||||
i.attrs.iter().any(|attr| attr.check_name("allow_fail"))
|
attr::contains_name(&i.attrs, "allow_fail")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_panic(i: &ast::Item, cx: &TestCtxt) -> ShouldPanic {
|
fn should_panic(i: &ast::Item, cx: &TestCtxt) -> ShouldPanic {
|
||||||
match i.attrs.iter().find(|attr| attr.check_name("should_panic")) {
|
match attr::find_by_name(&i.attrs, "should_panic") {
|
||||||
Some(attr) => {
|
Some(attr) => {
|
||||||
let sd = cx.span_diagnostic;
|
let sd = cx.span_diagnostic;
|
||||||
if attr.is_value_str() {
|
if attr.is_value_str() {
|
||||||
|
|
|
@ -13,6 +13,7 @@ use std::mem;
|
||||||
use errors;
|
use errors;
|
||||||
|
|
||||||
use syntax::ast::{self, Ident, NodeId};
|
use syntax::ast::{self, Ident, NodeId};
|
||||||
|
use syntax::attr;
|
||||||
use syntax::codemap::{ExpnInfo, NameAndSpan, MacroAttribute};
|
use syntax::codemap::{ExpnInfo, NameAndSpan, MacroAttribute};
|
||||||
use syntax::ext::base::ExtCtxt;
|
use syntax::ext::base::ExtCtxt;
|
||||||
use syntax::ext::build::AstBuilder;
|
use syntax::ext::build::AstBuilder;
|
||||||
|
@ -248,8 +249,7 @@ impl<'a> CollectProcMacros<'a> {
|
||||||
impl<'a> Visitor<'a> for CollectProcMacros<'a> {
|
impl<'a> Visitor<'a> for CollectProcMacros<'a> {
|
||||||
fn visit_item(&mut self, item: &'a ast::Item) {
|
fn visit_item(&mut self, item: &'a ast::Item) {
|
||||||
if let ast::ItemKind::MacroDef(..) = item.node {
|
if let ast::ItemKind::MacroDef(..) = item.node {
|
||||||
if self.is_proc_macro_crate &&
|
if self.is_proc_macro_crate && attr::contains_name(&item.attrs, "macro_export") {
|
||||||
item.attrs.iter().any(|attr| attr.path == "macro_export") {
|
|
||||||
let msg =
|
let msg =
|
||||||
"cannot export macro_rules! macros from a `proc-macro` crate type currently";
|
"cannot export macro_rules! macros from a `proc-macro` crate type currently";
|
||||||
self.handler.span_err(item.span, msg);
|
self.handler.span_err(item.span, msg);
|
||||||
|
|
|
@ -21,6 +21,7 @@ extern crate rustc;
|
||||||
extern crate rustc_plugin;
|
extern crate rustc_plugin;
|
||||||
|
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
|
use syntax::attr;
|
||||||
use syntax::ext::base::{MultiDecorator, ExtCtxt, Annotatable};
|
use syntax::ext::base::{MultiDecorator, ExtCtxt, Annotatable};
|
||||||
use syntax::ext::build::AstBuilder;
|
use syntax::ext::build::AstBuilder;
|
||||||
use syntax::symbol::Symbol;
|
use syntax::symbol::Symbol;
|
||||||
|
@ -80,7 +81,7 @@ fn totalsum_substructure(cx: &mut ExtCtxt, trait_span: Span,
|
||||||
};
|
};
|
||||||
|
|
||||||
fields.iter().fold(cx.expr_isize(trait_span, 0), |acc, ref item| {
|
fields.iter().fold(cx.expr_isize(trait_span, 0), |acc, ref item| {
|
||||||
if item.attrs.iter().find(|a| a.check_name("ignore")).is_some() {
|
if attr::contains_name(&item.attrs, "ignore") {
|
||||||
acc
|
acc
|
||||||
} else {
|
} else {
|
||||||
cx.expr_binary(item.span, ast::BinOpKind::Add, acc,
|
cx.expr_binary(item.span, ast::BinOpKind::Add, acc,
|
||||||
|
|
|
@ -17,6 +17,7 @@ extern crate rustc_plugin;
|
||||||
extern crate syntax;
|
extern crate syntax;
|
||||||
|
|
||||||
use rustc_plugin::Registry;
|
use rustc_plugin::Registry;
|
||||||
|
use syntax::attr;
|
||||||
use syntax::ext::base::*;
|
use syntax::ext::base::*;
|
||||||
use syntax::feature_gate::AttributeType::Whitelisted;
|
use syntax::feature_gate::AttributeType::Whitelisted;
|
||||||
use syntax::symbol::Symbol;
|
use syntax::symbol::Symbol;
|
||||||
|
@ -59,9 +60,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingWhitelistedAttrPass {
|
||||||
_ => cx.tcx.hir.expect_item(cx.tcx.hir.get_parent(id)),
|
_ => cx.tcx.hir.expect_item(cx.tcx.hir.get_parent(id)),
|
||||||
};
|
};
|
||||||
|
|
||||||
if !item.attrs.iter().any(|a| a.check_name("whitelisted_attr")) {
|
if !attr::contains_name(&item.attrs, "whitelisted_attr") {
|
||||||
cx.span_lint(MISSING_WHITELISTED_ATTR, span,
|
cx.span_lint(MISSING_WHITELISTED_ATTR, span,
|
||||||
"Missing 'whitelited_attr' attribute");
|
"Missing 'whitelisted_attr' attribute");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue