Skip to content

Commit 5a25c0e

Browse files
committed
Auto merge of rust-lang#87648 - JulianKnodt:const_eq_constrain, r=oli-obk
allow eq constraints on associated constants Updates rust-lang#70256 (cc `@varkor,` `@Centril)`
2 parents 7a2cabb + 109583e commit 5a25c0e

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

Diff for: clippy_lints/src/manual_async_fn.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use if_chain::if_chain;
66
use rustc_errors::Applicability;
77
use rustc_hir::intravisit::FnKind;
88
use rustc_hir::{
9-
AsyncGeneratorKind, Block, Body, Expr, ExprKind, FnDecl, FnRetTy, GeneratorKind, GenericArg, GenericBound, HirId,
9+
Term, AsyncGeneratorKind, Block, Body, Expr, ExprKind, FnDecl, FnRetTy, GeneratorKind, GenericArg, GenericBound, HirId,
1010
IsAsync, ItemKind, LifetimeName, TraitRef, Ty, TyKind, TypeBindingKind,
1111
};
1212
use rustc_lint::{LateContext, LateLintPass};
@@ -140,7 +140,7 @@ fn future_output_ty<'tcx>(trait_ref: &'tcx TraitRef<'tcx>) -> Option<&'tcx Ty<'t
140140
if args.bindings.len() == 1;
141141
let binding = &args.bindings[0];
142142
if binding.ident.name == sym::Output;
143-
if let TypeBindingKind::Equality{ty: output} = binding.kind;
143+
if let TypeBindingKind::Equality{term: Term::Ty(output)} = binding.kind;
144144
then {
145145
return Some(output)
146146
}

Diff for: clippy_lints/src/methods/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -2178,12 +2178,16 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
21782178
// one of the associated types must be Self
21792179
for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) {
21802180
if let ty::PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() {
2181+
let assoc_ty = match projection_predicate.term {
2182+
ty::Term::Ty(ty) => ty,
2183+
ty::Term::Const(_c) => continue,
2184+
};
21812185
// walk the associated type and check for Self
21822186
if let Some(self_adt) = self_ty.ty_adt_def() {
2183-
if contains_adt_constructor(projection_predicate.ty, self_adt) {
2187+
if contains_adt_constructor(assoc_ty, self_adt) {
21842188
return;
21852189
}
2186-
} else if contains_ty(projection_predicate.ty, self_ty) {
2190+
} else if contains_ty(assoc_ty, self_ty) {
21872191
return;
21882192
}
21892193
}

Diff for: 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.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
}

Diff for: 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.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.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
}

Diff for: clippy_utils/src/ast_utils.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -645,11 +645,19 @@ pub fn eq_generic_bound(l: &GenericBound, r: &GenericBound) -> bool {
645645
}
646646
}
647647

648-
pub fn eq_assoc_constraint(l: &AssocTyConstraint, r: &AssocTyConstraint) -> bool {
649-
use AssocTyConstraintKind::*;
648+
fn eq_term(l: &Term, r: &Term) -> bool {
649+
match (l, r) {
650+
(Term::Ty(l), Term::Ty(r)) => eq_ty(l,r),
651+
(Term::Const(l), Term::Const(r)) => eq_anon_const(l,r),
652+
_ => false,
653+
}
654+
}
655+
656+
pub fn eq_assoc_constraint(l: &AssocConstraint, r: &AssocConstraint) -> bool {
657+
use AssocConstraintKind::*;
650658
eq_id(l.ident, r.ident)
651659
&& match (&l.kind, &r.kind) {
652-
(Equality { ty: l }, Equality { ty: r }) => eq_ty(l, r),
660+
(Equality { term: l }, Equality { term: r }) => eq_term(l, r),
653661
(Bound { bounds: l }, Bound { bounds: r }) => over(l, r, eq_generic_bound),
654662
_ => false,
655663
}

0 commit comments

Comments
 (0)