From b1d14ef08fefa81a8f4b459fbfb11dafe9005d0a Mon Sep 17 00:00:00 2001 From: Ellen Date: Wed, 4 Aug 2021 18:30:41 +0100 Subject: [PATCH 1/2] dropck --- compiler/rustc_typeck/src/check/dropck.rs | 19 +++++++++++++++---- .../const_evaluatable_checked/drop_impl.rs | 16 ++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/const-generics/const_evaluatable_checked/drop_impl.rs diff --git a/compiler/rustc_typeck/src/check/dropck.rs b/compiler/rustc_typeck/src/check/dropck.rs index 01276495c185a..f0b8556b7a8af 100644 --- a/compiler/rustc_typeck/src/check/dropck.rs +++ b/compiler/rustc_typeck/src/check/dropck.rs @@ -217,10 +217,10 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>( // repeated `.iter().any(..)` calls. // 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`. + // than simple `==` checks (which were the previous implementation). It relies on + // `ty::relate` for `TraitPredicate`, `ProjectionPredicate`, `ConstEvaluatable` + // `TypeOutlives` and `TypeWellFormedFromEnv` (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`. @@ -235,6 +235,17 @@ 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() + } + ( + ty::PredicateKind::TypeWellFormedFromEnv(a), + ty::PredicateKind::TypeWellFormedFromEnv(b), + ) => relator.relate(predicate.rebind(a), p.rebind(b)).is_ok(), _ => predicate == p, } }; diff --git a/src/test/ui/const-generics/const_evaluatable_checked/drop_impl.rs b/src/test/ui/const-generics/const_evaluatable_checked/drop_impl.rs new file mode 100644 index 0000000000000..41fb5d70afd6e --- /dev/null +++ b/src/test/ui/const-generics/const_evaluatable_checked/drop_impl.rs @@ -0,0 +1,16 @@ +//check-pass +#![feature(const_generics, const_evaluatable_checked)] +#![allow(incomplete_features)] + +struct Foo +where + [(); N + 1]: ; + +impl Drop for Foo +where + [(); N + 1]: , +{ + fn drop(&mut self) {} +} + +fn main() {} From fa4671500273991967b293dd611e645512608d98 Mon Sep 17 00:00:00 2001 From: Ellen Date: Thu, 5 Aug 2021 03:09:01 +0100 Subject: [PATCH 2/2] remove tywf relation --- compiler/rustc_typeck/src/check/dropck.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_typeck/src/check/dropck.rs b/compiler/rustc_typeck/src/check/dropck.rs index f0b8556b7a8af..17f5020300d40 100644 --- a/compiler/rustc_typeck/src/check/dropck.rs +++ b/compiler/rustc_typeck/src/check/dropck.rs @@ -217,9 +217,9 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>( // repeated `.iter().any(..)` calls. // 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`, `ProjectionPredicate`, `ConstEvaluatable` - // `TypeOutlives` and `TypeWellFormedFromEnv` (which implement the Relate trait), + // than simple `==` checks (which were the previous implementation). + // 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` @@ -242,10 +242,6 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>( (ty::PredicateKind::TypeOutlives(a), ty::PredicateKind::TypeOutlives(b)) => { relator.relate(predicate.rebind(a.0), p.rebind(b.0)).is_ok() } - ( - ty::PredicateKind::TypeWellFormedFromEnv(a), - ty::PredicateKind::TypeWellFormedFromEnv(b), - ) => relator.relate(predicate.rebind(a), p.rebind(b)).is_ok(), _ => predicate == p, } };