Skip to content

Commit 1aa236d

Browse files
committed
Auto merge of #13006 - flip1995:manual-inspect-error-message, r=Jarcho
Add error message to manual_inspect lint r? `@Jarcho` changelog: none
2 parents 2f80536 + 01a6dfa commit 1aa236d

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

clippy_lints/src/methods/manual_inspect.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,12 @@ pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, name:
167167
} else {
168168
edits.extend(addr_of_edits);
169169
}
170-
edits.push((
171-
name_span,
172-
String::from(match name {
173-
"map" => "inspect",
174-
"map_err" => "inspect_err",
175-
_ => return,
176-
}),
177-
));
170+
let edit = match name {
171+
"map" => "inspect",
172+
"map_err" => "inspect_err",
173+
_ => return,
174+
};
175+
edits.push((name_span, edit.to_string()));
178176
edits.push((
179177
final_expr
180178
.span
@@ -187,9 +185,15 @@ pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, name:
187185
} else {
188186
Applicability::MachineApplicable
189187
};
190-
span_lint_and_then(cx, MANUAL_INSPECT, name_span, "", |diag| {
191-
diag.multipart_suggestion("try", edits, app);
192-
});
188+
span_lint_and_then(
189+
cx,
190+
MANUAL_INSPECT,
191+
name_span,
192+
format!("using `{name}` over `{edit}`"),
193+
|diag| {
194+
diag.multipart_suggestion("try", edits, app);
195+
},
196+
);
193197
}
194198
}
195199
}

tests/ui/manual_inspect.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error:
1+
error: using `map` over `inspect`
22
--> tests/ui/manual_inspect.rs:5:21
33
|
44
LL | let _ = Some(0).map(|x| {
@@ -12,7 +12,7 @@ LL ~ let _ = Some(0).inspect(|&x| {
1212
LL ~ println!("{}", x);
1313
|
1414

15-
error:
15+
error: using `map` over `inspect`
1616
--> tests/ui/manual_inspect.rs:10:21
1717
|
1818
LL | let _ = Some(0).map(|x| {
@@ -24,7 +24,7 @@ LL ~ let _ = Some(0).inspect(|&x| {
2424
LL ~ println!("{x}");
2525
|
2626

27-
error:
27+
error: using `map` over `inspect`
2828
--> tests/ui/manual_inspect.rs:15:21
2929
|
3030
LL | let _ = Some(0).map(|x| {
@@ -36,7 +36,7 @@ LL ~ let _ = Some(0).inspect(|&x| {
3636
LL ~ println!("{}", x * 5 + 1);
3737
|
3838

39-
error:
39+
error: using `map` over `inspect`
4040
--> tests/ui/manual_inspect.rs:20:21
4141
|
4242
LL | let _ = Some(0).map(|x| {
@@ -50,7 +50,7 @@ LL | panic!();
5050
LL ~ }
5151
|
5252

53-
error:
53+
error: using `map` over `inspect`
5454
--> tests/ui/manual_inspect.rs:27:21
5555
|
5656
LL | let _ = Some(0).map(|x| {
@@ -65,7 +65,7 @@ LL | panic!();
6565
LL ~ }
6666
|
6767

68-
error:
68+
error: using `map` over `inspect`
6969
--> tests/ui/manual_inspect.rs:78:41
7070
|
7171
LL | let _ = Some((String::new(), 0u32)).map(|x| {
@@ -80,7 +80,7 @@ LL | panic!();
8080
LL ~ }
8181
|
8282

83-
error:
83+
error: using `map` over `inspect`
8484
--> tests/ui/manual_inspect.rs:104:33
8585
|
8686
LL | let _ = Some(String::new()).map(|x| {
@@ -98,7 +98,7 @@ LL | }
9898
LL ~ println!("test");
9999
|
100100

101-
error:
101+
error: using `map` over `inspect`
102102
--> tests/ui/manual_inspect.rs:115:21
103103
|
104104
LL | let _ = Some(0).map(|x| {
@@ -113,7 +113,7 @@ LL | panic!();
113113
LL ~ }
114114
|
115115

116-
error:
116+
error: using `map` over `inspect`
117117
--> tests/ui/manual_inspect.rs:130:46
118118
|
119119
LL | let _ = Some(Cell2(Cell::new(0u32))).map(|x| {
@@ -125,7 +125,7 @@ LL ~ let _ = Some(Cell2(Cell::new(0u32))).inspect(|x| {
125125
LL ~ x.0.set(1);
126126
|
127127

128-
error:
128+
error: using `map` over `inspect`
129129
--> tests/ui/manual_inspect.rs:146:34
130130
|
131131
LL | let _: Result<_, ()> = Ok(0).map(|x| {
@@ -137,7 +137,7 @@ LL ~ let _: Result<_, ()> = Ok(0).inspect(|&x| {
137137
LL ~ println!("{}", x);
138138
|
139139

140-
error:
140+
error: using `map_err` over `inspect_err`
141141
--> tests/ui/manual_inspect.rs:151:35
142142
|
143143
LL | let _: Result<(), _> = Err(0).map_err(|x| {
@@ -166,7 +166,7 @@ LL | | .count();
166166
= note: `-D clippy::suspicious-map` implied by `-D warnings`
167167
= help: to override `-D warnings` add `#[allow(clippy::suspicious_map)]`
168168

169-
error:
169+
error: using `map` over `inspect`
170170
--> tests/ui/manual_inspect.rs:158:10
171171
|
172172
LL | .map(|x| {

0 commit comments

Comments
 (0)