11use clippy_utils:: diagnostics:: span_lint_and_sugg;
22use clippy_utils:: path_res;
33use clippy_utils:: source:: snippet;
4- use clippy_utils:: ty:: implements_trait;
54use rustc_errors:: Applicability ;
65use rustc_hir:: def:: { CtorKind , DefKind , Res } ;
7- use rustc_hir:: def_id:: DefId ;
86use rustc_hir:: { Expr , ExprKind , QPath } ;
97use 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 ;
1210use rustc_span:: sym;
1311use std:: iter;
1412
@@ -37,22 +35,7 @@ declare_clippy_lint! {
3735 being enclosed in `Path::new` when the argument implements the trait"
3836}
3937
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 ] ) ;
5639
5740fn is_used_anywhere_else < ' a > ( param_ty : & ' _ ParamTy , mut other_sig_tys : impl Iterator < Item = Ty < ' a > > ) -> bool {
5841 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
6952 } )
7053}
7154
72- impl < ' tcx > LateLintPass < ' tcx > for NeedlessPathNew < ' tcx > {
55+ impl < ' tcx > LateLintPass < ' tcx > for NeedlessPathNew {
7356 fn check_expr ( & mut self , cx : & LateContext < ' tcx > , e : & ' tcx Expr < ' tcx > ) {
7457 let tcx = cx. tcx ;
7558
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-
8459 let ( fn_did, args) = match e. kind {
8560 ExprKind :: Call ( callee, args)
8661 if let Res :: Def ( DefKind :: Fn | DefKind :: AssocFn | DefKind :: Ctor ( _, CtorKind :: Fn ) , did) =
@@ -112,8 +87,6 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPathNew<'tcx> {
11287 }
11388 } ;
11489
115- let implements_asref_path = |arg| implements_trait ( cx, arg, asref_def_id, & [ path_ty. into ( ) ] ) ;
116-
11790 let has_required_preds = |_param_ty : & ParamTy , _preds : GenericPredicates < ' _ > | -> bool { true } ;
11891
11992 // as far as I understand, `ExprKind::MethodCall` doesn't include the receiver in `args`,
0 commit comments