reg.register_late_lint_pass(box ok_if_let::Pass);
reg.register_late_lint_pass(box if_let_redundant_pattern_matching::Pass);
reg.register_late_lint_pass(box partialeq_ne_impl::Pass);
- reg.register_late_lint_pass(box reference::Pass);
+ reg.register_early_lint_pass(box reference::Pass);
reg.register_lint_group("clippy_restrictions", vec![
arithmetic::FLOAT_ARITHMETIC,
-use rustc::hir::*;
+use syntax::ast::{Expr,ExprKind,UnOp};
use rustc::lint::*;
use utils::{span_lint_and_then, snippet};
}
}
-impl LateLintPass for Pass {
- fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
- if let ExprUnary(UnDeref, ref deref_target) = e.node {
- if let ExprAddrOf(_, ref addrof_target) = deref_target.node {
+fn without_parens(mut e: &Expr) -> &Expr {
+ while let ExprKind::Paren(ref child_e) = e.node {
+ e = child_e;
+ }
+ e
+}
+
+impl EarlyLintPass for Pass {
+ fn check_expr(&mut self, cx: &EarlyContext, e: &Expr) {
+ if let ExprKind::Unary(UnOp::Deref, ref deref_target) = e.node {
+ if let ExprKind::AddrOf(_, ref addrof_target) = without_parens(deref_target).node {
span_lint_and_then(
cx,
DEREF_ADDROF,
#![allow(unused_variables)]
#![allow(unused_assignments)]
#![allow(if_same_then_else)]
+#![allow(deref_addrof)]
fn foo() -> bool { true }
//~|HELP try this
//~|SUGGESTION let b = bytes[1..2][0];
+ //This produces a suggestion of 'let b = (a);' which
+ //will trigger the 'unused_parens' lint
+ let b = *&(a);
+ //~^ERROR immediately dereferencing a reference
+ //~|HELP try this
+ //~|SUGGESTION let b = (a)
+
let b = *(&a);
//~^ERROR immediately dereferencing a reference
//~|HELP try this
//~|SUGGESTION let b = a;
+ let b = *((&a));
+ //~^ERROR immediately dereferencing a reference
+ //~|HELP try this
+ //~|SUGGESTION let b = a
+
let b = *&&a;
//~^ERROR immediately dereferencing a reference
//~|HELP try this