]> git.lizzy.rs Git - rust.git/blob - tests/ui/match_type_on_diag_item.rs
Auto merge of #6336 - giraffate:sync-from-rust, r=flip1995
[rust.git] / tests / ui / match_type_on_diag_item.rs
1 #![deny(clippy::internal)]
2 #![feature(rustc_private)]
3
4 extern crate rustc_hir;
5 extern crate rustc_lint;
6 extern crate rustc_middle;
7 #[macro_use]
8 extern crate rustc_session;
9 use rustc_hir::Expr;
10 use rustc_lint::{LateContext, LateLintPass};
11 use rustc_middle::ty::Ty;
12
13 mod paths {
14     pub const VEC: [&str; 3] = ["alloc", "vec", "Vec"];
15 }
16
17 mod utils {
18     use super::*;
19
20     pub fn match_type(_cx: &LateContext<'_>, _ty: Ty<'_>, _path: &[&str]) -> bool {
21         false
22     }
23 }
24
25 use utils::match_type;
26
27 declare_lint! {
28     pub TEST_LINT,
29     Warn,
30     ""
31 }
32
33 declare_lint_pass!(Pass => [TEST_LINT]);
34
35 static OPTION: [&str; 3] = ["core", "option", "Option"];
36
37 impl<'tcx> LateLintPass<'tcx> for Pass {
38     fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr) {
39         let ty = cx.typeck_results().expr_ty(expr);
40
41         let _ = match_type(cx, ty, &paths::VEC);
42         let _ = match_type(cx, ty, &OPTION);
43         let _ = match_type(cx, ty, &["core", "result", "Result"]);
44
45         let rc_path = &["alloc", "rc", "Rc"];
46         let _ = utils::match_type(cx, ty, rc_path);
47     }
48 }
49
50 fn main() {}