2 use rustc_front::hir::*;
8 "transmutes that have the same to and from types"
11 pub struct UselessTransmute;
13 impl LintPass for UselessTransmute {
14 fn get_lints(&self) -> LintArray {
15 lint_array!(USELESS_TRANSMUTE)
19 impl LateLintPass for UselessTransmute {
20 fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
21 if let ExprCall(ref path_expr, ref args) = e.node {
22 if let ExprPath(None, _) = path_expr.node {
23 let def_id = cx.tcx.def_map.borrow()[&path_expr.id].def_id();
25 if utils::match_def_path(cx, def_id, &["core", "intrinsics", "transmute"]) {
26 let from_ty = cx.tcx.expr_ty(&args[0]);
27 let to_ty = cx.tcx.expr_ty(e);
30 cx.span_lint(USELESS_TRANSMUTE, e.span,
31 &format!("transmute from a type (`{}`) to itself", from_ty));