]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui-internal/unnecessary_def_path.fixed
Rollup merge of #104581 - notriddle:notriddle/js-iife-2, r=GuillaumeGomez
[rust.git] / src / tools / clippy / tests / ui-internal / unnecessary_def_path.fixed
1 // run-rustfix
2 // aux-build:paths.rs
3 #![deny(clippy::internal)]
4 #![feature(rustc_private)]
5
6 extern crate clippy_utils;
7 extern crate paths;
8 extern crate rustc_hir;
9 extern crate rustc_lint;
10 extern crate rustc_middle;
11 extern crate rustc_span;
12
13 #[allow(unused)]
14 use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item, match_type};
15 #[allow(unused)]
16 use clippy_utils::{
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,
19 };
20
21 #[allow(unused)]
22 use rustc_hir::LangItem;
23 #[allow(unused)]
24 use rustc_span::sym;
25
26 use rustc_hir::def_id::DefId;
27 use rustc_hir::Expr;
28 use rustc_lint::LateContext;
29 use rustc_middle::ty::Ty;
30
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"];
35
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);
40
41     #[allow(unused, clippy::unnecessary_def_path)]
42     let rc_path = &["alloc", "rc", "Rc"];
43     let _ = is_type_diagnostic_item(cx, ty, sym::Rc);
44
45     let _ = is_type_diagnostic_item(cx, ty, sym::Option);
46     let _ = is_type_diagnostic_item(cx, ty, sym::Result);
47
48     let _ = is_type_lang_item(cx, ty, LangItem::OwnedBox);
49     let _ = is_type_diagnostic_item(cx, ty, sym::maybe_uninit_uninit);
50
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);
54
55     let _ = is_trait_method(cx, expr, sym::AsRef);
56
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);
60 }
61
62 fn main() {}