Skip to content

Commit a783912

Browse files
committed
Update term for use in more places
Replace use of `ty()` on term and use it in more places. This will allow more flexibility in the future, but slightly worried it allows items which are consts which only accept types.
1 parent 9fb0bff commit a783912

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

clippy_lints/src/methods/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -2141,12 +2141,16 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
21412141
// one of the associated types must be Self
21422142
for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) {
21432143
if let ty::PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() {
2144+
let assoc_ty = match projection_predicate.term {
2145+
ty::Term::Ty(ty) => ty,
2146+
ty::Term::Const(c) => c.ty,
2147+
};
21442148
// walk the associated type and check for Self
21452149
if let Some(self_adt) = self_ty.ty_adt_def() {
2146-
if contains_adt_constructor(projection_predicate.term.ty(), self_adt) {
2150+
if contains_adt_constructor(assoc_ty, self_adt) {
21472151
return;
21482152
}
2149-
} else if contains_ty(projection_predicate.term.ty(), self_ty) {
2153+
} else if contains_ty(assoc_ty, self_ty) {
21502154
return;
21512155
}
21522156
}

clippy_lints/src/methods/unnecessary_to_owned.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,10 @@ fn check_other_call_arg<'tcx>(
243243
if if trait_predicate.def_id() == deref_trait_id {
244244
if let [projection_predicate] = projection_predicates[..] {
245245
let normalized_ty =
246-
cx.tcx.subst_and_normalize_erasing_regions(call_substs, cx.param_env, projection_predicate.term.ty());
246+
cx.tcx.subst_and_normalize_erasing_regions(call_substs, cx.param_env, projection_predicate.term);
247247
implements_trait(cx, receiver_ty, deref_trait_id, &[])
248-
&& get_associated_type(cx, receiver_ty, deref_trait_id, "Target") == Some(normalized_ty)
248+
&& get_associated_type(cx, receiver_ty, deref_trait_id,
249+
"Target").map_or(false, |ty| ty::Term::Ty(ty) == normalized_ty)
249250
} else {
250251
false
251252
}

clippy_lints/src/unit_return_expecting_ord.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Ve
9898
if trait_pred.self_ty() == inp;
9999
if let Some(return_ty_pred) = get_projection_pred(cx, generics, *trait_pred);
100100
then {
101-
if ord_preds.iter().any(|ord| ord.self_ty() == return_ty_pred.term.ty()) {
101+
if ord_preds.iter().any(|ord| Some(ord.self_ty()) ==
102+
return_ty_pred.term.ty()) {
102103
args_to_check.push((i, "Ord".to_string()));
103-
} else if partial_ord_preds.iter().any(|pord| pord.self_ty() == return_ty_pred.term.ty()) {
104+
} else if partial_ord_preds.iter().any(|pord| pord.self_ty() == return_ty_pred.term.ty().unwrap()) {
104105
args_to_check.push((i, "PartialOrd".to_string()));
105106
}
106107
}

0 commit comments

Comments
 (0)