File tree Expand file tree Collapse file tree 4 files changed +26
-6
lines changed Expand file tree Collapse file tree 4 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -267,7 +267,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
267
267
reg. register_late_lint_pass ( box ok_if_let:: Pass ) ;
268
268
reg. register_late_lint_pass ( box if_let_redundant_pattern_matching:: Pass ) ;
269
269
reg. register_late_lint_pass ( box partialeq_ne_impl:: Pass ) ;
270
- reg. register_late_lint_pass ( box reference:: Pass ) ;
270
+ reg. register_early_lint_pass ( box reference:: Pass ) ;
271
271
272
272
reg. register_lint_group ( "clippy_restrictions" , vec ! [
273
273
arithmetic:: FLOAT_ARITHMETIC ,
Original file line number Diff line number Diff line change 1
- use rustc :: hir :: * ;
1
+ use syntax :: ast :: { Expr , ExprKind , UnOp } ;
2
2
use rustc:: lint:: * ;
3
3
use utils:: { span_lint_and_then, snippet} ;
4
4
@@ -29,10 +29,17 @@ impl LintPass for Pass {
29
29
}
30
30
}
31
31
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 {
32
+ fn without_parens ( mut e : & Expr ) -> & Expr {
33
+ while let ExprKind :: Paren ( ref child_e) = e. node {
34
+ e = child_e;
35
+ }
36
+ e
37
+ }
38
+
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 {
36
43
span_lint_and_then (
37
44
cx,
38
45
DEREF_ADDROF ,
Original file line number Diff line number Diff line change 5
5
#![ allow( unused_variables) ]
6
6
#![ allow( unused_assignments) ]
7
7
#![ allow( if_same_then_else) ]
8
+ #![ allow( deref_addrof) ]
8
9
9
10
fn foo ( ) -> bool { true }
10
11
Original file line number Diff line number Diff line change @@ -34,11 +34,23 @@ fn main() {
34
34
//~|HELP try this
35
35
//~|SUGGESTION let b = bytes[1..2][0];
36
36
37
+ //This produces a suggestion of 'let b = (a);' which
38
+ //will trigger the 'unused_parens' lint
39
+ let b = * & ( a) ;
40
+ //~^ERROR immediately dereferencing a reference
41
+ //~|HELP try this
42
+ //~|SUGGESTION let b = (a)
43
+
37
44
let b = * ( & a) ;
38
45
//~^ERROR immediately dereferencing a reference
39
46
//~|HELP try this
40
47
//~|SUGGESTION let b = a;
41
48
49
+ let b = * ( ( & a) ) ;
50
+ //~^ERROR immediately dereferencing a reference
51
+ //~|HELP try this
52
+ //~|SUGGESTION let b = a
53
+
42
54
let b = * & & a;
43
55
//~^ERROR immediately dereferencing a reference
44
56
//~|HELP try this
You can’t perform that action at this time.
0 commit comments