about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorBastian Kauschke <bastian_kauschke@hotmail.de>2020-06-20 00:21:59 +0200
committerBastian Kauschke <bastian_kauschke@hotmail.de>2020-07-27 21:06:36 +0200
commitc6c0d17c8d6be89c6ef00de14fbafaf76d276d55 (patch)
tree3f6112c6764192c9e44740c179d3f3d559617fdb /src
parentbbd581c583a7168359bf94beaa111d6ad3316837 (diff)
downloadrust-c6c0d17c8d6be89c6ef00de14fbafaf76d276d55.tar.gz
rust-c6c0d17c8d6be89c6ef00de14fbafaf76d276d55.zip
review
Diffstat (limited to 'src')
-rw-r--r--src/librustc_infer/traits/util.rs42
-rw-r--r--src/librustc_middle/ty/mod.rs16
-rw-r--r--src/librustc_mir/transform/qualify_min_const_fn.rs1
-rw-r--r--src/librustc_trait_selection/traits/auto_trait.rs1
-rw-r--r--src/librustc_trait_selection/traits/error_reporting/mod.rs24
-rw-r--r--src/librustc_trait_selection/traits/object_safety.rs2
-rw-r--r--src/librustc_trait_selection/traits/project.rs2
-rw-r--r--src/librustc_trait_selection/traits/select/mod.rs1
-rw-r--r--src/librustc_traits/chalk/lowering.rs18
-rw-r--r--src/librustc_traits/normalize_erasing_regions.rs1
-rw-r--r--src/librustc_typeck/astconv.rs1
-rw-r--r--src/librustc_typeck/check/method/suggest.rs1
-rw-r--r--src/librustc_typeck/check/mod.rs3
-rw-r--r--src/librustc_typeck/outlives/explicit.rs7
14 files changed, 45 insertions, 75 deletions
diff --git a/src/librustc_infer/traits/util.rs b/src/librustc_infer/traits/util.rs
index 6aeb225a6e9..a1944781df2 100644
--- a/src/librustc_infer/traits/util.rs
+++ b/src/librustc_infer/traits/util.rs
@@ -11,36 +11,22 @@ pub fn anonymize_predicate<'tcx>(
     pred: ty::Predicate<'tcx>,
 ) -> ty::Predicate<'tcx> {
     let kind = pred.kind();
-    let new = match kind {
+    match kind {
         ty::PredicateKind::ForAll(binder) => {
-            ty::PredicateKind::ForAll(tcx.anonymize_late_bound_regions(binder))
+            let new = ty::PredicateKind::ForAll(tcx.anonymize_late_bound_regions(binder));
+            if new != *kind { new.to_predicate(tcx) } else { pred }
         }
-        &ty::PredicateKind::Trait(data, constness) => ty::PredicateKind::Trait(data, constness),
-
-        &ty::PredicateKind::RegionOutlives(data) => ty::PredicateKind::RegionOutlives(data),
-
-        &ty::PredicateKind::TypeOutlives(data) => ty::PredicateKind::TypeOutlives(data),
-
-        &ty::PredicateKind::Projection(data) => ty::PredicateKind::Projection(data),
-
-        &ty::PredicateKind::WellFormed(data) => ty::PredicateKind::WellFormed(data),
-
-        &ty::PredicateKind::ObjectSafe(data) => ty::PredicateKind::ObjectSafe(data),
-
-        &ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
-            ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind)
-        }
-
-        &ty::PredicateKind::Subtype(data) => ty::PredicateKind::Subtype(data),
-
-        &ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
-            ty::PredicateKind::ConstEvaluatable(def_id, substs)
-        }
-
-        &ty::PredicateKind::ConstEquate(c1, c2) => ty::PredicateKind::ConstEquate(c1, c2),
-    };
-
-    if new != *kind { new.to_predicate(tcx) } else { pred }
+        ty::PredicateKind::Trait(_, _)
+        | ty::PredicateKind::RegionOutlives(_)
+        | ty::PredicateKind::TypeOutlives(_)
+        | ty::PredicateKind::Projection(_)
+        | ty::PredicateKind::WellFormed(_)
+        | ty::PredicateKind::ObjectSafe(_)
+        | ty::PredicateKind::ClosureKind(_, _, _)
+        | ty::PredicateKind::Subtype(_)
+        | ty::PredicateKind::ConstEvaluatable(_, _)
+        | ty::PredicateKind::ConstEquate(_, _) => pred,
+    }
 }
 
 struct PredicateSet<'tcx> {
diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs
index 3b154bf1518..5b5996e84ee 100644
--- a/src/librustc_middle/ty/mod.rs
+++ b/src/librustc_middle/ty/mod.rs
@@ -1225,20 +1225,10 @@ impl<'tcx> Predicate<'tcx> {
         // substitution code expects equal binding levels in the values
         // from the substitution and the value being substituted into, and
         // this trick achieves that).
-
         let substs = trait_ref.skip_binder().substs;
-        let kind = match self.kind() {
-            PredicateKind::ForAll(binder) => binder.skip_binder().kind(),
-            kind => kind,
-        };
-
-        let new = kind.subst(tcx, substs);
-
-        if new != *kind {
-            new.to_predicate(tcx).potentially_qualified(tcx, PredicateKind::ForAll)
-        } else {
-            self
-        }
+        let pred = *self.ignore_qualifiers(tcx).skip_binder();
+        let new = pred.subst(tcx, substs);
+        if new != pred { new.potentially_qualified(tcx, PredicateKind::ForAll) } else { self }
     }
 }
 
diff --git a/src/librustc_mir/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs
index 0d4d1026381..f4bfc7d4b98 100644
--- a/src/librustc_mir/transform/qualify_min_const_fn.rs
+++ b/src/librustc_mir/transform/qualify_min_const_fn.rs
@@ -24,7 +24,6 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -
     loop {
         let predicates = tcx.predicates_of(current);
         for (predicate, _) in predicates.predicates {
-            // TODO: forall
             match predicate.ignore_qualifiers(tcx).skip_binder().kind() {
                 ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", predicate),
                 ty::PredicateKind::RegionOutlives(_)
diff --git a/src/librustc_trait_selection/traits/auto_trait.rs b/src/librustc_trait_selection/traits/auto_trait.rs
index 74a4939ae10..aebe96f7ddc 100644
--- a/src/librustc_trait_selection/traits/auto_trait.rs
+++ b/src/librustc_trait_selection/traits/auto_trait.rs
@@ -639,7 +639,6 @@ impl AutoTraitFinder<'tcx> {
             // We check this by calling is_of_param on the relevant types
             // from the various possible predicates
 
-            // TODO: forall
             match predicate.ignore_qualifiers(self.tcx).skip_binder().kind() {
                 &ty::PredicateKind::Trait(p, _) => {
                     if self.is_param_no_infer(p.trait_ref.substs)
diff --git a/src/librustc_trait_selection/traits/error_reporting/mod.rs b/src/librustc_trait_selection/traits/error_reporting/mod.rs
index 8a2915bb30c..75fe9b7701e 100644
--- a/src/librustc_trait_selection/traits/error_reporting/mod.rs
+++ b/src/librustc_trait_selection/traits/error_reporting/mod.rs
@@ -256,7 +256,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
                     return;
                 }
 
-                // TODO: forall
                 match obligation.predicate.ignore_qualifiers(tcx).skip_binder().kind() {
                     ty::PredicateKind::ForAll(_) => {
                         bug!("unexpected predicate: {:?}", obligation.predicate)
@@ -1481,7 +1480,6 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
             return;
         }
 
-        // TODO: forall
         let mut err = match predicate.ignore_qualifiers(self.tcx).skip_binder().kind() {
             &ty::PredicateKind::Trait(data, _) => {
                 let trait_ref = ty::Binder::bind(data.trait_ref);
@@ -1583,8 +1581,6 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
             }
 
             ty::PredicateKind::WellFormed(arg) => {
-                // TODO: forall
-
                 // Same hacky approach as above to avoid deluging user
                 // with error messages.
                 if arg.references_error() || self.tcx.sess.has_errors() {
@@ -1604,7 +1600,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
                 }
             }
 
-            ty::PredicateKind::Subtype(ref data) => {
+            ty::PredicateKind::Subtype(data) => {
                 if data.references_error() || self.tcx.sess.has_errors() {
                     // no need to overload user in such cases
                     return;
@@ -1737,14 +1733,16 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
         err: &mut DiagnosticBuilder<'tcx>,
         obligation: &PredicateObligation<'tcx>,
     ) {
-        let (pred, item_def_id, span) =
-            match (obligation.predicate.ignore_qualifiers(self.tcx).skip_binder().kind(), obligation.cause.code.peel_derives()) {
-                (
-                    ty::PredicateKind::Trait(pred, _),
-                    &ObligationCauseCode::BindingObligation(item_def_id, span),
-                ) => (pred, item_def_id, span),
-                _ => return,
-            };
+        let (pred, item_def_id, span) = match (
+            obligation.predicate.ignore_qualifiers(self.tcx).skip_binder().kind(),
+            obligation.cause.code.peel_derives(),
+        ) {
+            (
+                ty::PredicateKind::Trait(pred, _),
+                &ObligationCauseCode::BindingObligation(item_def_id, span),
+            ) => (pred, item_def_id, span),
+            _ => return,
+        };
 
         let node = match (
             self.tcx.hir().get_if_local(item_def_id),
diff --git a/src/librustc_trait_selection/traits/object_safety.rs b/src/librustc_trait_selection/traits/object_safety.rs
index cb03751bb78..5ad43084e7f 100644
--- a/src/librustc_trait_selection/traits/object_safety.rs
+++ b/src/librustc_trait_selection/traits/object_safety.rs
@@ -245,7 +245,6 @@ fn predicates_reference_self(
         .iter()
         .map(|(predicate, sp)| (predicate.subst_supertrait(tcx, &trait_ref), sp))
         .filter_map(|(predicate, &sp)| {
-            // TODO: forall
             match predicate.ignore_qualifiers(tcx).skip_binder().kind() {
                 ty::PredicateKind::Trait(ref data, _) => {
                     // In the case of a trait predicate, we can skip the "self" type.
@@ -300,7 +299,6 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
     let predicates = tcx.predicates_of(def_id);
     let predicates = predicates.instantiate_identity(tcx).predicates;
     elaborate_predicates(tcx, predicates.into_iter()).any(|obligation| {
-        // TODO: forall
         match obligation.predicate.ignore_qualifiers(tcx).skip_binder().kind() {
             ty::PredicateKind::Trait(ref trait_pred, _) => {
                 trait_pred.def_id() == sized_def_id && trait_pred.self_ty().is_param(0)
diff --git a/src/librustc_trait_selection/traits/project.rs b/src/librustc_trait_selection/traits/project.rs
index 30c86055e40..c2ae26d9d25 100644
--- a/src/librustc_trait_selection/traits/project.rs
+++ b/src/librustc_trait_selection/traits/project.rs
@@ -933,7 +933,6 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
     let infcx = selcx.infcx();
     for predicate in env_predicates {
         debug!("assemble_candidates_from_predicates: predicate={:?}", predicate);
-        // TODO: forall
         if let &ty::PredicateKind::Projection(data) =
             predicate.ignore_qualifiers(infcx.tcx).skip_binder().kind()
         {
@@ -1228,7 +1227,6 @@ fn confirm_object_candidate<'cx, 'tcx>(
         // select only those projections that are actually projecting an
         // item with the correct name
 
-        // TODO: forall
         let env_predicates = env_predicates.filter_map(|o| {
             match o.predicate.ignore_qualifiers(selcx.tcx()).skip_binder().kind() {
                 &ty::PredicateKind::Projection(data)
diff --git a/src/librustc_trait_selection/traits/select/mod.rs b/src/librustc_trait_selection/traits/select/mod.rs
index 56833036055..1bc53f0c5c5 100644
--- a/src/librustc_trait_selection/traits/select/mod.rs
+++ b/src/librustc_trait_selection/traits/select/mod.rs
@@ -408,7 +408,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
             None => self.check_recursion_limit(&obligation, &obligation)?,
         }
 
-        // TODO: forall
         match obligation.predicate.ignore_qualifiers(self.tcx()).skip_binder().kind() {
             ty::PredicateKind::ForAll(_) => {
                 bug!("unexpected predicate: {:?}", obligation.predicate)
diff --git a/src/librustc_traits/chalk/lowering.rs b/src/librustc_traits/chalk/lowering.rs
index 2abceb5fe2b..7154b3fb378 100644
--- a/src/librustc_traits/chalk/lowering.rs
+++ b/src/librustc_traits/chalk/lowering.rs
@@ -223,9 +223,21 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
                     // the environment.
                     ty::Placeholder(..) => chalk_ir::GoalData::All(chalk_ir::Goals::new(interner)),
 
-                    _ => chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::WellFormed(
-                        chalk_ir::WellFormed::Ty(ty.lower_into(interner)),
-                    )),
+                    _ => {
+                        let (ty, binders, _named_regions) =
+                            collect_bound_vars(interner, interner.tcx, &ty::Binder::bind(ty));
+
+                        chalk_ir::GoalData::Quantified(
+                            chalk_ir::QuantifierKind::ForAll,
+                            chalk_ir::Binders::new(
+                                binders,
+                                chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::WellFormed(
+                                    chalk_ir::WellFormed::Ty(ty.lower_into(interner)),
+                                ))
+                                .intern(interner),
+                            ),
+                        )
+                    }
                 },
                 // FIXME(chalk): handle well formed consts
                 GenericArgKind::Const(..) => {
diff --git a/src/librustc_traits/normalize_erasing_regions.rs b/src/librustc_traits/normalize_erasing_regions.rs
index 06a90d14511..8415690d41f 100644
--- a/src/librustc_traits/normalize_erasing_regions.rs
+++ b/src/librustc_traits/normalize_erasing_regions.rs
@@ -42,7 +42,6 @@ fn normalize_generic_arg_after_erasing_regions<'tcx>(
 }
 
 fn not_outlives_predicate(tcx: TyCtxt<'tcx>, p: &ty::Predicate<'tcx>) -> bool {
-    // TODO: forall
     match p.ignore_qualifiers(tcx).skip_binder().kind() {
         ty::PredicateKind::RegionOutlives(..) | ty::PredicateKind::TypeOutlives(..) => false,
         ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", p),
diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs
index ef7726e7705..c028597ccd2 100644
--- a/src/librustc_typeck/astconv.rs
+++ b/src/librustc_typeck/astconv.rs
@@ -1706,7 +1706,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
                     obligation.predicate
                 );
 
-                // TODO: forall
                 match obligation.predicate.ignore_qualifiers(tcx).skip_binder().kind() {
                     &ty::PredicateKind::Trait(pred, _) => {
                         let pred = ty::Binder::bind(pred);
diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs
index 34abbb9cef1..ddf539277b9 100644
--- a/src/librustc_typeck/check/method/suggest.rs
+++ b/src/librustc_typeck/check/method/suggest.rs
@@ -631,7 +631,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                         }
                     };
                     let mut format_pred = |pred: ty::Predicate<'tcx>| {
-                        // TODO: forall
                         match pred.ignore_qualifiers(tcx).skip_binder().kind() {
                             &ty::PredicateKind::Projection(pred) => {
                                 let pred = ty::Binder::bind(pred);
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index a98a7198435..201288022ed 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -2400,8 +2400,6 @@ fn bounds_from_generic_predicates<'tcx>(
     let mut projections = vec![];
     for (predicate, _) in predicates.predicates {
         debug!("predicate {:?}", predicate);
-        // TODO: forall (we could keep the current behavior and just skip binders eagerly,
-        // not sure if we want to though)
         match predicate.ignore_qualifiers(tcx).skip_binder().kind() {
             ty::PredicateKind::Trait(trait_predicate, _) => {
                 let entry = types.entry(trait_predicate.self_ty()).or_default();
@@ -3895,7 +3893,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
             .borrow()
             .pending_obligations()
             .into_iter()
-            // TODO: forall
             .filter_map(move |obligation| {
                 match obligation.predicate.ignore_qualifiers(self.tcx).skip_binder().kind() {
                     ty::PredicateKind::ForAll(_) => {
diff --git a/src/librustc_typeck/outlives/explicit.rs b/src/librustc_typeck/outlives/explicit.rs
index 1e946c73c50..d6551a5a387 100644
--- a/src/librustc_typeck/outlives/explicit.rs
+++ b/src/librustc_typeck/outlives/explicit.rs
@@ -29,12 +29,10 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> {
 
             // process predicates and convert to `RequiredPredicates` entry, see below
             for &(predicate, span) in predicates.predicates {
-                // TODO: forall
                 match predicate.ignore_qualifiers(tcx).skip_binder().kind() {
                     ty::PredicateKind::ForAll(_) => bug!("unepected predicate: {:?}", predicate),
 
-                    ty::PredicateKind::TypeOutlives(predicate) => {
-                        let OutlivesPredicate(ref ty, ref reg) = predicate;
+                    ty::PredicateKind::TypeOutlives(OutlivesPredicate(ref ty, ref reg)) => {
                         insert_outlives_predicate(
                             tcx,
                             (*ty).into(),
@@ -44,8 +42,7 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> {
                         )
                     }
 
-                    ty::PredicateKind::RegionOutlives(predicate) => {
-                        let OutlivesPredicate(ref reg1, ref reg2) = predicate;
+                    ty::PredicateKind::RegionOutlives(OutlivesPredicate(ref reg1, ref reg2)) => {
                         insert_outlives_predicate(
                             tcx,
                             (*reg1).into(),