1
1
use clippy_utils:: diagnostics:: span_lint_and_sugg;
2
2
use clippy_utils:: path_res;
3
3
use clippy_utils:: source:: snippet;
4
- use clippy_utils:: ty:: implements_trait;
5
4
use rustc_errors:: Applicability ;
6
5
use rustc_hir:: def:: { CtorKind , DefKind , Res } ;
7
- use rustc_hir:: def_id:: DefId ;
8
6
use rustc_hir:: { Expr , ExprKind , QPath } ;
9
7
use rustc_lint:: { LateContext , LateLintPass } ;
10
- use rustc_middle:: ty:: { self , GenericPredicates , List , ParamTy , Ty , TyCtxt } ;
11
- use rustc_session:: impl_lint_pass ;
8
+ use rustc_middle:: ty:: { self , GenericPredicates , ParamTy , Ty } ;
9
+ use rustc_session:: declare_lint_pass ;
12
10
use rustc_span:: sym;
13
11
use std:: iter;
14
12
@@ -37,22 +35,7 @@ declare_clippy_lint! {
37
35
being enclosed in `Path::new` when the argument implements the trait"
38
36
}
39
37
40
- impl_lint_pass ! ( NeedlessPathNew <' _> => [ NEEDLESS_PATH_NEW ] ) ;
41
-
42
- pub struct NeedlessPathNew < ' tcx > {
43
- path_ty : Option < Ty < ' tcx > > ,
44
- asref_def_id : Option < DefId > ,
45
- }
46
-
47
- impl < ' tcx > NeedlessPathNew < ' tcx > {
48
- pub fn new ( tcx : TyCtxt < ' tcx > ) -> Self {
49
- Self {
50
- path_ty : ( tcx. get_diagnostic_item ( sym:: Path ) )
51
- . map ( |path_def_id| Ty :: new_adt ( tcx, tcx. adt_def ( path_def_id) , List :: empty ( ) ) ) ,
52
- asref_def_id : tcx. get_diagnostic_item ( sym:: AsRef ) ,
53
- }
54
- }
55
- }
38
+ declare_lint_pass ! ( NeedlessPathNew => [ NEEDLESS_PATH_NEW ] ) ;
56
39
57
40
fn is_used_anywhere_else < ' a > ( param_ty : & ' _ ParamTy , mut other_sig_tys : impl Iterator < Item = Ty < ' a > > ) -> bool {
58
41
other_sig_tys. any ( |sig_ty| {
@@ -69,18 +52,10 @@ fn is_used_anywhere_else<'a>(param_ty: &'_ ParamTy, mut other_sig_tys: impl Iter
69
52
} )
70
53
}
71
54
72
- impl < ' tcx > LateLintPass < ' tcx > for NeedlessPathNew < ' tcx > {
55
+ impl < ' tcx > LateLintPass < ' tcx > for NeedlessPathNew {
73
56
fn check_expr ( & mut self , cx : & LateContext < ' tcx > , e : & ' tcx Expr < ' tcx > ) {
74
57
let tcx = cx. tcx ;
75
58
76
- let Some ( path_ty) = self . path_ty else {
77
- return ;
78
- } ;
79
-
80
- let Some ( asref_def_id) = self . asref_def_id else {
81
- return ;
82
- } ;
83
-
84
59
let ( fn_did, args) = match e. kind {
85
60
ExprKind :: Call ( callee, args)
86
61
if let Res :: Def ( DefKind :: Fn | DefKind :: AssocFn | DefKind :: Ctor ( _, CtorKind :: Fn ) , did) =
@@ -112,8 +87,6 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPathNew<'tcx> {
112
87
}
113
88
} ;
114
89
115
- let implements_asref_path = |arg| implements_trait ( cx, arg, asref_def_id, & [ path_ty. into ( ) ] ) ;
116
-
117
90
let has_required_preds = |_param_ty : & ParamTy , _preds : GenericPredicates < ' _ > | -> bool { true } ;
118
91
119
92
// as far as I understand, `ExprKind::MethodCall` doesn't include the receiver in `args`,
0 commit comments