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
This commit is contained in:
Vadim Petrochenkov 2020-08-02 13:17:20 +03:00
parent 24a6130da2
commit 52a9c157d0
11 changed files with 19 additions and 19 deletions

View File

@ -286,14 +286,14 @@ fn check_attribute(&mut self, cx: &LateContext<'tcx>, attr: &'tcx Attribute) {
}, },
_ => {}, _ => {},
} }
if items.is_empty() || !attr.check_name(sym!(deprecated)) { if items.is_empty() || !attr.has_name(sym!(deprecated)) {
return; return;
} }
for item in items { for item in items {
if_chain! { if_chain! {
if let NestedMetaItem::MetaItem(mi) = &item; if let NestedMetaItem::MetaItem(mi) = &item;
if let MetaItemKind::NameValue(lit) = &mi.kind; if let MetaItemKind::NameValue(lit) = &mi.kind;
if mi.check_name(sym!(since)); if mi.has_name(sym!(since));
then { then {
check_semver(cx, item.span(), lit); check_semver(cx, item.span(), lit);
} }
@ -309,7 +309,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
} }
match item.kind { match item.kind {
ItemKind::ExternCrate(..) | ItemKind::Use(..) => { 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 { for attr in item.attrs {
if in_external_macro(cx.sess(), attr.span) { 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 { for attr in attrs {
if let Some(values) = attr.meta_item_list() { 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; continue;
} }
if is_word(&values[0], sym!(always)) { 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 { fn is_word(nmi: &NestedMetaItem, expected: Symbol) -> bool {
if let NestedMetaItem::MetaItem(mi) = &nmi { if let NestedMetaItem::MetaItem(mi) = &nmi {
mi.is_word() && mi.check_name(expected) mi.is_word() && mi.has_name(expected)
} else { } else {
false 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) { fn check_deprecated_cfg_attr(cx: &EarlyContext<'_>, attr: &Attribute) {
if_chain! { if_chain! {
// check cfg_attr // 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 let Some(items) = attr.meta_item_list();
if items.len() == 2; if items.len() == 2;
// check for `rustfmt` // check for `rustfmt`
if let Some(feature_item) = items[0].meta_item(); 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` // check for `rustfmt_skip` and `rustfmt::skip`
if let Some(skip_item) = &items[1].meta_item(); 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); skip_item.path.segments.last().expect("empty path in attribute").ident.name == sym!(skip);
// Only lint outer attributes, because custom inner attributes are unstable // Only lint outer attributes, because custom inner attributes are unstable
// Tracking issue: https://github.com/rust-lang/rust/issues/54726 // Tracking issue: https://github.com/rust-lang/rust/issues/54726
@ -685,7 +685,7 @@ fn find_mismatched_target_os(items: &[NestedMetaItem]) -> Vec<(&str, Span)> {
} }
if_chain! { if_chain! {
if attr.check_name(sym!(cfg)); if attr.has_name(sym!(cfg));
if let Some(list) = attr.meta_item_list(); if let Some(list) = attr.meta_item_list();
let mismatched = find_mismatched_target_os(&list); let mismatched = find_mismatched_target_os(&list);
if !mismatched.is_empty(); 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); let (comment, current_spans) = strip_doc_comment_decoration(&comment, attr.span);
spans.extend_from_slice(&current_spans); spans.extend_from_slice(&current_spans);
doc.push_str(&comment); 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 // ignore mix of sugared and non-sugared doc
// don't trigger the safety or errors check // don't trigger the safety or errors check
return DocHeaders { return DocHeaders {

View File

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

View File

@ -83,7 +83,7 @@ fn is_non_exhaustive_marker(variant: &Variant) -> bool {
} }
fn is_doc_hidden(attr: &Attribute) -> bool { fn is_doc_hidden(attr: &Attribute) -> bool {
attr.check_name(sym!(doc)) attr.has_name(sym!(doc))
&& match attr.meta_item_list() { && match attr.meta_item_list() {
Some(l) => attr::list_contains_name(&l, sym!(hidden)), Some(l) => attr::list_contains_name(&l, sym!(hidden)),
None => false, 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]) { fn enter_lint_attrs(&mut self, _: &LateContext<'tcx>, attrs: &'tcx [ast::Attribute]) {
let doc_hidden = self.doc_hidden() let doc_hidden = self.doc_hidden()
|| attrs.iter().any(|attr| { || attrs.iter().any(|attr| {
attr.check_name(sym!(doc)) attr.has_name(sym!(doc))
&& match attr.meta_item_list() { && match attr.meta_item_list() {
None => false, None => false,
Some(l) => attr::list_contains_name(&l[..], sym!(hidden)), Some(l) => attr::list_contains_name(&l[..], sym!(hidden)),

View File

@ -57,7 +57,7 @@
} }
fn check_missing_inline_attrs(cx: &LateContext<'_>, attrs: &[ast::Attribute], sp: Span, desc: &'static str) { 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 { if !has_inline {
span_lint( span_lint(
cx, cx,

View File

@ -112,7 +112,7 @@ fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) {
} }
fn check_item(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) { 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()); debug_assert!(self.derived_item.is_none());
self.derived_item = Some(item.hir_id); self.derived_item = Some(item.hir_id);
} }

View File

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

View File

@ -235,7 +235,7 @@ fn check_poly_trait_ref(&mut self, cx: &EarlyContext<'_>, poly: &ast::PolyTraitR
} }
fn attr_is_cfg(attr: &ast::Attribute) -> bool { 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 // get the def site

View File

@ -155,7 +155,7 @@ fn check_fn(
return; return;
} }
for a in attrs { 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; return;
} }
} }

View File

@ -13,7 +13,7 @@
/// Gets the configuration file from arguments. /// Gets the configuration file from arguments.
pub fn file_from_args(args: &[NestedMetaItem]) -> Result<Option<PathBuf>, (&'static str, Span)> { pub fn file_from_args(args: &[NestedMetaItem]) -> Result<Option<PathBuf>, (&'static str, Span)> {
for arg in args.iter().filter_map(NestedMetaItem::meta_item) { 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 { return match arg.kind {
MetaItemKind::Word | MetaItemKind::List(_) => Err(("`conf_file` must be a named value", arg.span)), MetaItemKind::Word | MetaItemKind::List(_) => Err(("`conf_file` must be a named value", arg.span)),
MetaItemKind::NameValue(ref value) => { MetaItemKind::NameValue(ref value) => {