1 use crate::utils::{is_type_diagnostic_item, span_lint_and_help};
3 use rustc_lint::LateContext;
6 use super::EXPECT_USED;
8 /// lint use of `expect()` for `Option`s and `Result`s
9 pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, expect_args: &[hir::Expr<'_>]) {
10 let obj_ty = cx.typeck_results().expr_ty(&expect_args[0]).peel_refs();
12 let mess = if is_type_diagnostic_item(cx, obj_ty, sym::option_type) {
13 Some((EXPECT_USED, "an Option", "None"))
14 } else if is_type_diagnostic_item(cx, obj_ty, sym::result_type) {
15 Some((EXPECT_USED, "a Result", "Err"))
20 if let Some((lint, kind, none_value)) = mess {
25 &format!("used `expect()` on `{}` value", kind,),
27 &format!("if this value is an `{}`, it will panic", none_value,),