Skip to content

Commit b6a6aac

Browse files
committed
refactor with map
1 parent 86c6db9 commit b6a6aac

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

clippy_lints/src/borrow_deref_ref.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,20 @@ impl LateLintPass<'_> for BorrowDerefRef {
9191

9292
// has deref trait -> give 2 help
9393
// doesn't have deref trait -> give 1 help
94-
if let Some(deref_trait_id) = cx.tcx.lang_items().deref_trait(){
95-
if !implements_trait(cx, inner_ty, deref_trait_id, &[]) {
96-
return;
94+
match cx.tcx.lang_items()
95+
.deref_trait()
96+
.map(|deref_trait_id| implements_trait(cx, inner_ty, deref_trait_id, &[]) ) {
97+
Some(false) => {}
98+
_ => {
99+
diag.help(
100+
&format!(
101+
"consider using `&**{}` if you would like to deref",
102+
&snippet_opt(cx, deref_target.span).unwrap(),
103+
)
104+
);
97105
}
98106
}
99107

100-
diag.help(
101-
&format!(
102-
"consider using `&**{}` if you would like to deref",
103-
&snippet_opt(cx, deref_target.span).unwrap(),
104-
)
105-
);
106-
107108
}
108109
);
109110

0 commit comments

Comments
 (0)