1 use syntax::ast::{Expr, ExprKind, UnOp};
3 use utils::{span_lint_and_sugg, snippet};
5 /// **What it does:** Checks for usage of `*&` and `*&mut` in expressions.
7 /// **Why is this bad?** Immediately dereferencing a reference is no-op and
8 /// makes the code less clear.
10 /// **Known problems:** Multiple dereference/addrof pairs are not handled so
11 /// the suggested fix for `x = **&&y` is `x = *&y`, which is still incorrect.
15 /// let a = f(*&mut b);
21 "use of `*&` or `*&mut` in an expression"
26 impl LintPass for Pass {
27 fn get_lints(&self) -> LintArray {
28 lint_array!(DEREF_ADDROF)
32 fn without_parens(mut e: &Expr) -> &Expr {
33 while let ExprKind::Paren(ref child_e) = e.node {
39 impl EarlyLintPass for Pass {
40 fn check_expr(&mut self, cx: &EarlyContext, e: &Expr) {
41 if let ExprKind::Unary(UnOp::Deref, ref deref_target) = e.node {
42 if let ExprKind::AddrOf(_, ref addrof_target) = without_parens(deref_target).node {
47 "immediately dereferencing a reference",
49 format!("{}", snippet(cx, addrof_target.span, "_")),