3 #![deny(clippy::internal)]
4 #![feature(rustc_private)]
6 extern crate clippy_utils;
8 extern crate rustc_hir;
9 extern crate rustc_lint;
10 extern crate rustc_middle;
11 extern crate rustc_span;
14 use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item, match_type};
17 is_expr_path_def_path, is_path_diagnostic_item, is_res_diagnostic_ctor, is_res_lang_ctor, is_trait_method,
18 match_def_path, match_trait_method, path_res,
22 use rustc_hir::LangItem;
26 use rustc_hir::def_id::DefId;
28 use rustc_lint::LateContext;
29 use rustc_middle::ty::Ty;
31 #[allow(unused, clippy::unnecessary_def_path)]
32 static OPTION: [&str; 3] = ["core", "option", "Option"];
33 #[allow(unused, clippy::unnecessary_def_path)]
34 const RESULT: &[&str] = &["core", "result", "Result"];
36 fn _f<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, did: DefId, expr: &Expr<'_>) {
37 let _ = is_type_diagnostic_item(cx, ty, sym::Option);
38 let _ = is_type_diagnostic_item(cx, ty, sym::Result);
39 let _ = is_type_diagnostic_item(cx, ty, sym::Result);
41 #[allow(unused, clippy::unnecessary_def_path)]
42 let rc_path = &["alloc", "rc", "Rc"];
43 let _ = is_type_diagnostic_item(cx, ty, sym::Rc);
45 let _ = is_type_diagnostic_item(cx, ty, sym::Option);
46 let _ = is_type_diagnostic_item(cx, ty, sym::Result);
48 let _ = is_type_lang_item(cx, ty, LangItem::OwnedBox);
49 let _ = is_type_diagnostic_item(cx, ty, sym::maybe_uninit_uninit);
51 let _ = cx.tcx.lang_items().get(LangItem::OwnedBox) == Some(did);
52 let _ = cx.tcx.is_diagnostic_item(sym::Option, did);
53 let _ = cx.tcx.lang_items().get(LangItem::OptionSome) == Some(did);
55 let _ = is_trait_method(cx, expr, sym::AsRef);
57 let _ = is_path_diagnostic_item(cx, expr, sym::Option);
58 let _ = path_res(cx, expr).opt_def_id().map_or(false, |id| cx.tcx.lang_items().get(LangItem::IteratorNext) == Some(id));
59 let _ = is_res_lang_ctor(cx, path_res(cx, expr), LangItem::OptionSome);