1 use clippy_utils::diagnostics::span_lint_and_help;
2 use clippy_utils::ty::is_type_diagnostic_item;
4 use rustc_lint::LateContext;
7 use super::UNWRAP_USED;
9 /// lint use of `unwrap()` for `Option`s and `Result`s
10 pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) {
11 let obj_ty = cx.typeck_results().expr_ty(recv).peel_refs();
13 let mess = if is_type_diagnostic_item(cx, obj_ty, sym::option_type) {
14 Some((UNWRAP_USED, "an Option", "None"))
15 } else if is_type_diagnostic_item(cx, obj_ty, sym::result_type) {
16 Some((UNWRAP_USED, "a Result", "Err"))
21 if let Some((lint, kind, none_value)) = mess {
26 &format!("used `unwrap()` on `{}` value", kind,),
29 "if you don't want to handle the `{}` case gracefully, consider \
30 using `expect()` to provide a better panic message",