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::EXPECT_USED;
9 /// lint use of `expect()` 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((EXPECT_USED, "an Option", "None"))
15 } else if is_type_diagnostic_item(cx, obj_ty, sym::result_type) {
16 Some((EXPECT_USED, "a Result", "Err"))
21 if let Some((lint, kind, none_value)) = mess {
26 &format!("used `expect()` on `{}` value", kind,),
28 &format!("if this value is an `{}`, it will panic", none_value,),