2 use rustc_front::hir::*;
5 /// **What it does:** This lint checks for transmutes to the original type of the object. It is `Warn` by default.
7 /// **Why is this bad?** Readability. The code tricks people into thinking that the original value was of some other type.
9 /// **Known problems:** None.
11 /// **Example:** `core::intrinsics::transmute(t)` where the result type is the same as `t`'s.
13 pub USELESS_TRANSMUTE,
15 "transmutes that have the same to and from types"
18 pub struct UselessTransmute;
20 impl LintPass for UselessTransmute {
21 fn get_lints(&self) -> LintArray {
22 lint_array!(USELESS_TRANSMUTE)
26 impl LateLintPass for UselessTransmute {
27 fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
28 if let ExprCall(ref path_expr, ref args) = e.node {
29 if let ExprPath(None, _) = path_expr.node {
30 let def_id = cx.tcx.def_map.borrow()[&path_expr.id].def_id();
32 if utils::match_def_path(cx, def_id, &["core", "intrinsics", "transmute"]) {
33 let from_ty = cx.tcx.expr_ty(&args[0]);
34 let to_ty = cx.tcx.expr_ty(e);
37 cx.span_lint(USELESS_TRANSMUTE, e.span,
38 &format!("transmute from a type (`{}`) to itself", from_ty));