3 use utils::{span_lint_and_then, 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 impl LateLintPass for Pass {
33 fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
34 if let ExprUnary(UnDeref, ref deref_target) = e.node {
35 if let ExprAddrOf(_, ref addrof_target) = deref_target.node {
40 "immediately dereferencing a reference",
42 db.span_suggestion(e.span, "try this",
43 format!("{}", snippet(cx, addrof_target.span, "_")));