Skip to content

Commit 00799d2

Browse files
committed
don't auto fix
1 parent 501fb20 commit 00799d2

File tree

2 files changed

+16
-27
lines changed

2 files changed

+16
-27
lines changed

clippy_lints/src/needless_deref.rs

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use clippy_utils::diagnostics::span_lint_and_sugg;
1+
use clippy_utils::diagnostics::span_lint_and_help;
22
use clippy_utils::in_macro;
33
use clippy_utils::source::snippet_opt;
4-
use clippy_utils::source::snippet_with_applicability;
5-
use rustc_errors::Applicability;
64
use rustc_hir::ExprKind;
75
use rustc_hir::UnOp;
86
use rustc_lint::{LateContext, LateLintPass};
@@ -69,29 +67,18 @@ impl LateLintPass<'_> for NeedlessDeref {
6967
}
7068

7169

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",
9178
"&**".to_owned()+&snippet_opt(cx, deref_target.span).unwrap(),
92-
Applicability::MachineApplicable,
93-
);
94-
}
79+
&snippet_opt(cx, deref_target.span).unwrap(),
80+
)
81+
);
9582
}
9683
}
9784
}

tests/ui/needless_deref.stderr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
error: immediately dereferencing a reference
1+
error: reference on a de-referenced
22
--> $DIR/needless_deref.rs:6:18
33
|
44
LL | let _b = &*a;
5-
| ^^^ help: try this: `a`
5+
| ^^^
66
|
77
= note: `-D clippy::needless-deref` implied by `-D warnings`
8+
= help: consider using `&**a` if you would like to deref
9+
consider using `a` if you would like to reborrow
810

911
error: aborting due to previous error
1012

0 commit comments

Comments
 (0)