Rollup merge of #75043 - petrochenkov:hasname, r=nnethercote

rustc_ast: `(Nested)MetaItem::check_name` -> `has_name`

For consistency with `Attribute::has_name` which doesn't mark the attribute as used either.

Replace all uses of `check_name` with `has_name` outside of rustc, only rustc needs to mark attributes as used.

cc https://github.com/rust-lang/rust/pull/74932
r? @nnethercote
This commit is contained in:
Yuki Okushi 2020-08-04 09:26:59 +09:00 committed by GitHub
commit 262fce481d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 94 additions and 89 deletions

View File

@ -100,8 +100,8 @@ impl NestedMetaItem {
}
/// Returns `true` if this list item is a MetaItem with a name of `name`.
pub fn check_name(&self, name: Symbol) -> bool {
self.meta_item().map_or(false, |meta_item| meta_item.check_name(name))
pub fn has_name(&self, name: Symbol) -> bool {
self.meta_item().map_or(false, |meta_item| meta_item.has_name(name))
}
/// For a single-segment meta item, returns its name; otherwise, returns `None`.
@ -173,8 +173,13 @@ impl Attribute {
}
}
/// Returns `true` if the attribute's path matches the argument. If it matches, then the
/// attribute is marked as used.
/// Returns `true` if the attribute's path matches the argument.
/// If it matches, then the attribute is marked as used.
/// Should only be used by rustc, other tools can use `has_name` instead,
/// because only rustc is supposed to report the `unused_attributes` lint.
/// `MetaItem` and `NestedMetaItem` are produced by "lowering" an `Attribute`
/// and don't have identity, so they only has the `has_name` method,
/// and you need to mark the original `Attribute` as used when necessary.
pub fn check_name(&self, name: Symbol) -> bool {
let matches = self.has_name(name);
if matches {
@ -278,7 +283,7 @@ impl MetaItem {
}
}
pub fn check_name(&self, name: Symbol) -> bool {
pub fn has_name(&self, name: Symbol) -> bool {
self.path == name
}
@ -405,7 +410,7 @@ pub fn mk_doc_comment(style: AttrStyle, comment: Symbol, span: Span) -> Attribut
}
pub fn list_contains_name(items: &[NestedMetaItem], name: Symbol) -> bool {
items.iter().any(|item| item.check_name(name))
items.iter().any(|item| item.has_name(name))
}
pub fn contains_name(attrs: &[Attribute], name: Symbol) -> bool {

View File

@ -243,7 +243,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
if attr.check_name(sym::doc) {
for nested_meta in attr.meta_item_list().unwrap_or_default() {
macro_rules! gate_doc { ($($name:ident => $feature:ident)*) => {
$(if nested_meta.check_name(sym::$name) {
$(if nested_meta.has_name(sym::$name) {
let msg = concat!("`#[doc(", stringify!($name), ")]` is experimental");
gate_feature_post!(self, $feature, attr.span, msg);
})*
@ -314,7 +314,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
ast::ItemKind::Struct(..) => {
for attr in attr::filter_by_name(&i.attrs[..], sym::repr) {
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
if item.check_name(sym::simd) {
if item.has_name(sym::simd) {
gate_feature_post!(
&self,
repr_simd,

View File

@ -92,9 +92,9 @@ pub fn find_unwind_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> Op
if let Some(meta) = attr.meta() {
if let MetaItemKind::List(items) = meta.kind {
if items.len() == 1 {
if items[0].check_name(sym::allowed) {
if items[0].has_name(sym::allowed) {
return Some(UnwindAttr::Allowed);
} else if items[0].check_name(sym::aborts) {
} else if items[0].has_name(sym::aborts) {
return Some(UnwindAttr::Aborts);
}
}
@ -168,7 +168,7 @@ pub fn contains_feature_attr(attrs: &[Attribute], feature_name: Symbol) -> bool
item.check_name(sym::feature)
&& item
.meta_item_list()
.map(|list| list.iter().any(|mi| mi.is_word() && mi.check_name(feature_name)))
.map(|list| list.iter().any(|mi| mi.is_word() && mi.has_name(feature_name)))
.unwrap_or(false)
})
}
@ -505,7 +505,7 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat
}
fn try_gate_cfg(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Features>) {
let gate = find_gated_cfg(|sym| cfg.check_name(sym));
let gate = find_gated_cfg(|sym| cfg.has_name(sym));
if let (Some(feats), Some(gated_cfg)) = (features, gate) {
gate_cfg(&gated_cfg, cfg.span, sess, feats);
}
@ -898,7 +898,7 @@ pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec<ReprAttr> {
}
} else {
if let Some(meta_item) = item.meta_item() {
if meta_item.check_name(sym::align) {
if meta_item.has_name(sym::align) {
if let MetaItemKind::NameValue(ref value) = meta_item.kind {
recognised = true;
let mut err = struct_span_err!(

View File

@ -143,7 +143,7 @@ impl<'a> CollectProcMacros<'a> {
let attributes_attr = list.get(1);
let proc_attrs: Vec<_> = if let Some(attr) = attributes_attr {
if !attr.check_name(sym::attributes) {
if !attr.has_name(sym::attributes) {
self.handler.span_err(attr.span(), "second argument must be `attributes`")
}
attr.meta_item_list()

View File

@ -336,7 +336,7 @@ fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
Some(list) => {
let msg = list
.iter()
.find(|mi| mi.check_name(sym::expected))
.find(|mi| mi.has_name(sym::expected))
.and_then(|mi| mi.meta_item())
.and_then(|mi| mi.value_str());
if list.len() != 1 || msg.is_none() {

View File

@ -1644,14 +1644,14 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
}
if let Some(list) = at.meta_item_list() {
if !list.iter().any(|it| it.check_name(sym::include)) {
if !list.iter().any(|it| it.has_name(sym::include)) {
return noop_visit_attribute(at, self);
}
let mut items = vec![];
for mut it in list {
if !it.check_name(sym::include) {
if !it.has_name(sym::include) {
items.push({
noop_visit_meta_list_item(&mut it, self);
it

View File

@ -149,7 +149,7 @@ impl AssertModuleSource<'tcx> {
fn field(&self, attr: &ast::Attribute, name: Symbol) -> Symbol {
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
if item.check_name(name) {
if item.has_name(name) {
if let Some(value) = item.value_str() {
return value;
} else {

View File

@ -231,7 +231,7 @@ impl DirtyCleanVisitor<'tcx> {
fn labels(&self, attr: &Attribute) -> Option<Labels> {
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
if item.check_name(LABEL) {
if item.has_name(LABEL) {
let value = expect_associated_value(self.tcx, &item);
return Some(self.resolve_labels(&item, value));
}
@ -242,7 +242,7 @@ impl DirtyCleanVisitor<'tcx> {
/// `except=` attribute value
fn except(&self, attr: &Attribute) -> Labels {
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
if item.check_name(EXCEPT) {
if item.has_name(EXCEPT) {
let value = expect_associated_value(self.tcx, &item);
return self.resolve_labels(&item, value);
}
@ -474,15 +474,15 @@ fn check_config(tcx: TyCtxt<'_>, attr: &Attribute) -> bool {
debug!("check_config: config={:?}", config);
let (mut cfg, mut except, mut label) = (None, false, false);
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
if item.check_name(CFG) {
if item.has_name(CFG) {
let value = expect_associated_value(tcx, &item);
debug!("check_config: searching for cfg {:?}", value);
cfg = Some(config.contains(&(value, None)));
}
if item.check_name(LABEL) {
if item.has_name(LABEL) {
label = true;
}
if item.check_name(EXCEPT) {
if item.has_name(EXCEPT) {
except = true;
}
}

View File

@ -330,7 +330,7 @@ fn has_doc(attr: &ast::Attribute) -> bool {
if let Some(list) = attr.meta_item_list() {
for meta in list {
if meta.check_name(sym::include) || meta.check_name(sym::hidden) {
if meta.has_name(sym::include) || meta.has_name(sym::hidden) {
return true;
}
}

View File

@ -58,7 +58,7 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
let mut kind_specified = false;
for item in items.iter() {
if item.check_name(sym::kind) {
if item.has_name(sym::kind) {
kind_specified = true;
let kind = match item.value_str() {
Some(name) => name,
@ -84,9 +84,9 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
NativeLibKind::Unspecified
}
};
} else if item.check_name(sym::name) {
} else if item.has_name(sym::name) {
lib.name = item.value_str();
} else if item.check_name(sym::cfg) {
} else if item.has_name(sym::cfg) {
let cfg = match item.meta_item_list() {
Some(list) => list,
None => continue, // skip like historical compilers
@ -98,7 +98,7 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
} else {
self.tcx.sess.span_err(cfg[0].span(), "invalid argument for `cfg(..)`");
}
} else if item.check_name(sym::wasm_import_module) {
} else if item.has_name(sym::wasm_import_module) {
match item.value_str() {
Some(s) => lib.wasm_import_module = Some(s),
None => {

View File

@ -339,7 +339,7 @@ impl RustcMirAttrs {
.flat_map(|attr| attr.meta_item_list().into_iter().flat_map(|v| v.into_iter()));
for attr in rustc_mir_attrs {
let attr_result = if attr.check_name(sym::borrowck_graphviz_postflow) {
let attr_result = if attr.has_name(sym::borrowck_graphviz_postflow) {
Self::set_field(&mut ret.basename_and_suffix, tcx, &attr, |s| {
let path = PathBuf::from(s.to_string());
match path.file_name() {
@ -350,7 +350,7 @@ impl RustcMirAttrs {
}
}
})
} else if attr.check_name(sym::borrowck_graphviz_format) {
} else if attr.has_name(sym::borrowck_graphviz_format) {
Self::set_field(&mut ret.formatter, tcx, &attr, |s| match s {
sym::gen_kill | sym::two_phase => Ok(s),
_ => {

View File

@ -34,7 +34,7 @@ pub(crate) fn has_rustc_mir_with(attrs: &[ast::Attribute], name: Symbol) -> Opti
let items = attr.meta_item_list();
for item in items.iter().flat_map(|l| l.iter()) {
match item.meta_item() {
Some(mi) if mi.check_name(name) => return Some(mi.clone()),
Some(mi) if mi.has_name(name) => return Some(mi.clone()),
_ => continue,
}
}

View File

@ -222,7 +222,7 @@ impl CheckAttrVisitor<'tcx> {
if let Some(mi) = attr.meta() {
if let Some(list) = mi.meta_item_list() {
for meta in list {
if meta.check_name(sym::alias) {
if meta.has_name(sym::alias) {
if !meta.is_value_str()
|| meta
.value_str()

View File

@ -832,10 +832,10 @@ impl<'tcx> SaveContext<'tcx> {
if let Some(meta_list) = attr.meta_item_list() {
meta_list
.into_iter()
.filter(|it| it.check_name(sym::include))
.filter(|it| it.has_name(sym::include))
.filter_map(|it| it.meta_item_list().map(|l| l.to_owned()))
.flat_map(|it| it)
.filter(|meta| meta.check_name(sym::contents))
.filter(|meta| meta.has_name(sym::contents))
.filter_map(|meta| meta.value_str())
.for_each(|val| {
result.push_str(&val.as_str());

View File

@ -95,27 +95,27 @@ impl<'tcx> OnUnimplementedDirective {
};
for item in item_iter {
if item.check_name(sym::message) && message.is_none() {
if item.has_name(sym::message) && message.is_none() {
if let Some(message_) = item.value_str() {
message = parse_value(message_)?;
continue;
}
} else if item.check_name(sym::label) && label.is_none() {
} else if item.has_name(sym::label) && label.is_none() {
if let Some(label_) = item.value_str() {
label = parse_value(label_)?;
continue;
}
} else if item.check_name(sym::note) && note.is_none() {
} else if item.has_name(sym::note) && note.is_none() {
if let Some(note_) = item.value_str() {
note = parse_value(note_)?;
continue;
}
} else if item.check_name(sym::enclosing_scope) && enclosing_scope.is_none() {
} else if item.has_name(sym::enclosing_scope) && enclosing_scope.is_none() {
if let Some(enclosing_scope_) = item.value_str() {
enclosing_scope = parse_value(enclosing_scope_)?;
continue;
}
} else if item.check_name(sym::on)
} else if item.has_name(sym::on)
&& is_root
&& message.is_none()
&& label.is_none()

View File

@ -2231,7 +2231,7 @@ fn from_target_feature(
let rust_features = tcx.features();
for item in list {
// Only `enable = ...` is accepted in the meta-item list.
if !item.check_name(sym::enable) {
if !item.has_name(sym::enable) {
bad_item(item.span());
continue;
}
@ -2483,11 +2483,11 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
no_sanitize_span = Some(attr.span);
if let Some(list) = attr.meta_item_list() {
for item in list.iter() {
if item.check_name(sym::address) {
if item.has_name(sym::address) {
codegen_fn_attrs.no_sanitize |= SanitizerSet::ADDRESS;
} else if item.check_name(sym::memory) {
} else if item.has_name(sym::memory) {
codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMORY;
} else if item.check_name(sym::thread) {
} else if item.has_name(sym::thread) {
codegen_fn_attrs.no_sanitize |= SanitizerSet::THREAD;
} else {
tcx.sess

View File

@ -113,7 +113,7 @@ impl Clean<ExternalCrate> for CrateNum {
let mut prim = None;
for attr in attrs.lists(sym::doc) {
if let Some(v) = attr.value_str() {
if attr.check_name(sym::primitive) {
if attr.has_name(sym::primitive) {
prim = PrimitiveType::from_symbol(v);
if prim.is_some() {
break;
@ -168,7 +168,7 @@ impl Clean<ExternalCrate> for CrateNum {
let mut keyword = None;
for attr in attrs.lists(sym::doc) {
if let Some(v) = attr.value_str() {
if attr.check_name(sym::keyword) {
if attr.has_name(sym::keyword) {
if v.is_doc_keyword() {
keyword = Some(v.to_string());
break;
@ -2157,7 +2157,7 @@ impl Clean<Vec<Item>> for doctree::ExternCrate<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Vec<Item> {
let please_inline = self.vis.node.is_pub()
&& self.attrs.iter().any(|a| {
a.check_name(sym::doc)
a.has_name(sym::doc)
&& match a.meta_item_list() {
Some(l) => attr::list_contains_name(&l, sym::inline),
None => false,
@ -2197,7 +2197,7 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
// Don't inline doc(hidden) imports so they can be stripped at a later stage.
let mut denied = !self.vis.node.is_pub()
|| self.attrs.iter().any(|a| {
a.check_name(sym::doc)
a.has_name(sym::doc)
&& match a.meta_item_list() {
Some(l) => {
attr::list_contains_name(&l, sym::no_inline)

View File

@ -210,7 +210,7 @@ impl Item {
}
pub fn is_non_exhaustive(&self) -> bool {
self.attrs.other_attrs.iter().any(|a| a.check_name(sym::non_exhaustive))
self.attrs.other_attrs.iter().any(|a| a.has_name(sym::non_exhaustive))
}
/// Returns a documentation-level item type from the item.
@ -309,7 +309,7 @@ impl<'a> Iterator for ListAttributesIter<'a> {
for attr in &mut self.attrs {
if let Some(list) = attr.meta_item_list() {
if attr.check_name(self.name) {
if attr.has_name(self.name) {
self.current_list = list.into_iter();
if let Some(nested) = self.current_list.next() {
return Some(nested);
@ -345,7 +345,7 @@ pub trait NestedAttributesExt {
impl<I: IntoIterator<Item = ast::NestedMetaItem>> NestedAttributesExt for I {
fn has_word(self, word: Symbol) -> bool {
self.into_iter().any(|attr| attr.is_word() && attr.check_name(word))
self.into_iter().any(|attr| attr.is_word() && attr.has_name(word))
}
}
@ -425,7 +425,7 @@ impl Attributes {
if let ast::MetaItemKind::List(ref nmis) = mi.kind {
if nmis.len() == 1 {
if let MetaItem(ref cfg_mi) = nmis[0] {
if cfg_mi.check_name(sym::cfg) {
if cfg_mi.has_name(sym::cfg) {
if let ast::MetaItemKind::List(ref cfg_nmis) = cfg_mi.kind {
if cfg_nmis.len() == 1 {
if let MetaItem(ref content_mi) = cfg_nmis[0] {
@ -447,7 +447,7 @@ impl Attributes {
pub fn extract_include(mi: &ast::MetaItem) -> Option<(String, String)> {
mi.meta_item_list().and_then(|list| {
for meta in list {
if meta.check_name(sym::include) {
if meta.has_name(sym::include) {
// the actual compiled `#[doc(include="filename")]` gets expanded to
// `#[doc(include(file="filename", contents="file contents")]` so we need to
// look for that instead
@ -456,11 +456,11 @@ impl Attributes {
let mut contents: Option<String> = None;
for it in list {
if it.check_name(sym::file) {
if it.has_name(sym::file) {
if let Some(name) = it.value_str() {
filename = Some(name.to_string());
}
} else if it.check_name(sym::contents) {
} else if it.has_name(sym::contents) {
if let Some(docs) = it.value_str() {
contents = Some(docs.to_string());
}
@ -482,12 +482,12 @@ impl Attributes {
pub fn has_doc_flag(&self, flag: Symbol) -> bool {
for attr in &self.other_attrs {
if !attr.check_name(sym::doc) {
if !attr.has_name(sym::doc) {
continue;
}
if let Some(items) = attr.meta_item_list() {
if items.iter().filter_map(|i| i.meta_item()).any(|it| it.check_name(flag)) {
if items.iter().filter_map(|i| i.meta_item()).any(|it| it.has_name(flag)) {
return true;
}
}
@ -521,7 +521,7 @@ impl Attributes {
}
None
} else {
if attr.check_name(sym::doc) {
if attr.has_name(sym::doc) {
if let Some(mi) = attr.meta() {
if let Some(cfg_mi) = Attributes::extract_cfg(&mi) {
// Extracted #[doc(cfg(...))]
@ -548,7 +548,7 @@ impl Attributes {
// treat #[target_feature(enable = "feat")] attributes as if they were
// #[doc(cfg(target_feature = "feat"))] attributes as well
for attr in attrs.lists(sym::target_feature) {
if attr.check_name(sym::enable) {
if attr.has_name(sym::enable) {
if let Some(feat) = attr.value_str() {
let meta = attr::mk_name_value_item_str(
Ident::with_dummy_span(sym::target_feature),
@ -648,7 +648,7 @@ impl Attributes {
pub fn get_doc_aliases(&self) -> FxHashSet<String> {
self.other_attrs
.lists(sym::doc)
.filter(|a| a.check_name(sym::alias))
.filter(|a| a.has_name(sym::alias))
.filter_map(|a| a.value_str().map(|s| s.to_string().replace("\"", "")))
.filter(|v| !v.is_empty())
.collect::<FxHashSet<_>>()

View File

@ -48,7 +48,7 @@ pub fn extern_location(
// external crate
e.attrs
.lists(sym::doc)
.filter(|a| a.check_name(sym::html_root_url))
.filter(|a| a.has_name(sym::html_root_url))
.filter_map(|a| a.value_str())
.map(|url| {
let mut url = url.to_string();

View File

@ -175,17 +175,17 @@ fn scrape_test_config(krate: &::rustc_hir::Crate<'_>) -> TestOptions {
.item
.attrs
.iter()
.filter(|a| a.check_name(sym::doc))
.filter(|a| a.has_name(sym::doc))
.flat_map(|a| a.meta_item_list().unwrap_or_else(Vec::new))
.filter(|a| a.check_name(sym::test))
.filter(|a| a.has_name(sym::test))
.collect();
let attrs = test_attrs.iter().flat_map(|a| a.meta_item_list().unwrap_or(&[]));
for attr in attrs {
if attr.check_name(sym::no_crate_inject) {
if attr.has_name(sym::no_crate_inject) {
opts.no_crate_inject = true;
}
if attr.check_name(sym::attr) {
if attr.has_name(sym::attr) {
if let Some(l) = attr.meta_item_list() {
for item in l {
opts.attrs.push(pprust::meta_list_item_to_string(item));

View File

@ -165,11 +165,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
) {
debug!("visiting fn");
let macro_kind = item.attrs.iter().find_map(|a| {
if a.check_name(sym::proc_macro) {
if a.has_name(sym::proc_macro) {
Some(MacroKind::Bang)
} else if a.check_name(sym::proc_macro_derive) {
} else if a.has_name(sym::proc_macro_derive) {
Some(MacroKind::Derive)
} else if a.check_name(sym::proc_macro_attribute) {
} else if a.has_name(sym::proc_macro_attribute) {
Some(MacroKind::Attr)
} else {
None
@ -189,7 +189,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
let mut helpers = Vec::new();
for mi in item.attrs.lists(sym::proc_macro_derive) {
if !mi.check_name(sym::attributes) {
if !mi.has_name(sym::attributes) {
continue;
}
@ -419,8 +419,8 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
// anything as it will probably be stripped anyway.
if item.vis.node.is_pub() && self.inside_public_path {
let please_inline = item.attrs.iter().any(|item| match item.meta_item_list() {
Some(ref list) if item.check_name(sym::doc) => {
list.iter().any(|i| i.check_name(sym::inline))
Some(ref list) if item.has_name(sym::doc) => {
list.iter().any(|i| i.has_name(sym::inline))
}
_ => false,
});

View File

@ -286,14 +286,14 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
},
_ => {},
}
if items.is_empty() || !attr.check_name(sym!(deprecated)) {
if items.is_empty() || !attr.has_name(sym!(deprecated)) {
return;
}
for item in items {
if_chain! {
if let NestedMetaItem::MetaItem(mi) = &item;
if let MetaItemKind::NameValue(lit) = &mi.kind;
if mi.check_name(sym!(since));
if mi.has_name(sym!(since));
then {
check_semver(cx, item.span(), lit);
}
@ -309,7 +309,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
}
match item.kind {
ItemKind::ExternCrate(..) | ItemKind::Use(..) => {
let skip_unused_imports = item.attrs.iter().any(|attr| attr.check_name(sym!(macro_use)));
let skip_unused_imports = item.attrs.iter().any(|attr| attr.has_name(sym!(macro_use)));
for attr in item.attrs {
if in_external_macro(cx.sess(), attr.span) {
@ -524,7 +524,7 @@ fn check_attrs(cx: &LateContext<'_>, span: Span, name: Name, attrs: &[Attribute]
for attr in attrs {
if let Some(values) = attr.meta_item_list() {
if values.len() != 1 || !attr.check_name(sym!(inline)) {
if values.len() != 1 || !attr.has_name(sym!(inline)) {
continue;
}
if is_word(&values[0], sym!(always)) {
@ -558,7 +558,7 @@ fn check_semver(cx: &LateContext<'_>, span: Span, lit: &Lit) {
fn is_word(nmi: &NestedMetaItem, expected: Symbol) -> bool {
if let NestedMetaItem::MetaItem(mi) = &nmi {
mi.is_word() && mi.check_name(expected)
mi.is_word() && mi.has_name(expected)
} else {
false
}
@ -618,15 +618,15 @@ fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::as
fn check_deprecated_cfg_attr(cx: &EarlyContext<'_>, attr: &Attribute) {
if_chain! {
// check cfg_attr
if attr.check_name(sym!(cfg_attr));
if attr.has_name(sym!(cfg_attr));
if let Some(items) = attr.meta_item_list();
if items.len() == 2;
// check for `rustfmt`
if let Some(feature_item) = items[0].meta_item();
if feature_item.check_name(sym!(rustfmt));
if feature_item.has_name(sym!(rustfmt));
// check for `rustfmt_skip` and `rustfmt::skip`
if let Some(skip_item) = &items[1].meta_item();
if skip_item.check_name(sym!(rustfmt_skip)) ||
if skip_item.has_name(sym!(rustfmt_skip)) ||
skip_item.path.segments.last().expect("empty path in attribute").ident.name == sym!(skip);
// Only lint outer attributes, because custom inner attributes are unstable
// Tracking issue: https://github.com/rust-lang/rust/issues/54726
@ -685,7 +685,7 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) {
}
if_chain! {
if attr.check_name(sym!(cfg));
if attr.has_name(sym!(cfg));
if let Some(list) = attr.meta_item_list();
let mismatched = find_mismatched_target_os(&list);
if !mismatched.is_empty();

View File

@ -323,7 +323,7 @@ fn check_attrs<'a>(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs
let (comment, current_spans) = strip_doc_comment_decoration(&comment, attr.span);
spans.extend_from_slice(&current_spans);
doc.push_str(&comment);
} else if attr.check_name(sym!(doc)) {
} else if attr.has_name(sym!(doc)) {
// ignore mix of sugared and non-sugared doc
// don't trigger the safety or errors check
return DocHeaders {

View File

@ -41,7 +41,7 @@ impl<'tcx> LateLintPass<'tcx> for InlineFnWithoutBody {
fn check_attrs(cx: &LateContext<'_>, name: Symbol, attrs: &[Attribute]) {
for attr in attrs {
if !attr.check_name(sym!(inline)) {
if !attr.has_name(sym!(inline)) {
continue;
}

View File

@ -83,7 +83,7 @@ fn check_manual_non_exhaustive_enum(cx: &EarlyContext<'_>, item: &Item, variants
}
fn is_doc_hidden(attr: &Attribute) -> bool {
attr.check_name(sym!(doc))
attr.has_name(sym!(doc))
&& match attr.meta_item_list() {
Some(l) => attr::list_contains_name(&l, sym!(hidden)),
None => false,

View File

@ -105,7 +105,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
fn enter_lint_attrs(&mut self, _: &LateContext<'tcx>, attrs: &'tcx [ast::Attribute]) {
let doc_hidden = self.doc_hidden()
|| attrs.iter().any(|attr| {
attr.check_name(sym!(doc))
attr.has_name(sym!(doc))
&& match attr.meta_item_list() {
None => false,
Some(l) => attr::list_contains_name(&l[..], sym!(hidden)),

View File

@ -57,7 +57,7 @@ declare_clippy_lint! {
}
fn check_missing_inline_attrs(cx: &LateContext<'_>, attrs: &[ast::Attribute], sp: Span, desc: &'static str) {
let has_inline = attrs.iter().any(|a| a.check_name(sym!(inline)));
let has_inline = attrs.iter().any(|a| a.has_name(sym!(inline)));
if !has_inline {
span_lint(
cx,

View File

@ -112,7 +112,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
}
fn check_item(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) {
if item.attrs.iter().any(|a| a.check_name(sym!(automatically_derived))) {
if item.attrs.iter().any(|a| a.has_name(sym!(automatically_derived))) {
debug_assert!(self.derived_item.is_none());
self.derived_item = Some(item.hir_id);
}

View File

@ -312,7 +312,7 @@ fn requires_exact_signature(attrs: &[Attribute]) -> bool {
attrs.iter().any(|attr| {
[sym!(proc_macro), sym!(proc_macro_attribute), sym!(proc_macro_derive)]
.iter()
.any(|&allow| attr.check_name(allow))
.any(|&allow| attr.has_name(allow))
})
}

View File

@ -235,7 +235,7 @@ impl EarlyLintPass for Return {
}
fn attr_is_cfg(attr: &ast::Attribute) -> bool {
attr.meta_item_list().is_some() && attr.check_name(sym!(cfg))
attr.meta_item_list().is_some() && attr.has_name(sym!(cfg))
}
// get the def site

View File

@ -155,7 +155,7 @@ impl<'tcx> LateLintPass<'tcx> for TriviallyCopyPassByRef {
return;
}
for a in attrs {
if a.meta_item_list().is_some() && a.check_name(sym!(proc_macro_derive)) {
if a.meta_item_list().is_some() && a.has_name(sym!(proc_macro_derive)) {
return;
}
}

View File

@ -13,7 +13,7 @@ use std::{env, fmt, fs, io};
/// Gets the configuration file from arguments.
pub fn file_from_args(args: &[NestedMetaItem]) -> Result<Option<PathBuf>, (&'static str, Span)> {
for arg in args.iter().filter_map(NestedMetaItem::meta_item) {
if arg.check_name(sym!(conf_file)) {
if arg.has_name(sym!(conf_file)) {
return match arg.kind {
MetaItemKind::Word | MetaItemKind::List(_) => Err(("`conf_file` must be a named value", arg.span)),
MetaItemKind::NameValue(ref value) => {