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:
parent
24a6130da2
commit
52a9c157d0
@ -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;
|
||||
}
|
||||
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 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
}
|
||||
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 find_mismatched_target_os(items: &[NestedMetaItem]) -> Vec<(&str, Span)> {
|
||||
}
|
||||
|
||||
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();
|
||||
|
@ -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(¤t_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 {
|
||||
|
@ -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]) {
|
||||
for attr in attrs {
|
||||
if !attr.check_name(sym!(inline)) {
|
||||
if !attr.has_name(sym!(inline)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ fn is_non_exhaustive_marker(variant: &Variant) -> bool {
|
||||
}
|
||||
|
||||
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,
|
||||
|
@ -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)),
|
||||
|
@ -57,7 +57,7 @@
|
||||
}
|
||||
|
||||
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,
|
||||
|
@ -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<'_>) {
|
||||
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);
|
||||
}
|
||||
|
@ -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))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -235,7 +235,7 @@ fn check_poly_trait_ref(&mut self, cx: &EarlyContext<'_>, poly: &ast::PolyTraitR
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -155,7 +155,7 @@ fn check_fn(
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
/// 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) => {
|
||||
|
Loading…
Reference in New Issue
Block a user