Skip to content

Commit 736158a

Browse files
committed
rm bitflag
1 parent 4ad4413 commit 736158a

File tree

2 files changed

+30
-45
lines changed

2 files changed

+30
-45
lines changed

clippy_lints/src/borrow_deref_ref.rs

+29-44
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::reference::DEREF_ADDROF;
2-
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then};
2+
use clippy_utils::diagnostics::span_lint_and_then;
33
use clippy_utils::is_lint_allowed;
44
use clippy_utils::source::snippet_opt;
55
use clippy_utils::ty::implements_trait;
@@ -25,7 +25,7 @@ declare_clippy_lint! {
2525
/// let x = &12;
2626
/// let addr_x = &x as *const _ as usize;
2727
/// let addr_y = &&*x as *const _ as usize; // assert ok now, and lint triggerd.
28-
/// // But if we apply it, it will assert fail.
28+
/// // But if we fix it, assert will fail.
2929
/// assert_ne!(addr_x, addr_y);
3030
/// ```
3131
///
@@ -80,51 +80,36 @@ impl LateLintPass<'_> for BorrowDerefRef {
8080
}
8181
}
8282

83-
let mut give_2_help = true;
83+
span_lint_and_then(
84+
cx,
85+
BORROW_DEREF_REF,
86+
e.span,
87+
"deref on an immutable reference",
88+
|diag| {
89+
diag.help(
90+
&format!(
91+
"consider using `{}` if you would like to reborrow",
92+
&snippet_opt(cx, deref_expr.span).unwrap(),
93+
)
94+
);
8495

85-
// has deref trait -> give 2 help
86-
// doesn't have deref trait -> give 1 help
87-
if let Some(deref_trait_id) = cx.tcx.lang_items().deref_trait(){
88-
if !implements_trait(cx, inner_ty, deref_trait_id, &[]) {
89-
give_2_help = false;
90-
}
91-
}
92-
93-
if give_2_help {
94-
span_lint_and_then(
95-
cx,
96-
BORROW_DEREF_REF,
97-
e.span,
98-
"deref on an immutable reference",
99-
|diag| {
100-
diag.help(
101-
&format!(
102-
"consider using `{}` if you would like to deref",
103-
"&**".to_owned() + &snippet_opt(cx, deref_expr.span).unwrap(),
104-
)
105-
);
106-
diag.help(
107-
&format!(
108-
"consider using `{}` if you would like to reborrow",
109-
&snippet_opt(cx, deref_expr.span).unwrap(),
110-
)
111-
);
96+
// has deref trait -> give 2 help
97+
// doesn't have deref trait -> give 1 help
98+
if let Some(deref_trait_id) = cx.tcx.lang_items().deref_trait(){
99+
if !implements_trait(cx, inner_ty, deref_trait_id, &[]) {
100+
return;
101+
}
112102
}
113-
);
114-
}else {
115-
span_lint_and_help(
116-
cx,
117-
BORROW_DEREF_REF,
118-
e.span,
119-
"deref on an immutable reference",
120-
None,
121-
&format!(
122-
"consider using `{}` if you would like to reborrow",
123-
&snippet_opt(cx, deref_expr.span).unwrap(),
124-
)
125-
);
126-
}
127103

104+
diag.help(
105+
&format!(
106+
"consider using `{}` if you would like to deref",
107+
"&**".to_owned() + &snippet_opt(cx, deref_expr.span).unwrap(),
108+
)
109+
);
110+
111+
}
112+
);
128113

129114
}
130115
}

tests/ui/borrow_deref_ref.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ error: deref on an immutable reference
1313
LL | let x: &str = &*s;
1414
| ^^^
1515
|
16-
= help: consider using `&**s` if you would like to deref
1716
= help: consider using `s` if you would like to reborrow
17+
= help: consider using `&**s` if you would like to deref
1818

1919
error: deref on an immutable reference
2020
--> $DIR/borrow_deref_ref.rs:11:22

0 commit comments

Comments
 (0)