File tree Expand file tree Collapse file tree 3 files changed +19
-11
lines changed Expand file tree Collapse file tree 3 files changed +19
-11
lines changed Original file line number Diff line number Diff line change 1
- use clippy_utils:: diagnostics:: span_lint_and_help ;
1
+ use clippy_utils:: diagnostics:: span_lint_and_then ;
2
2
use clippy_utils:: source:: snippet_opt;
3
3
use rustc_hir:: { ExprKind , UnOp } ;
4
4
use rustc_lint:: { LateContext , LateLintPass } ;
@@ -63,17 +63,25 @@ impl LateLintPass<'_> for NeedlessDeref {
63
63
}
64
64
}
65
65
66
- span_lint_and_help (
66
+ span_lint_and_then (
67
67
cx,
68
68
NEEDLESS_DEREF ,
69
69
e. span,
70
70
"deref on an immutable borrow" ,
71
- None ,
72
- & format!(
73
- "consider using `{}` if you would like to deref\n consider using `{}` if you would like to reborrow" ,
74
- "&**" . to_owned( ) + & snippet_opt( cx, deref_target. span) . unwrap( ) ,
75
- & snippet_opt( cx, deref_target. span) . unwrap( ) ,
76
- )
71
+ |diag| {
72
+ diag. help(
73
+ & format!(
74
+ "consider using `{}` if you would like to deref" ,
75
+ "&**" . to_owned( ) + & snippet_opt( cx, deref_target. span) . unwrap( ) ,
76
+ )
77
+ ) ;
78
+ diag. help(
79
+ & format!(
80
+ "consider using `{}` if you would like to reborrow" ,
81
+ & snippet_opt( cx, deref_target. span) . unwrap( ) ,
82
+ )
83
+ ) ;
84
+ }
77
85
) ;
78
86
}
79
87
}
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ mod should_not_lint {
20
20
foo ( & mut & * x) ; // should not lint
21
21
assert_eq ! ( * x, 0 ) ;
22
22
23
- foo ( & mut x) ; // should not lint
23
+ foo ( & mut x) ;
24
24
assert_eq ! ( * x, 1 ) ;
25
25
}
26
26
}
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ LL | let _b = &*a;
6
6
|
7
7
= note: `-D clippy::needless-deref` implied by `-D warnings`
8
8
= help: consider using `&**a` if you would like to deref
9
- consider using `a` if you would like to reborrow
9
+ = help: consider using `a` if you would like to reborrow
10
10
11
11
error: deref on an immutable borrow
12
12
--> $DIR/needless_deref.rs:9:23
@@ -15,7 +15,7 @@ LL | let a: &str = &*s;
15
15
| ^^^
16
16
|
17
17
= help: consider using `&**s` if you would like to deref
18
- consider using `s` if you would like to reborrow
18
+ = help: consider using `s` if you would like to reborrow
19
19
20
20
error: aborting due to 2 previous errors
21
21
You can’t perform that action at this time.
0 commit comments