]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui-internal/unnecessary_def_path.rs
Rollup merge of #105768 - fee1-dead-contrib:iat-style, r=eholk
[rust.git] / src / tools / clippy / tests / ui-internal / unnecessary_def_path.rs
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 _ = match_type(cx, ty, &OPTION);
38     let _ = match_type(cx, ty, RESULT);
39     let _ = match_type(cx, ty, &["core", "result", "Result"]);
40
41     #[allow(unused, clippy::unnecessary_def_path)]
42     let rc_path = &["alloc", "rc", "Rc"];
43     let _ = clippy_utils::ty::match_type(cx, ty, rc_path);
44
45     let _ = match_type(cx, ty, &paths::OPTION);
46     let _ = match_type(cx, ty, paths::RESULT);
47
48     let _ = match_type(cx, ty, &["alloc", "boxed", "Box"]);
49     let _ = match_type(cx, ty, &["core", "mem", "maybe_uninit", "MaybeUninit", "uninit"]);
50
51     let _ = match_def_path(cx, did, &["alloc", "boxed", "Box"]);
52     let _ = match_def_path(cx, did, &["core", "option", "Option"]);
53     let _ = match_def_path(cx, did, &["core", "option", "Option", "Some"]);
54
55     let _ = match_trait_method(cx, expr, &["core", "convert", "AsRef"]);
56
57     let _ = is_expr_path_def_path(cx, expr, &["core", "option", "Option"]);
58     let _ = is_expr_path_def_path(cx, expr, &["core", "iter", "traits", "Iterator", "next"]);
59     let _ = is_expr_path_def_path(cx, expr, &["core", "option", "Option", "Some"]);
60 }
61
62 fn main() {}