|
1 |
| -use clippy_utils::diagnostics::span_lint_and_sugg; |
| 1 | +use clippy_utils::diagnostics::span_lint_and_help; |
2 | 2 | use clippy_utils::in_macro;
|
3 | 3 | use clippy_utils::source::snippet_opt;
|
4 |
| -use clippy_utils::source::snippet_with_applicability; |
5 |
| -use rustc_errors::Applicability; |
6 | 4 | use rustc_hir::ExprKind;
|
7 | 5 | use rustc_hir::UnOp;
|
8 | 6 | use rustc_lint::{LateContext, LateLintPass};
|
@@ -69,29 +67,18 @@ impl LateLintPass<'_> for NeedlessDeref {
|
69 | 67 | }
|
70 | 68 |
|
71 | 69 |
|
72 |
| - let outer_ty=cx.typeck_results().expr_ty(e); |
73 |
| - let mut applicability = Applicability::MachineApplicable; |
74 |
| - if inner_ty == outer_ty { |
75 |
| - span_lint_and_sugg( |
76 |
| - cx, |
77 |
| - NEEDLESS_DEREF, |
78 |
| - e.span, |
79 |
| - "immediately dereferencing a reference", |
80 |
| - "try this", |
81 |
| - snippet_with_applicability(cx, deref_target.span, "_", &mut applicability).to_string(), |
82 |
| - applicability, |
83 |
| - ); |
84 |
| - }else{ |
85 |
| - span_lint_and_sugg( |
86 |
| - cx, |
87 |
| - NEEDLESS_DEREF, |
88 |
| - e.span, |
89 |
| - "reference on a de-referenced", |
90 |
| - "you may want to do this", |
| 70 | + span_lint_and_help( |
| 71 | + cx, |
| 72 | + NEEDLESS_DEREF, |
| 73 | + e.span, |
| 74 | + "reference on a de-referenced", |
| 75 | + None, |
| 76 | + &format!( |
| 77 | + "consider using `{}` if you would like to deref\nconsider using `{}` if you would like to reborrow", |
91 | 78 | "&**".to_owned()+&snippet_opt(cx, deref_target.span).unwrap(),
|
92 |
| - Applicability::MachineApplicable, |
93 |
| - ); |
94 |
| - } |
| 79 | + &snippet_opt(cx, deref_target.span).unwrap(), |
| 80 | + ) |
| 81 | + ); |
95 | 82 | }
|
96 | 83 | }
|
97 | 84 | }
|
|
0 commit comments