Skip to content

Commit 945d5e4

Browse files
committed
has_required_preds: make the Clause::as_trait_clause more explicit
should I keep this?
1 parent 0e88347 commit 945d5e4

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

clippy_lints/src/needless_path_new.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hir::{Expr, ExprKind, QPath};
77
use rustc_infer::infer::InferCtxt;
88
use rustc_infer::traits::{Obligation, ObligationCause};
99
use rustc_lint::{LateContext, LateLintPass};
10-
use rustc_middle::ty::{self, GenericPredicates, ParamTy, PredicatePolarity, Ty};
10+
use rustc_middle::ty::{self, ClauseKind, GenericPredicates, ParamTy, PredicatePolarity, Ty};
1111
use rustc_session::declare_lint_pass;
1212
use rustc_span::sym;
1313
use rustc_trait_selection::infer::TyCtxtInferExt;
@@ -134,8 +134,31 @@ fn has_required_preds<'tcx>(
134134
let has_required_preds = preds
135135
.predicates
136136
.iter()
137-
.filter_map(|(clause, _)| clause.as_trait_clause())
138-
.map(|pred| pred.skip_binder())
137+
.filter_map(|(clause, _)| {
138+
let clause = clause.kind();
139+
#[expect(clippy::match_same_arms, reason = "branches have different reasons to be `None`")]
140+
match clause.skip_binder() {
141+
// This is what we analyze
142+
// NOTE: repeats the contents of `Clause::as_trait_clause`,
143+
// except we don't `Binder::rebind` as we don't care about the binder
144+
ClauseKind::Trait(trait_clause) => Some(trait_clause),
145+
146+
// Trivially holds for `P`: `Path::new` has signature `&S -> &Path`, so any "outlives" that holds for
147+
// `P` does so for `S` as well
148+
ClauseKind::TypeOutlives(_) | ClauseKind::RegionOutlives(_) => None,
149+
150+
// Irrelevant to us: neither `AsRef` nor `Sized` have associated types
151+
ClauseKind::Projection(_) => None,
152+
153+
// Irrelevant: we don't have anything to do with consts
154+
ClauseKind::ConstArgHasType(..) | ClauseKind::ConstEvaluatable(_) | ClauseKind::HostEffect(_) => None,
155+
156+
// Irrelevant?: we don't deal with unstable impls
157+
ClauseKind::UnstableFeature(_) => None,
158+
159+
ClauseKind::WellFormed(_) => None,
160+
}
161+
})
139162
.filter(|pred| {
140163
// dbg!(pred.self_ty(), param_ty);
141164
pred.self_ty() == param_ty

0 commit comments

Comments
 (0)