]> git.lizzy.rs Git - rust.git/commitdiff
Remove PredicateKind::Atom
authorJack Huey <jack.huey@umassmed.edu>
Tue, 22 Dec 2020 03:49:03 +0000 (22:49 -0500)
committerJack Huey <jack.huey@umassmed.edu>
Sat, 16 Jan 2021 23:40:47 +0000 (18:40 -0500)
12 files changed:
compiler/rustc_infer/src/infer/canonical/query_response.rs
compiler/rustc_infer/src/traits/util.rs
compiler/rustc_middle/src/ty/flags.rs
compiler/rustc_middle/src/ty/mod.rs
compiler/rustc_middle/src/ty/print/pretty.rs
compiler/rustc_middle/src/ty/structural_impls.rs
compiler/rustc_trait_selection/src/traits/fulfill.rs
compiler/rustc_traits/src/implied_outlives_bounds.rs
compiler/rustc_typeck/src/collect.rs
compiler/rustc_typeck/src/outlives/mod.rs
src/test/ui/specialization/min_specialization/repeated_projection_type.stderr
src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs

index 71ce50f7453725be234897a53cd5daa4a2a9b100..6dbaf8d225a7ac22eba3e4612b467006cd6f9a5a 100644 (file)
@@ -541,8 +541,7 @@ fn query_outlives_constraints_into_obligations<'a>(
                     span_bug!(cause.span, "unexpected const outlives {:?}", constraint);
                 }
             };
-            let predicate =
-                predicate.rebind(atom).potentially_quantified(self.tcx, ty::PredicateKind::ForAll);
+            let predicate = predicate.rebind(atom).potentially_quantified(self.tcx);
 
             Obligation::new(cause.clone(), param_env, predicate)
         })
index 8273c2d291d096020ede192b4f10f6c7a2e257e0..d9ef5d88f1cfaef3f80f89edc1d04cd9106a2545 100644 (file)
@@ -14,7 +14,6 @@ pub fn anonymize_predicate<'tcx>(
             let new = ty::PredicateKind::ForAll(tcx.anonymize_late_bound_regions(binder));
             tcx.reuse_or_mk_predicate(pred, new)
         }
-        ty::PredicateKind::Atom(_) => pred,
     }
 }
 
index 4de3d15924862cbdbfe4a19a3d2d68b6fea645e2..47ada10f55f84ee7896be5fa3fe4bac65dbeca98 100644 (file)
@@ -211,7 +211,6 @@ fn add_predicate_kind(&mut self, kind: ty::PredicateKind<'_>) {
                     computation.add_predicate_atom(atom)
                 });
             }
-            ty::PredicateKind::Atom(atom) => self.add_predicate_atom(atom),
         }
     }
 
index 1399fc76e02d693f3310d511334260013f929cbd..539506409660c0e701385ee7ae6b56039b6a41c3 100644 (file)
@@ -1037,7 +1037,7 @@ fn instantiate_identity_into(
 }
 
 #[cfg(target_arch = "x86_64")]
-static_assert_size!(PredicateInner<'_>, 48);
+static_assert_size!(PredicateInner<'_>, 40);
 
 #[derive(Clone, Copy, Lift)]
 pub struct Predicate<'tcx> {
@@ -1074,10 +1074,6 @@ pub fn kind(self) -> &'tcx PredicateKind<'tcx> {
     pub fn skip_binders(self) -> PredicateAtom<'tcx> {
         match self.kind() {
             &PredicateKind::ForAll(binder) => binder.skip_binder(),
-            &PredicateKind::Atom(atom) => {
-                debug_assert!(!atom.has_escaping_bound_vars());
-                atom
-            }
         }
     }
 
@@ -1090,7 +1086,6 @@ pub fn skip_binders(self) -> PredicateAtom<'tcx> {
     pub fn skip_binders_unchecked(self) -> PredicateAtom<'tcx> {
         match self.kind() {
             &PredicateKind::ForAll(binder) => binder.skip_binder(),
-            &PredicateKind::Atom(atom) => atom,
         }
     }
 
@@ -1099,19 +1094,14 @@ pub fn skip_binders_unchecked(self) -> PredicateAtom<'tcx> {
     pub fn bound_atom(self) -> Binder<PredicateAtom<'tcx>> {
         match self.kind() {
             &PredicateKind::ForAll(binder) => binder,
-            &PredicateKind::Atom(atom) => {
-                debug_assert!(!atom.has_escaping_bound_vars());
-                Binder::dummy(atom)
-            }
         }
     }
 
     /// Allows using a `Binder<PredicateAtom<'tcx>>` even if the given predicate previously
     /// contained unbound variables by shifting these variables outwards.
-    pub fn bound_atom_with_opt_escaping(self, tcx: TyCtxt<'tcx>) -> Binder<PredicateAtom<'tcx>> {
+    pub fn bound_atom_with_opt_escaping(self, _tcx: TyCtxt<'tcx>) -> Binder<PredicateAtom<'tcx>> {
         match self.kind() {
             &PredicateKind::ForAll(binder) => binder,
-            &PredicateKind::Atom(atom) => Binder::wrap_nonbinding(tcx, atom),
         }
     }
 }
@@ -1136,7 +1126,6 @@ fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHas
 pub enum PredicateKind<'tcx> {
     /// `for<'a>: ...`
     ForAll(Binder<PredicateAtom<'tcx>>),
-    Atom(PredicateAtom<'tcx>),
 }
 
 #[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
@@ -1189,16 +1178,8 @@ pub enum PredicateAtom<'tcx> {
 
 impl<'tcx> Binder<PredicateAtom<'tcx>> {
     /// Wraps `self` with the given qualifier if this predicate has any unbound variables.
-    pub fn potentially_quantified(
-        self,
-        tcx: TyCtxt<'tcx>,
-        qualifier: impl FnOnce(Binder<PredicateAtom<'tcx>>) -> PredicateKind<'tcx>,
-    ) -> Predicate<'tcx> {
-        match self.no_bound_vars() {
-            Some(atom) => PredicateKind::Atom(atom),
-            None => qualifier(self),
-        }
-        .to_predicate(tcx)
+    pub fn potentially_quantified(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
+        PredicateKind::ForAll(self).to_predicate(tcx)
     }
 }
 
@@ -1289,11 +1270,7 @@ pub fn subst_supertrait(
         let substs = trait_ref.skip_binder().substs;
         let pred = self.skip_binders();
         let new = pred.subst(tcx, substs);
-        if new != pred {
-            ty::Binder::bind(new).potentially_quantified(tcx, PredicateKind::ForAll)
-        } else {
-            self
-        }
+        if new != pred { ty::Binder::bind(new).potentially_quantified(tcx) } else { self }
     }
 }
 
@@ -1425,7 +1402,7 @@ impl ToPredicate<'tcx> for PredicateAtom<'tcx> {
     #[inline(always)]
     fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
         debug_assert!(!self.has_escaping_bound_vars(), "escaping bound vars for {:?}", self);
-        tcx.mk_predicate(PredicateKind::Atom(self))
+        tcx.mk_predicate(PredicateKind::ForAll(Binder::dummy(self)))
     }
 }
 
@@ -1450,27 +1427,25 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitPredicate<'tcx>> {
     fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
         self.value
             .map_bound(|value| PredicateAtom::Trait(value, self.constness))
-            .potentially_quantified(tcx, PredicateKind::ForAll)
+            .potentially_quantified(tcx)
     }
 }
 
 impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> {
     fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
-        self.map_bound(PredicateAtom::RegionOutlives)
-            .potentially_quantified(tcx, PredicateKind::ForAll)
+        self.map_bound(PredicateAtom::RegionOutlives).potentially_quantified(tcx)
     }
 }
 
 impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> {
     fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
-        self.map_bound(PredicateAtom::TypeOutlives)
-            .potentially_quantified(tcx, PredicateKind::ForAll)
+        self.map_bound(PredicateAtom::TypeOutlives).potentially_quantified(tcx)
     }
 }
 
 impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> {
     fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
-        self.map_bound(PredicateAtom::Projection).potentially_quantified(tcx, PredicateKind::ForAll)
+        self.map_bound(PredicateAtom::Projection).potentially_quantified(tcx)
     }
 }
 
index 893572785f76b0dde108da22218cc9de28b4dfb5..bc9ea3728b61a328f6b466741e0c53de6efdcfd9 100644 (file)
@@ -2069,7 +2069,6 @@ pub fn print_only_trait_path(self) -> ty::Binder<TraitRefPrintOnlyTraitPath<'tcx
 
     ty::Predicate<'tcx> {
         match self.kind() {
-            &ty::PredicateKind::Atom(atom) => p!(print(atom)),
             ty::PredicateKind::ForAll(binder) => p!(print(binder)),
         }
     }
index 7a1ca6a6c2bfc21a657a156cf4fb47253e9ece1d..934d97d00e8460ee502b3e9df1b2c13c79f44885 100644 (file)
@@ -232,7 +232,6 @@ impl fmt::Debug for ty::PredicateKind<'tcx> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         match *self {
             ty::PredicateKind::ForAll(binder) => write!(f, "ForAll({:?})", binder),
-            ty::PredicateKind::Atom(atom) => write!(f, "{:?}", atom),
         }
     }
 }
@@ -486,7 +485,6 @@ impl<'a, 'tcx> Lift<'tcx> for ty::PredicateKind<'a> {
     fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
         match self {
             ty::PredicateKind::ForAll(binder) => tcx.lift(binder).map(ty::PredicateKind::ForAll),
-            ty::PredicateKind::Atom(atom) => tcx.lift(atom).map(ty::PredicateKind::Atom),
         }
     }
 }
index a04f816b0f8a002bdc1c063a25748852fdd48c68..55d5331ae37b77f70d7e159be2e70a9999e9b771 100644 (file)
@@ -346,45 +346,47 @@ fn progress_changed_obligations(
         let infcx = self.selcx.infcx();
 
         match *obligation.predicate.kind() {
-            ty::PredicateKind::ForAll(binder) => match binder.skip_binder() {
-                // Evaluation will discard candidates using the leak check.
-                // This means we need to pass it the bound version of our
-                // predicate.
-                ty::PredicateAtom::Trait(trait_ref, _constness) => {
-                    let trait_obligation = obligation.with(binder.rebind(trait_ref));
-
-                    self.process_trait_obligation(
-                        obligation,
-                        trait_obligation,
-                        &mut pending_obligation.stalled_on,
-                    )
-                }
-                ty::PredicateAtom::Projection(data) => {
-                    let project_obligation = obligation.with(binder.rebind(data));
+            ty::PredicateKind::ForAll(binder) if binder.skip_binder().has_escaping_bound_vars() => {
+                match binder.skip_binder() {
+                    // Evaluation will discard candidates using the leak check.
+                    // This means we need to pass it the bound version of our
+                    // predicate.
+                    ty::PredicateAtom::Trait(trait_ref, _constness) => {
+                        let trait_obligation = obligation.with(binder.rebind(trait_ref));
+
+                        self.process_trait_obligation(
+                            obligation,
+                            trait_obligation,
+                            &mut pending_obligation.stalled_on,
+                        )
+                    }
+                    ty::PredicateAtom::Projection(data) => {
+                        let project_obligation = obligation.with(binder.rebind(data));
 
-                    self.process_projection_obligation(
-                        project_obligation,
-                        &mut pending_obligation.stalled_on,
-                    )
-                }
-                ty::PredicateAtom::RegionOutlives(_)
-                | ty::PredicateAtom::TypeOutlives(_)
-                | ty::PredicateAtom::WellFormed(_)
-                | ty::PredicateAtom::ObjectSafe(_)
-                | ty::PredicateAtom::ClosureKind(..)
-                | ty::PredicateAtom::Subtype(_)
-                | ty::PredicateAtom::ConstEvaluatable(..)
-                | ty::PredicateAtom::ConstEquate(..) => {
-                    let pred = infcx.replace_bound_vars_with_placeholders(binder);
-                    ProcessResult::Changed(mk_pending(vec![
-                        obligation.with(pred.to_predicate(self.selcx.tcx())),
-                    ]))
-                }
-                ty::PredicateAtom::TypeWellFormedFromEnv(..) => {
-                    bug!("TypeWellFormedFromEnv is only used for Chalk")
+                        self.process_projection_obligation(
+                            project_obligation,
+                            &mut pending_obligation.stalled_on,
+                        )
+                    }
+                    ty::PredicateAtom::RegionOutlives(_)
+                    | ty::PredicateAtom::TypeOutlives(_)
+                    | ty::PredicateAtom::WellFormed(_)
+                    | ty::PredicateAtom::ObjectSafe(_)
+                    | ty::PredicateAtom::ClosureKind(..)
+                    | ty::PredicateAtom::Subtype(_)
+                    | ty::PredicateAtom::ConstEvaluatable(..)
+                    | ty::PredicateAtom::ConstEquate(..) => {
+                        let pred = infcx.replace_bound_vars_with_placeholders(binder);
+                        ProcessResult::Changed(mk_pending(vec![
+                            obligation.with(pred.to_predicate(self.selcx.tcx())),
+                        ]))
+                    }
+                    ty::PredicateAtom::TypeWellFormedFromEnv(..) => {
+                        bug!("TypeWellFormedFromEnv is only used for Chalk")
+                    }
                 }
-            },
-            ty::PredicateKind::Atom(atom) => match atom {
+            }
+            ty::PredicateKind::ForAll(binder) => match binder.skip_binder() {
                 ty::PredicateAtom::Trait(data, _) => {
                     let trait_obligation = obligation.with(Binder::dummy(data));
 
index 97017fbf2e56a31965167a6400c4bb376b66b296..a4da22fc2ca83e9500d1ca9fab203de6ed7c1d8c 100644 (file)
@@ -95,8 +95,12 @@ fn compute_implied_outlives_bounds<'tcx>(
         implied_bounds.extend(obligations.into_iter().flat_map(|obligation| {
             assert!(!obligation.has_escaping_bound_vars());
             match obligation.predicate.kind() {
-                &ty::PredicateKind::ForAll(..) => vec![],
-                &ty::PredicateKind::Atom(atom) => match atom {
+                &ty::PredicateKind::ForAll(binder)
+                    if binder.skip_binder().has_escaping_bound_vars() =>
+                {
+                    vec![]
+                }
+                &ty::PredicateKind::ForAll(binder) => match binder.skip_binder() {
                     ty::PredicateAtom::Trait(..)
                     | ty::PredicateAtom::Subtype(..)
                     | ty::PredicateAtom::Projection(..)
index a6677328f8f8827b5864c7cb9799d27ec16b58b8..b1242f0d1d5183f35cd12184398383dcb529dd71 100644 (file)
@@ -1949,10 +1949,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
                         let predicate = ty::Binder::bind(ty::PredicateAtom::TypeOutlives(
                             ty::OutlivesPredicate(ty, re_root_empty),
                         ));
-                        predicates.insert((
-                            predicate.potentially_quantified(tcx, ty::PredicateKind::ForAll),
-                            span,
-                        ));
+                        predicates.insert((predicate.potentially_quantified(tcx), span));
                     }
                 }
 
@@ -1996,7 +1993,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
                                 ty::Binder::bind(ty::PredicateAtom::TypeOutlives(
                                     ty::OutlivesPredicate(ty, region),
                                 ))
-                                .potentially_quantified(tcx, ty::PredicateKind::ForAll),
+                                .potentially_quantified(tcx),
                                 lifetime.span,
                             ));
                         }
index b1f79331d5f62bbfebd1ca287552317f76ca1f7a..649edfb8f52316368411bcb1f25857b34929875e 100644 (file)
@@ -31,13 +31,11 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate
                     let mut pred: Vec<String> = predicates
                         .iter()
                         .map(|(out_pred, _)| match out_pred.kind() {
-                            ty::PredicateKind::Atom(ty::PredicateAtom::RegionOutlives(p)) => {
-                                p.to_string()
-                            }
-                            ty::PredicateKind::Atom(ty::PredicateAtom::TypeOutlives(p)) => {
-                                p.to_string()
-                            }
-                            err => bug!("unexpected predicate {:?}", err),
+                            ty::PredicateKind::ForAll(binder) => match binder.skip_binder() {
+                                ty::PredicateAtom::RegionOutlives(p) => p.to_string(),
+                                ty::PredicateAtom::TypeOutlives(p) => p.to_string(),
+                                err => bug!("unexpected predicate {:?}", err),
+                            },
                         })
                         .collect();
                     pred.sort();
index fee8b06e94c0bb5411eacb27b873ecd96c41c07b..fab36adb0f44e5bdd79a86d76d1ffaced705b5e6 100644 (file)
@@ -1,4 +1,4 @@
-error: cannot specialize on `ProjectionPredicate(ProjectionTy { substs: [V], item_def_id: DefId(0:6 ~ repeated_projection_type[317d]::Id::This) }, (I,))`
+error: cannot specialize on `ForAll(Binder(ProjectionPredicate(ProjectionTy { substs: [V], item_def_id: DefId(0:6 ~ repeated_projection_type[317d]::Id::This) }, (I,))))`
   --> $DIR/repeated_projection_type.rs:19:1
    |
 LL | / impl<I, V: Id<This = (I,)>> X for V {
index a435f86bfd8d56af2f8892b53517127bbd622c7a..ad50a6a0405fcc6eff1ee94154065938e2294102 100644 (file)
@@ -115,13 +115,15 @@ fn check_fn(
             .filter(|p| !p.is_global())
             .filter_map(|obligation| {
                 // Note that we do not want to deal with qualified predicates here.
-                if let ty::PredicateKind::Atom(ty::PredicateAtom::Trait(pred, _)) = obligation.predicate.kind() {
-                    if pred.def_id() == sized_trait {
-                        return None;
+                let ty::PredicateKind::ForAll(binder) = obligation.predicate.kind();
+                match binder.skip_binder() {
+                    ty::PredicateAtom::Trait(pred, _) if !binder.has_escaping_bound_vars() => {
+                        if pred.def_id() == sized_trait {
+                            return None;
+                        }
+                        Some(pred)
                     }
-                    Some(pred)
-                } else {
-                    None
+                    _ => None,
                 }
             })
             .collect::<Vec<_>>();