Skip to content

Commit 3c0d183

Browse files
committed
rm implements_asref_path and everything required for it
since we're (will be.. eventually) checking all predicates now, not just `AsRef<Path>`
1 parent a5553af commit 3c0d183

File tree

2 files changed

+5
-32
lines changed

2 files changed

+5
-32
lines changed

clippy_lints/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,6 @@ pub fn register_lint_passes(store: &mut rustc_lint::LintStore, conf: &'static Co
831831
store.register_late_pass(|_| Box::new(cloned_ref_to_slice_refs::ClonedRefToSliceRefs::new(conf)));
832832
store.register_late_pass(|_| Box::new(infallible_try_from::InfallibleTryFrom));
833833
store.register_late_pass(|_| Box::new(coerce_container_to_any::CoerceContainerToAny));
834-
store.register_late_pass(|tcx| Box::new(needless_path_new::NeedlessPathNew::new(tcx)));
834+
store.register_late_pass(|_| Box::new(needless_path_new::NeedlessPathNew));
835835
// add lints here, do not remove this comment, it's used in `new_lint`
836836
}

clippy_lints/src/needless_path_new.rs

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::path_res;
33
use clippy_utils::source::snippet;
4-
use clippy_utils::ty::implements_trait;
54
use rustc_errors::Applicability;
65
use rustc_hir::def::{CtorKind, DefKind, Res};
7-
use rustc_hir::def_id::DefId;
86
use rustc_hir::{Expr, ExprKind, QPath};
97
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;
1210
use rustc_span::sym;
1311
use 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

5740
fn 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

Comments
 (0)