Skip to content

Commit 8bad350

Browse files
authored
Rollup merge of #87770 - BoxyUwU:cec-drop-impl, r=lcnr
permit drop impls with generic constants in where clauses Fixes #79248 `==` is not sufficient to check for equality between unevaluated consts which causes the above issue because the const in `[(); N - 1]:` on the impl and the const in `[(); N - 1]:` on the struct def are not seen as equal. Any predicate that can contain an unevaluated const cant use `==` here as it will cause us to incorrectly emit an error. I dont know much about chalk but it seems like we ought to be relating the `TypeWellFormedFromEnv` instead of `==` as it contains a `Ty` so I added that too... r? ``````@lcnr``````
2 parents 41076a8 + fa46715 commit 8bad350

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

compiler/rustc_typeck/src/check/dropck.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
218218

219219
// This closure is a more robust way to check `Predicate` equality
220220
// than simple `==` checks (which were the previous implementation).
221-
// It relies on `ty::relate` for `TraitPredicate` and `ProjectionPredicate`
222-
// (which implement the Relate trait), while delegating on simple equality
223-
// for the other `Predicate`.
221+
// It relies on `ty::relate` for `TraitPredicate`, `ProjectionPredicate`,
222+
// `ConstEvaluatable` and `TypeOutlives` (which implement the Relate trait),
223+
// while delegating on simple equality for the other `Predicate`.
224224
// This implementation solves (Issue #59497) and (Issue #58311).
225225
// It is unclear to me at the moment whether the approach based on `relate`
226226
// could be extended easily also to the other `Predicate`.
@@ -235,6 +235,13 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
235235
(ty::PredicateKind::Projection(a), ty::PredicateKind::Projection(b)) => {
236236
relator.relate(predicate.rebind(a), p.rebind(b)).is_ok()
237237
}
238+
(
239+
ty::PredicateKind::ConstEvaluatable(def_a, substs_a),
240+
ty::PredicateKind::ConstEvaluatable(def_b, substs_b),
241+
) => tcx.try_unify_abstract_consts(((def_a, substs_a), (def_b, substs_b))),
242+
(ty::PredicateKind::TypeOutlives(a), ty::PredicateKind::TypeOutlives(b)) => {
243+
relator.relate(predicate.rebind(a.0), p.rebind(b.0)).is_ok()
244+
}
238245
_ => predicate == p,
239246
}
240247
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//check-pass
2+
#![feature(const_generics, const_evaluatable_checked)]
3+
#![allow(incomplete_features)]
4+
5+
struct Foo<const N: usize>
6+
where
7+
[(); N + 1]: ;
8+
9+
impl<const N: usize> Drop for Foo<N>
10+
where
11+
[(); N + 1]: ,
12+
{
13+
fn drop(&mut self) {}
14+
}
15+
16+
fn main() {}

0 commit comments

Comments
 (0)