2016-10-24 08:16:21 -05:00
|
|
|
#![allow(print_stdout, use_debug)]
|
|
|
|
|
2016-10-18 09:57:39 -05:00
|
|
|
//! checks for attributes
|
|
|
|
|
|
|
|
use rustc::lint::*;
|
|
|
|
use rustc::hir;
|
2017-01-03 22:40:42 -06:00
|
|
|
use rustc::hir::print;
|
2016-10-29 20:13:41 -05:00
|
|
|
use syntax::ast::Attribute;
|
|
|
|
use syntax::attr;
|
2016-10-18 09:57:39 -05:00
|
|
|
|
2017-08-09 02:30:56 -05:00
|
|
|
/// **What it does:** Dumps every ast/hir node which has the `#[clippy_dump]`
|
|
|
|
/// attribute
|
2016-10-18 09:57:39 -05:00
|
|
|
///
|
|
|
|
/// **Example:**
|
|
|
|
/// ```rust
|
2016-10-24 08:43:37 -05:00
|
|
|
/// #[clippy_dump]
|
2016-10-18 09:57:39 -05:00
|
|
|
/// extern crate foo;
|
|
|
|
/// ```
|
2016-10-24 09:30:22 -05:00
|
|
|
///
|
|
|
|
/// prints
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// item `foo`
|
|
|
|
/// visibility inherited from outer item
|
|
|
|
/// extern crate dylib source: "/path/to/foo.so"
|
|
|
|
/// ```
|
2018-03-28 08:24:26 -05:00
|
|
|
declare_clippy_lint! {
|
2016-10-18 09:57:39 -05:00
|
|
|
pub DEEP_CODE_INSPECTION,
|
2018-03-29 06:41:53 -05:00
|
|
|
internal_warn,
|
2016-10-18 09:57:39 -05:00
|
|
|
"helper to dump info about code"
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Pass;
|
|
|
|
|
|
|
|
impl LintPass for Pass {
|
|
|
|
fn get_lints(&self) -> LintArray {
|
|
|
|
lint_array!(DEEP_CODE_INSPECTION)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-07 06:13:40 -06:00
|
|
|
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|
|
|
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) {
|
2016-10-18 10:29:01 -05:00
|
|
|
if !has_attr(&item.attrs) {
|
2016-10-18 09:57:39 -05:00
|
|
|
return;
|
|
|
|
}
|
2016-10-24 07:29:09 -05:00
|
|
|
print_item(cx, item);
|
|
|
|
}
|
|
|
|
|
2016-12-07 06:13:40 -06:00
|
|
|
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::ImplItem) {
|
2016-10-24 07:29:09 -05:00
|
|
|
if !has_attr(&item.attrs) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
println!("impl item `{}`", item.name);
|
2016-10-18 09:57:39 -05:00
|
|
|
match item.vis {
|
|
|
|
hir::Visibility::Public => println!("public"),
|
|
|
|
hir::Visibility::Crate => println!("visible crate wide"),
|
2017-09-05 04:33:04 -05:00
|
|
|
hir::Visibility::Restricted { ref path, .. } => println!(
|
|
|
|
"visible in module `{}`",
|
|
|
|
print::to_string(print::NO_ANN, |s| s.print_path(path, false))
|
|
|
|
),
|
2016-10-18 09:57:39 -05:00
|
|
|
hir::Visibility::Inherited => println!("visibility inherited from outer item"),
|
|
|
|
}
|
2016-10-24 07:29:09 -05:00
|
|
|
if item.defaultness.is_default() {
|
|
|
|
println!("default");
|
|
|
|
}
|
2016-10-18 09:57:39 -05:00
|
|
|
match item.node {
|
2017-01-04 16:18:11 -06:00
|
|
|
hir::ImplItemKind::Const(_, body_id) => {
|
2016-10-24 07:29:09 -05:00
|
|
|
println!("associated constant");
|
2017-02-02 10:53:28 -06:00
|
|
|
print_expr(cx, &cx.tcx.hir.body(body_id).value, 1);
|
2016-10-18 09:57:39 -05:00
|
|
|
},
|
2016-10-24 07:29:09 -05:00
|
|
|
hir::ImplItemKind::Method(..) => println!("method"),
|
|
|
|
hir::ImplItemKind::Type(_) => println!("associated type"),
|
2016-10-18 09:57:39 -05:00
|
|
|
}
|
|
|
|
}
|
2017-08-09 02:30:56 -05:00
|
|
|
// fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx
|
|
|
|
// hir::TraitItem) {
|
2016-12-20 11:21:30 -06:00
|
|
|
// if !has_attr(&item.attrs) {
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
2017-08-09 02:30:56 -05:00
|
|
|
// fn check_variant(&mut self, cx: &LateContext<'a, 'tcx>, var: &'tcx
|
|
|
|
// hir::Variant, _:
|
2016-12-21 03:25:14 -06:00
|
|
|
// &hir::Generics) {
|
2016-12-20 11:21:30 -06:00
|
|
|
// if !has_attr(&var.node.attrs) {
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
2017-08-09 02:30:56 -05:00
|
|
|
// fn check_struct_field(&mut self, cx: &LateContext<'a, 'tcx>, field: &'tcx
|
|
|
|
// hir::StructField) {
|
2016-12-20 11:21:30 -06:00
|
|
|
// if !has_attr(&field.attrs) {
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
2016-10-18 09:57:39 -05:00
|
|
|
|
2016-12-07 06:13:40 -06:00
|
|
|
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
|
2016-10-18 10:29:01 -05:00
|
|
|
if !has_attr(&expr.attrs) {
|
2016-10-18 09:57:39 -05:00
|
|
|
return;
|
|
|
|
}
|
2016-10-24 07:28:58 -05:00
|
|
|
print_expr(cx, expr, 0);
|
2016-10-18 09:57:39 -05:00
|
|
|
}
|
|
|
|
|
2016-12-07 06:13:40 -06:00
|
|
|
fn check_arm(&mut self, cx: &LateContext<'a, 'tcx>, arm: &'tcx hir::Arm) {
|
2016-10-18 10:29:01 -05:00
|
|
|
if !has_attr(&arm.attrs) {
|
2016-10-18 09:57:39 -05:00
|
|
|
return;
|
|
|
|
}
|
2016-10-24 07:28:58 -05:00
|
|
|
for pat in &arm.pats {
|
|
|
|
print_pat(cx, pat, 1);
|
|
|
|
}
|
|
|
|
if let Some(ref guard) = arm.guard {
|
|
|
|
println!("guard:");
|
|
|
|
print_expr(cx, guard, 1);
|
|
|
|
}
|
|
|
|
println!("body:");
|
|
|
|
print_expr(cx, &arm.body, 1);
|
2016-10-18 09:57:39 -05:00
|
|
|
}
|
|
|
|
|
2016-12-07 06:13:40 -06:00
|
|
|
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx hir::Stmt) {
|
2016-10-18 10:29:01 -05:00
|
|
|
if !has_attr(stmt.node.attrs()) {
|
2016-10-18 09:57:39 -05:00
|
|
|
return;
|
|
|
|
}
|
2016-10-24 07:29:09 -05:00
|
|
|
match stmt.node {
|
|
|
|
hir::StmtDecl(ref decl, _) => print_decl(cx, decl),
|
2017-09-05 04:33:04 -05:00
|
|
|
hir::StmtExpr(ref e, _) | hir::StmtSemi(ref e, _) => print_expr(cx, e, 0),
|
2016-10-18 09:57:39 -05:00
|
|
|
}
|
|
|
|
}
|
2017-08-09 02:30:56 -05:00
|
|
|
// fn check_foreign_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx
|
|
|
|
// hir::ForeignItem) {
|
2016-12-20 11:21:30 -06:00
|
|
|
// if !has_attr(&item.attrs) {
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
2016-10-18 09:57:39 -05:00
|
|
|
}
|
|
|
|
|
2016-10-18 10:29:01 -05:00
|
|
|
fn has_attr(attrs: &[Attribute]) -> bool {
|
2016-10-29 20:13:41 -05:00
|
|
|
attr::contains_name(attrs, "clippy_dump")
|
2016-10-18 09:57:39 -05:00
|
|
|
}
|
2016-10-24 07:28:58 -05:00
|
|
|
|
|
|
|
fn print_decl(cx: &LateContext, decl: &hir::Decl) {
|
|
|
|
match decl.node {
|
|
|
|
hir::DeclLocal(ref local) => {
|
2017-08-15 04:10:49 -05:00
|
|
|
println!("local variable of type {}", cx.tables.node_id_to_type(local.hir_id));
|
2016-10-24 07:28:58 -05:00
|
|
|
println!("pattern:");
|
|
|
|
print_pat(cx, &local.pat, 0);
|
|
|
|
if let Some(ref e) = local.init {
|
|
|
|
println!("init expression:");
|
|
|
|
print_expr(cx, e, 0);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
hir::DeclItem(_) => println!("item decl"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn print_expr(cx: &LateContext, expr: &hir::Expr, indent: usize) {
|
|
|
|
let ind = " ".repeat(indent);
|
|
|
|
println!("{}+", ind);
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}ty: {}", ind, cx.tables.expr_ty(expr));
|
2017-08-15 04:10:49 -05:00
|
|
|
println!("{}adjustments: {:?}", ind, cx.tables.adjustments().get(expr.hir_id));
|
2016-10-24 07:28:58 -05:00
|
|
|
match expr.node {
|
|
|
|
hir::ExprBox(ref e) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}Box", ind);
|
2016-10-24 07:28:58 -05:00
|
|
|
print_expr(cx, e, indent + 1);
|
|
|
|
},
|
|
|
|
hir::ExprArray(ref v) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}Array", ind);
|
2016-10-24 07:28:58 -05:00
|
|
|
for e in v {
|
|
|
|
print_expr(cx, e, indent + 1);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
hir::ExprCall(ref func, ref args) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}Call", ind);
|
2016-10-24 07:28:58 -05:00
|
|
|
println!("{}function:", ind);
|
|
|
|
print_expr(cx, func, indent + 1);
|
|
|
|
println!("{}arguments:", ind);
|
|
|
|
for arg in args {
|
|
|
|
print_expr(cx, arg, indent + 1);
|
|
|
|
}
|
|
|
|
},
|
2017-07-10 03:17:40 -05:00
|
|
|
hir::ExprMethodCall(ref path, _, ref args) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}MethodCall", ind);
|
2017-07-10 03:17:40 -05:00
|
|
|
println!("{}method name: {}", ind, path.name);
|
2016-10-24 07:28:58 -05:00
|
|
|
for arg in args {
|
|
|
|
print_expr(cx, arg, indent + 1);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
hir::ExprTup(ref v) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}Tup", ind);
|
2016-10-24 07:28:58 -05:00
|
|
|
for e in v {
|
|
|
|
print_expr(cx, e, indent + 1);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
hir::ExprBinary(op, ref lhs, ref rhs) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}Binary", ind);
|
2016-10-24 07:28:58 -05:00
|
|
|
println!("{}op: {:?}", ind, op.node);
|
|
|
|
println!("{}lhs:", ind);
|
|
|
|
print_expr(cx, lhs, indent + 1);
|
|
|
|
println!("{}rhs:", ind);
|
|
|
|
print_expr(cx, rhs, indent + 1);
|
|
|
|
},
|
|
|
|
hir::ExprUnary(op, ref inner) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}Unary", ind);
|
2016-10-24 07:28:58 -05:00
|
|
|
println!("{}op: {:?}", ind, op);
|
|
|
|
print_expr(cx, inner, indent + 1);
|
|
|
|
},
|
|
|
|
hir::ExprLit(ref lit) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}Lit", ind);
|
2016-10-24 07:28:58 -05:00
|
|
|
println!("{}{:?}", ind, lit);
|
|
|
|
},
|
|
|
|
hir::ExprCast(ref e, ref target) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}Cast", ind);
|
2016-10-24 07:28:58 -05:00
|
|
|
print_expr(cx, e, indent + 1);
|
|
|
|
println!("{}target type: {:?}", ind, target);
|
|
|
|
},
|
|
|
|
hir::ExprType(ref e, ref target) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}Type", ind);
|
2016-10-24 07:28:58 -05:00
|
|
|
print_expr(cx, e, indent + 1);
|
|
|
|
println!("{}target type: {:?}", ind, target);
|
|
|
|
},
|
|
|
|
hir::ExprIf(ref e, _, ref els) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}If", ind);
|
2016-10-24 07:28:58 -05:00
|
|
|
println!("{}condition:", ind);
|
|
|
|
print_expr(cx, e, indent + 1);
|
|
|
|
if let Some(ref els) = *els {
|
|
|
|
println!("{}else:", ind);
|
|
|
|
print_expr(cx, els, indent + 1);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
hir::ExprWhile(ref cond, _, _) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}While", ind);
|
2016-10-24 07:28:58 -05:00
|
|
|
println!("{}condition:", ind);
|
|
|
|
print_expr(cx, cond, indent + 1);
|
|
|
|
},
|
|
|
|
hir::ExprLoop(..) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}Loop", ind);
|
2016-10-24 07:28:58 -05:00
|
|
|
},
|
|
|
|
hir::ExprMatch(ref cond, _, ref source) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}Match", ind);
|
2016-10-24 07:28:58 -05:00
|
|
|
println!("{}condition:", ind);
|
|
|
|
print_expr(cx, cond, indent + 1);
|
|
|
|
println!("{}source: {:?}", ind, source);
|
|
|
|
},
|
2017-08-30 03:54:24 -05:00
|
|
|
hir::ExprClosure(ref clause, _, _, _, _) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}Closure", ind);
|
2016-10-24 07:28:58 -05:00
|
|
|
println!("{}clause: {:?}", ind, clause);
|
|
|
|
},
|
2017-08-30 03:54:24 -05:00
|
|
|
hir::ExprYield(ref sub) => {
|
|
|
|
println!("{}Yield", ind);
|
|
|
|
print_expr(cx, sub, indent + 1);
|
2017-09-03 16:15:15 -05:00
|
|
|
},
|
2018-05-17 04:21:15 -05:00
|
|
|
hir::ExprBlock(_, _) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}Block", ind);
|
2016-10-24 07:28:58 -05:00
|
|
|
},
|
|
|
|
hir::ExprAssign(ref lhs, ref rhs) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}Assign", ind);
|
2016-10-24 07:28:58 -05:00
|
|
|
println!("{}lhs:", ind);
|
|
|
|
print_expr(cx, lhs, indent + 1);
|
|
|
|
println!("{}rhs:", ind);
|
|
|
|
print_expr(cx, rhs, indent + 1);
|
|
|
|
},
|
|
|
|
hir::ExprAssignOp(ref binop, ref lhs, ref rhs) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}AssignOp", ind);
|
2016-10-24 07:28:58 -05:00
|
|
|
println!("{}op: {:?}", ind, binop.node);
|
|
|
|
println!("{}lhs:", ind);
|
|
|
|
print_expr(cx, lhs, indent + 1);
|
|
|
|
println!("{}rhs:", ind);
|
|
|
|
print_expr(cx, rhs, indent + 1);
|
|
|
|
},
|
|
|
|
hir::ExprField(ref e, ref name) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}Field", ind);
|
2016-10-24 07:28:58 -05:00
|
|
|
println!("{}field name: {}", ind, name.node);
|
|
|
|
println!("{}struct expr:", ind);
|
|
|
|
print_expr(cx, e, indent + 1);
|
|
|
|
},
|
|
|
|
hir::ExprIndex(ref arr, ref idx) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}Index", ind);
|
2016-10-24 07:28:58 -05:00
|
|
|
println!("{}array expr:", ind);
|
|
|
|
print_expr(cx, arr, indent + 1);
|
|
|
|
println!("{}index expr:", ind);
|
|
|
|
print_expr(cx, idx, indent + 1);
|
|
|
|
},
|
2016-12-01 15:31:56 -06:00
|
|
|
hir::ExprPath(hir::QPath::Resolved(ref ty, ref path)) => {
|
|
|
|
println!("{}Resolved Path, {:?}", ind, ty);
|
2016-10-24 07:28:58 -05:00
|
|
|
println!("{}path: {:?}", ind, path);
|
|
|
|
},
|
2016-12-01 15:31:56 -06:00
|
|
|
hir::ExprPath(hir::QPath::TypeRelative(ref ty, ref seg)) => {
|
|
|
|
println!("{}Relative Path, {:?}", ind, ty);
|
|
|
|
println!("{}seg: {:?}", ind, seg);
|
2016-12-20 11:21:30 -06:00
|
|
|
},
|
2016-10-24 07:28:58 -05:00
|
|
|
hir::ExprAddrOf(ref muta, ref e) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}AddrOf", ind);
|
2016-10-24 07:28:58 -05:00
|
|
|
println!("mutability: {:?}", muta);
|
|
|
|
print_expr(cx, e, indent + 1);
|
|
|
|
},
|
2016-11-25 12:24:55 -06:00
|
|
|
hir::ExprBreak(_, ref e) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}Break", ind);
|
2016-11-25 12:24:55 -06:00
|
|
|
if let Some(ref e) = *e {
|
|
|
|
print_expr(cx, e, indent + 1);
|
|
|
|
}
|
|
|
|
},
|
2017-05-05 07:25:54 -05:00
|
|
|
hir::ExprAgain(_) => println!("{}Again", ind),
|
2016-10-24 07:28:58 -05:00
|
|
|
hir::ExprRet(ref e) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}Ret", ind);
|
2016-10-24 07:28:58 -05:00
|
|
|
if let Some(ref e) = *e {
|
|
|
|
print_expr(cx, e, indent + 1);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
hir::ExprInlineAsm(_, ref input, ref output) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}InlineAsm", ind);
|
2016-10-24 07:28:58 -05:00
|
|
|
println!("{}inputs:", ind);
|
|
|
|
for e in input {
|
|
|
|
print_expr(cx, e, indent + 1);
|
|
|
|
}
|
|
|
|
println!("{}outputs:", ind);
|
|
|
|
for e in output {
|
|
|
|
print_expr(cx, e, indent + 1);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
hir::ExprStruct(ref path, ref fields, ref base) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}Struct", ind);
|
2016-10-24 07:28:58 -05:00
|
|
|
println!("{}path: {:?}", ind, path);
|
|
|
|
for field in fields {
|
|
|
|
println!("{}field \"{}\":", ind, field.name.node);
|
|
|
|
print_expr(cx, &field.expr, indent + 1);
|
|
|
|
}
|
|
|
|
if let Some(ref base) = *base {
|
|
|
|
println!("{}base:", ind);
|
|
|
|
print_expr(cx, base, indent + 1);
|
|
|
|
}
|
|
|
|
},
|
2017-01-04 16:18:11 -06:00
|
|
|
hir::ExprRepeat(ref val, body_id) => {
|
2017-05-05 07:25:54 -05:00
|
|
|
println!("{}Repeat", ind);
|
2016-10-24 07:28:58 -05:00
|
|
|
println!("{}value:", ind);
|
|
|
|
print_expr(cx, val, indent + 1);
|
|
|
|
println!("{}repeat count:", ind);
|
2017-02-02 10:53:28 -06:00
|
|
|
print_expr(cx, &cx.tcx.hir.body(body_id).value, indent + 1);
|
2016-10-24 07:28:58 -05:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2016-10-24 07:29:09 -05:00
|
|
|
|
|
|
|
fn print_item(cx: &LateContext, item: &hir::Item) {
|
2017-02-02 10:53:28 -06:00
|
|
|
let did = cx.tcx.hir.local_def_id(item.id);
|
2016-10-24 07:29:09 -05:00
|
|
|
println!("item `{}`", item.name);
|
|
|
|
match item.vis {
|
|
|
|
hir::Visibility::Public => println!("public"),
|
|
|
|
hir::Visibility::Crate => println!("visible crate wide"),
|
2017-09-05 04:33:04 -05:00
|
|
|
hir::Visibility::Restricted { ref path, .. } => println!(
|
|
|
|
"visible in module `{}`",
|
|
|
|
print::to_string(print::NO_ANN, |s| s.print_path(path, false))
|
|
|
|
),
|
2016-10-24 07:29:09 -05:00
|
|
|
hir::Visibility::Inherited => println!("visibility inherited from outer item"),
|
|
|
|
}
|
|
|
|
match item.node {
|
|
|
|
hir::ItemExternCrate(ref _renamed_from) => {
|
2017-09-12 07:26:40 -05:00
|
|
|
let def_id = cx.tcx.hir.local_def_id(item.id);
|
|
|
|
if let Some(crate_id) = cx.tcx.extern_mod_stmt_cnum(def_id) {
|
2017-09-09 00:23:08 -05:00
|
|
|
let source = cx.tcx.used_crate_source(crate_id);
|
|
|
|
if let Some(ref src) = source.dylib {
|
2016-10-24 07:29:09 -05:00
|
|
|
println!("extern crate dylib source: {:?}", src.0);
|
|
|
|
}
|
2017-09-09 00:23:08 -05:00
|
|
|
if let Some(ref src) = source.rlib {
|
2016-10-24 07:29:09 -05:00
|
|
|
println!("extern crate rlib source: {:?}", src.0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
println!("weird extern crate without a crate id");
|
|
|
|
}
|
2016-12-20 11:21:30 -06:00
|
|
|
},
|
2016-12-01 15:31:56 -06:00
|
|
|
hir::ItemUse(ref path, ref kind) => println!("{:?}, {:?}", path, kind),
|
2017-04-27 07:00:35 -05:00
|
|
|
hir::ItemStatic(..) => println!("static item of type {:#?}", cx.tcx.type_of(did)),
|
|
|
|
hir::ItemConst(..) => println!("const item of type {:#?}", cx.tcx.type_of(did)),
|
2016-10-24 07:29:09 -05:00
|
|
|
hir::ItemFn(..) => {
|
2017-04-27 07:00:35 -05:00
|
|
|
let item_ty = cx.tcx.type_of(did);
|
2016-11-18 06:21:07 -06:00
|
|
|
println!("function of type {:#?}", item_ty);
|
2016-10-24 07:29:09 -05:00
|
|
|
},
|
|
|
|
hir::ItemMod(..) => println!("module"),
|
|
|
|
hir::ItemForeignMod(ref fm) => println!("foreign module with abi: {}", fm.abi),
|
2017-04-16 11:38:17 -05:00
|
|
|
hir::ItemGlobalAsm(ref asm) => println!("global asm: {:?}", asm),
|
2016-10-24 07:29:09 -05:00
|
|
|
hir::ItemTy(..) => {
|
2017-04-27 07:00:35 -05:00
|
|
|
println!("type alias for {:?}", cx.tcx.type_of(did));
|
2016-10-24 07:29:09 -05:00
|
|
|
},
|
|
|
|
hir::ItemEnum(..) => {
|
2017-04-27 07:00:35 -05:00
|
|
|
println!("enum definition of type {:?}", cx.tcx.type_of(did));
|
2016-10-24 07:29:09 -05:00
|
|
|
},
|
|
|
|
hir::ItemStruct(..) => {
|
2017-04-27 07:00:35 -05:00
|
|
|
println!("struct definition of type {:?}", cx.tcx.type_of(did));
|
2016-10-24 07:29:09 -05:00
|
|
|
},
|
|
|
|
hir::ItemUnion(..) => {
|
2017-04-27 07:00:35 -05:00
|
|
|
println!("union definition of type {:?}", cx.tcx.type_of(did));
|
2016-10-24 07:29:09 -05:00
|
|
|
},
|
|
|
|
hir::ItemTrait(..) => {
|
|
|
|
println!("trait decl");
|
2017-11-05 06:19:11 -06:00
|
|
|
if cx.tcx.trait_is_auto(did) {
|
|
|
|
println!("trait is auto");
|
2016-10-24 07:29:09 -05:00
|
|
|
} else {
|
2017-11-05 06:19:11 -06:00
|
|
|
println!("trait is not auto");
|
2016-10-24 07:29:09 -05:00
|
|
|
}
|
|
|
|
},
|
2017-12-15 03:02:39 -06:00
|
|
|
hir::ItemTraitAlias(..) => {
|
|
|
|
println!("trait alias");
|
|
|
|
}
|
2017-04-28 06:00:42 -05:00
|
|
|
hir::ItemImpl(_, _, _, _, Some(ref _trait_ref), _, _) => {
|
2016-12-01 15:31:56 -06:00
|
|
|
println!("trait impl");
|
2016-10-24 07:29:09 -05:00
|
|
|
},
|
2017-04-28 06:00:42 -05:00
|
|
|
hir::ItemImpl(_, _, _, _, None, _, _) => {
|
2016-10-24 07:29:09 -05:00
|
|
|
println!("impl");
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-24 07:28:58 -05:00
|
|
|
fn print_pat(cx: &LateContext, pat: &hir::Pat, indent: usize) {
|
|
|
|
let ind = " ".repeat(indent);
|
|
|
|
println!("{}+", ind);
|
|
|
|
match pat.node {
|
|
|
|
hir::PatKind::Wild => println!("{}Wild", ind),
|
2016-12-01 15:31:56 -06:00
|
|
|
hir::PatKind::Binding(ref mode, _, ref name, ref inner) => {
|
2016-10-24 07:28:58 -05:00
|
|
|
println!("{}Binding", ind);
|
|
|
|
println!("{}mode: {:?}", ind, mode);
|
|
|
|
println!("{}name: {}", ind, name.node);
|
|
|
|
if let Some(ref inner) = *inner {
|
|
|
|
println!("{}inner:", ind);
|
|
|
|
print_pat(cx, inner, indent + 1);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
hir::PatKind::Struct(ref path, ref fields, ignore) => {
|
|
|
|
println!("{}Struct", ind);
|
2017-08-09 02:30:56 -05:00
|
|
|
println!(
|
|
|
|
"{}name: {}",
|
|
|
|
ind,
|
|
|
|
print::to_string(print::NO_ANN, |s| s.print_qpath(path, false))
|
|
|
|
);
|
2016-10-24 07:28:58 -05:00
|
|
|
println!("{}ignore leftover fields: {}", ind, ignore);
|
|
|
|
println!("{}fields:", ind);
|
|
|
|
for field in fields {
|
|
|
|
println!("{} field name: {}", ind, field.node.name);
|
|
|
|
if field.node.is_shorthand {
|
|
|
|
println!("{} in shorthand notation", ind);
|
|
|
|
}
|
|
|
|
print_pat(cx, &field.node.pat, indent + 1);
|
|
|
|
}
|
|
|
|
},
|
2016-10-24 08:16:21 -05:00
|
|
|
hir::PatKind::TupleStruct(ref path, ref fields, opt_dots_position) => {
|
2016-10-24 07:28:58 -05:00
|
|
|
println!("{}TupleStruct", ind);
|
2017-08-09 02:30:56 -05:00
|
|
|
println!(
|
|
|
|
"{}path: {}",
|
|
|
|
ind,
|
|
|
|
print::to_string(print::NO_ANN, |s| s.print_qpath(path, false))
|
|
|
|
);
|
2016-10-24 07:28:58 -05:00
|
|
|
if let Some(dot_position) = opt_dots_position {
|
|
|
|
println!("{}dot position: {}", ind, dot_position);
|
|
|
|
}
|
2016-10-24 08:16:21 -05:00
|
|
|
for field in fields {
|
|
|
|
print_pat(cx, field, indent + 1);
|
2016-10-24 07:28:58 -05:00
|
|
|
}
|
|
|
|
},
|
2016-12-01 15:31:56 -06:00
|
|
|
hir::PatKind::Path(hir::QPath::Resolved(ref ty, ref path)) => {
|
|
|
|
println!("{}Resolved Path, {:?}", ind, ty);
|
2016-10-24 07:28:58 -05:00
|
|
|
println!("{}path: {:?}", ind, path);
|
|
|
|
},
|
2016-12-01 15:31:56 -06:00
|
|
|
hir::PatKind::Path(hir::QPath::TypeRelative(ref ty, ref seg)) => {
|
|
|
|
println!("{}Relative Path, {:?}", ind, ty);
|
|
|
|
println!("{}seg: {:?}", ind, seg);
|
|
|
|
},
|
2016-10-24 07:28:58 -05:00
|
|
|
hir::PatKind::Tuple(ref pats, opt_dots_position) => {
|
|
|
|
println!("{}Tuple", ind);
|
|
|
|
if let Some(dot_position) = opt_dots_position {
|
|
|
|
println!("{}dot position: {}", ind, dot_position);
|
|
|
|
}
|
|
|
|
for field in pats {
|
2016-10-24 08:16:21 -05:00
|
|
|
print_pat(cx, field, indent + 1);
|
2016-10-24 07:28:58 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
hir::PatKind::Box(ref inner) => {
|
|
|
|
println!("{}Box", ind);
|
|
|
|
print_pat(cx, inner, indent + 1);
|
|
|
|
},
|
|
|
|
hir::PatKind::Ref(ref inner, ref muta) => {
|
|
|
|
println!("{}Ref", ind);
|
|
|
|
println!("{}mutability: {:?}", ind, muta);
|
|
|
|
print_pat(cx, inner, indent + 1);
|
|
|
|
},
|
|
|
|
hir::PatKind::Lit(ref e) => {
|
|
|
|
println!("{}Lit", ind);
|
|
|
|
print_expr(cx, e, indent + 1);
|
|
|
|
},
|
2017-01-26 16:32:34 -06:00
|
|
|
hir::PatKind::Range(ref l, ref r, ref range_end) => {
|
2016-10-24 07:28:58 -05:00
|
|
|
println!("{}Range", ind);
|
|
|
|
print_expr(cx, l, indent + 1);
|
|
|
|
print_expr(cx, r, indent + 1);
|
2017-01-26 16:32:34 -06:00
|
|
|
match *range_end {
|
|
|
|
hir::RangeEnd::Included => println!("{} end included", ind),
|
|
|
|
hir::RangeEnd::Excluded => println!("{} end excluded", ind),
|
|
|
|
}
|
2016-10-24 07:28:58 -05:00
|
|
|
},
|
2016-10-24 08:16:21 -05:00
|
|
|
hir::PatKind::Slice(ref first_pats, ref range, ref last_pats) => {
|
2016-10-24 07:28:58 -05:00
|
|
|
println!("{}Slice [a, b, ..i, y, z]", ind);
|
|
|
|
println!("[a, b]:");
|
2016-10-24 08:16:21 -05:00
|
|
|
for pat in first_pats {
|
2016-10-24 07:28:58 -05:00
|
|
|
print_pat(cx, pat, indent + 1);
|
|
|
|
}
|
|
|
|
println!("i:");
|
|
|
|
if let Some(ref pat) = *range {
|
|
|
|
print_pat(cx, pat, indent + 1);
|
|
|
|
}
|
|
|
|
println!("[y, z]:");
|
2016-10-24 08:16:21 -05:00
|
|
|
for pat in last_pats {
|
2016-10-24 07:28:58 -05:00
|
|
|
print_pat(cx, pat, indent + 1);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|