Add error message to manual_inspect lint
This commit is contained in:
parent
68a799aea9
commit
01a6dfa29f
@ -167,14 +167,12 @@ pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, name:
|
||||
} else {
|
||||
edits.extend(addr_of_edits);
|
||||
}
|
||||
edits.push((
|
||||
name_span,
|
||||
String::from(match name {
|
||||
let edit = match name {
|
||||
"map" => "inspect",
|
||||
"map_err" => "inspect_err",
|
||||
_ => return,
|
||||
}),
|
||||
));
|
||||
};
|
||||
edits.push((name_span, edit.to_string()));
|
||||
edits.push((
|
||||
final_expr
|
||||
.span
|
||||
@ -187,9 +185,15 @@ pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, name:
|
||||
} else {
|
||||
Applicability::MachineApplicable
|
||||
};
|
||||
span_lint_and_then(cx, MANUAL_INSPECT, name_span, "", |diag| {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
MANUAL_INSPECT,
|
||||
name_span,
|
||||
format!("using `{name}` over `{edit}`"),
|
||||
|diag| {
|
||||
diag.multipart_suggestion("try", edits, app);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
error:
|
||||
error: using `map` over `inspect`
|
||||
--> tests/ui/manual_inspect.rs:5:21
|
||||
|
|
||||
LL | let _ = Some(0).map(|x| {
|
||||
@ -12,7 +12,7 @@ LL ~ let _ = Some(0).inspect(|&x| {
|
||||
LL ~ println!("{}", x);
|
||||
|
|
||||
|
||||
error:
|
||||
error: using `map` over `inspect`
|
||||
--> tests/ui/manual_inspect.rs:10:21
|
||||
|
|
||||
LL | let _ = Some(0).map(|x| {
|
||||
@ -24,7 +24,7 @@ LL ~ let _ = Some(0).inspect(|&x| {
|
||||
LL ~ println!("{x}");
|
||||
|
|
||||
|
||||
error:
|
||||
error: using `map` over `inspect`
|
||||
--> tests/ui/manual_inspect.rs:15:21
|
||||
|
|
||||
LL | let _ = Some(0).map(|x| {
|
||||
@ -36,7 +36,7 @@ LL ~ let _ = Some(0).inspect(|&x| {
|
||||
LL ~ println!("{}", x * 5 + 1);
|
||||
|
|
||||
|
||||
error:
|
||||
error: using `map` over `inspect`
|
||||
--> tests/ui/manual_inspect.rs:20:21
|
||||
|
|
||||
LL | let _ = Some(0).map(|x| {
|
||||
@ -50,7 +50,7 @@ LL | panic!();
|
||||
LL ~ }
|
||||
|
|
||||
|
||||
error:
|
||||
error: using `map` over `inspect`
|
||||
--> tests/ui/manual_inspect.rs:27:21
|
||||
|
|
||||
LL | let _ = Some(0).map(|x| {
|
||||
@ -65,7 +65,7 @@ LL | panic!();
|
||||
LL ~ }
|
||||
|
|
||||
|
||||
error:
|
||||
error: using `map` over `inspect`
|
||||
--> tests/ui/manual_inspect.rs:78:41
|
||||
|
|
||||
LL | let _ = Some((String::new(), 0u32)).map(|x| {
|
||||
@ -80,7 +80,7 @@ LL | panic!();
|
||||
LL ~ }
|
||||
|
|
||||
|
||||
error:
|
||||
error: using `map` over `inspect`
|
||||
--> tests/ui/manual_inspect.rs:104:33
|
||||
|
|
||||
LL | let _ = Some(String::new()).map(|x| {
|
||||
@ -98,7 +98,7 @@ LL | }
|
||||
LL ~ println!("test");
|
||||
|
|
||||
|
||||
error:
|
||||
error: using `map` over `inspect`
|
||||
--> tests/ui/manual_inspect.rs:115:21
|
||||
|
|
||||
LL | let _ = Some(0).map(|x| {
|
||||
@ -113,7 +113,7 @@ LL | panic!();
|
||||
LL ~ }
|
||||
|
|
||||
|
||||
error:
|
||||
error: using `map` over `inspect`
|
||||
--> tests/ui/manual_inspect.rs:130:46
|
||||
|
|
||||
LL | let _ = Some(Cell2(Cell::new(0u32))).map(|x| {
|
||||
@ -125,7 +125,7 @@ LL ~ let _ = Some(Cell2(Cell::new(0u32))).inspect(|x| {
|
||||
LL ~ x.0.set(1);
|
||||
|
|
||||
|
||||
error:
|
||||
error: using `map` over `inspect`
|
||||
--> tests/ui/manual_inspect.rs:146:34
|
||||
|
|
||||
LL | let _: Result<_, ()> = Ok(0).map(|x| {
|
||||
@ -137,7 +137,7 @@ LL ~ let _: Result<_, ()> = Ok(0).inspect(|&x| {
|
||||
LL ~ println!("{}", x);
|
||||
|
|
||||
|
||||
error:
|
||||
error: using `map_err` over `inspect_err`
|
||||
--> tests/ui/manual_inspect.rs:151:35
|
||||
|
|
||||
LL | let _: Result<(), _> = Err(0).map_err(|x| {
|
||||
@ -166,7 +166,7 @@ LL | | .count();
|
||||
= note: `-D clippy::suspicious-map` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::suspicious_map)]`
|
||||
|
||||
error:
|
||||
error: using `map` over `inspect`
|
||||
--> tests/ui/manual_inspect.rs:158:10
|
||||
|
|
||||
LL | .map(|x| {
|
||||
|
Loading…
Reference in New Issue
Block a user