1 //! Checks for needless address of operations (`&`)
3 //! This lint is **warn** by default
8 use utils::{span_lint, in_macro};
10 /// **What it does:** This lint checks for address of operations (`&`) that are going to be dereferenced immediately by the compiler
12 /// **Why is this bad?** Suggests that the receiver of the expression borrows the expression
14 /// **Known problems:**
16 /// **Example:** `let x: &i32 = &&&&&&5;`
20 "taking a reference that is going to be automatically dereferenced"
24 pub struct NeedlessBorrow;
26 impl LintPass for NeedlessBorrow {
27 fn get_lints(&self) -> LintArray {
28 lint_array!(NEEDLESS_BORROW)
32 impl LateLintPass for NeedlessBorrow {
33 fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
34 if in_macro(cx, e.span) {
37 if let ExprAddrOf(MutImmutable, ref inner) = e.node {
38 if let TyRef(..) = cx.tcx.expr_ty(inner).sty {
39 let ty = cx.tcx.expr_ty(e);
40 let adj_ty = cx.tcx.expr_ty_adjusted(e);
45 "this expression borrows a reference that is immediately dereferenced by the compiler");