Skip to content

Commit

Permalink
Rollup merge of rust-lang#87770 - BoxyUwU:cec-drop-impl, r=lcnr
Browse files Browse the repository at this point in the history
permit drop impls with generic constants in where clauses

Fixes rust-lang#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`````
  • Loading branch information
JohnTitor authored Aug 6, 2021
2 parents f91d8d1 + fa46715 commit 5f37944
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
13 changes: 10 additions & 3 deletions compiler/rustc_typeck/src/check/dropck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(

// This closure is a more robust way to check `Predicate` equality
// than simple `==` checks (which were the previous implementation).
// It relies on `ty::relate` for `TraitPredicate` and `ProjectionPredicate`
// (which implement the Relate trait), while delegating on simple equality
// for the other `Predicate`.
// It relies on `ty::relate` for `TraitPredicate`, `ProjectionPredicate`,
// `ConstEvaluatable` and `TypeOutlives` (which implement the Relate trait),
// while delegating on simple equality for the other `Predicate`.
// This implementation solves (Issue #59497) and (Issue #58311).
// It is unclear to me at the moment whether the approach based on `relate`
// could be extended easily also to the other `Predicate`.
Expand All @@ -235,6 +235,13 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
(ty::PredicateKind::Projection(a), ty::PredicateKind::Projection(b)) => {
relator.relate(predicate.rebind(a), p.rebind(b)).is_ok()
}
(
ty::PredicateKind::ConstEvaluatable(def_a, substs_a),
ty::PredicateKind::ConstEvaluatable(def_b, substs_b),
) => tcx.try_unify_abstract_consts(((def_a, substs_a), (def_b, substs_b))),
(ty::PredicateKind::TypeOutlives(a), ty::PredicateKind::TypeOutlives(b)) => {
relator.relate(predicate.rebind(a.0), p.rebind(b.0)).is_ok()
}
_ => predicate == p,
}
};
Expand Down
16 changes: 16 additions & 0 deletions src/test/ui/const-generics/const_evaluatable_checked/drop_impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//check-pass
#![feature(const_generics, const_evaluatable_checked)]
#![allow(incomplete_features)]

struct Foo<const N: usize>
where
[(); N + 1]: ;

impl<const N: usize> Drop for Foo<N>
where
[(); N + 1]: ,
{
fn drop(&mut self) {}
}

fn main() {}

0 comments on commit 5f37944

Please sign in to comment.