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