rename inspection attribute to clippy_dump

This commit is contained in:
Oliver Schneider 2016-10-18 17:29:01 +02:00
parent ff3efc759e
commit a177d85681
No known key found for this signature in database
GPG key ID: 56D6EEA0FC67AC46

View file

@ -4,7 +4,7 @@ use rustc::lint::*;
use rustc::hir; use rustc::hir;
use syntax::ast::{Attribute, MetaItemKind}; use syntax::ast::{Attribute, MetaItemKind};
/// **What it does:** Dumps every ast/hir node which has the `#[inspect]` attribute /// **What it does:** Dumps every ast/hir node which has the `#[clippy_dump]` attribute
/// ///
/// **Why is this bad?** 😈 /// **Why is this bad?** 😈
/// ///
@ -32,7 +32,7 @@ impl LintPass for Pass {
#[allow(print_stdout, use_debug)] #[allow(print_stdout, use_debug)]
impl LateLintPass for Pass { impl LateLintPass for Pass {
fn check_item(&mut self, cx: &LateContext, item: &hir::Item) { fn check_item(&mut self, cx: &LateContext, item: &hir::Item) {
if !has_inspect_attr(&item.attrs) { if !has_attr(&item.attrs) {
return; return;
} }
let did = cx.tcx.map.local_def_id(item.id); let did = cx.tcx.map.local_def_id(item.id);
@ -102,39 +102,39 @@ impl LateLintPass for Pass {
/* /*
fn check_impl_item(&mut self, cx: &LateContext, item: &hir::ImplItem) { fn check_impl_item(&mut self, cx: &LateContext, item: &hir::ImplItem) {
if !has_inspect_attr(&item.attrs) { if !has_attr(&item.attrs) {
return; return;
} }
} }
fn check_trait_item(&mut self, cx: &LateContext, item: &hir::TraitItem) { fn check_trait_item(&mut self, cx: &LateContext, item: &hir::TraitItem) {
if !has_inspect_attr(&item.attrs) { if !has_attr(&item.attrs) {
return; return;
} }
} }
fn check_variant(&mut self, cx: &LateContext, var: &hir::Variant, _: &hir::Generics) { fn check_variant(&mut self, cx: &LateContext, var: &hir::Variant, _: &hir::Generics) {
if !has_inspect_attr(&var.node.attrs) { if !has_attr(&var.node.attrs) {
return; return;
} }
} }
fn check_struct_field(&mut self, cx: &LateContext, field: &hir::StructField) { fn check_struct_field(&mut self, cx: &LateContext, field: &hir::StructField) {
if !has_inspect_attr(&field.attrs) { if !has_attr(&field.attrs) {
return; return;
} }
} }
*/ */
fn check_expr(&mut self, cx: &LateContext, expr: &hir::Expr) { fn check_expr(&mut self, cx: &LateContext, expr: &hir::Expr) {
if !has_inspect_attr(&expr.attrs) { if !has_attr(&expr.attrs) {
return; return;
} }
println!("expression type: {}", cx.tcx.node_id_to_type(expr.id)); println!("expression type: {}", cx.tcx.node_id_to_type(expr.id));
} }
fn check_decl(&mut self, cx: &LateContext, decl: &hir::Decl) { fn check_decl(&mut self, cx: &LateContext, decl: &hir::Decl) {
if !has_inspect_attr(decl.node.attrs()) { if !has_attr(decl.node.attrs()) {
return; return;
} }
match decl.node { match decl.node {
@ -146,34 +146,34 @@ impl LateLintPass for Pass {
} }
/* /*
fn check_arm(&mut self, cx: &LateContext, arm: &hir::Arm) { fn check_arm(&mut self, cx: &LateContext, arm: &hir::Arm) {
if !has_inspect_attr(&arm.attrs) { if !has_attr(&arm.attrs) {
return; return;
} }
} }
fn check_stmt(&mut self, cx: &LateContext, stmt: &hir::Stmt) { fn check_stmt(&mut self, cx: &LateContext, stmt: &hir::Stmt) {
if !has_inspect_attr(stmt.node.attrs()) { if !has_attr(stmt.node.attrs()) {
return; return;
} }
} }
fn check_local(&mut self, cx: &LateContext, local: &hir::Local) { fn check_local(&mut self, cx: &LateContext, local: &hir::Local) {
if !has_inspect_attr(&local.attrs) { if !has_attr(&local.attrs) {
return; return;
} }
} }
fn check_foreign_item(&mut self, cx: &LateContext, item: &hir::ForeignItem) { fn check_foreign_item(&mut self, cx: &LateContext, item: &hir::ForeignItem) {
if !has_inspect_attr(&item.attrs) { if !has_attr(&item.attrs) {
return; return;
} }
} }
*/ */
} }
fn has_inspect_attr(attrs: &[Attribute]) -> bool { fn has_attr(attrs: &[Attribute]) -> bool {
attrs.iter().any(|attr| match attr.node.value.node { attrs.iter().any(|attr| match attr.node.value.node {
MetaItemKind::Word(ref word) => word == "inspect", MetaItemKind::Word(ref word) => word == "clippy_dump",
_ => false, _ => false,
}) })
} }