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:
bors 2024-06-28 18:47:12 +00:00
commit 1aa236d59b
2 changed files with 27 additions and 23 deletions

View file

@ -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 {
"map" => "inspect",
"map_err" => "inspect_err",
_ => return,
}),
));
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| {
diag.multipart_suggestion("try", edits, app);
});
span_lint_and_then(
cx,
MANUAL_INSPECT,
name_span,
format!("using `{name}` over `{edit}`"),
|diag| {
diag.multipart_suggestion("try", edits, app);
},
);
}
}
}