diff options
| author | Jack Huey <jack.huey@umassmed.edu> | 2021-01-07 18:01:03 -0500 |
|---|---|---|
| committer | Jack Huey <jack.huey@umassmed.edu> | 2021-01-16 18:56:37 -0500 |
| commit | dcad9f1893d6bd4d09fe1c48ea4b500be1096031 (patch) | |
| tree | 5cd3fc19439e73f2c313f9fb2fd835410cbd0306 | |
| parent | 3dea68de1d75c388beea3378a4d15371b713f157 (diff) | |
| download | rust-dcad9f1893d6bd4d09fe1c48ea4b500be1096031.tar.gz rust-dcad9f1893d6bd4d09fe1c48ea4b500be1096031.zip | |
More review comments
| -rw-r--r-- | compiler/rustc_infer/src/infer/outlives/mod.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/context.rs | 14 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/mod.rs | 19 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/print/pretty.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/structural_impls.rs | 4 | ||||
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 2 |
6 files changed, 20 insertions, 29 deletions
diff --git a/compiler/rustc_infer/src/infer/outlives/mod.rs b/compiler/rustc_infer/src/infer/outlives/mod.rs index 13fc5b360a9..07c75d50d91 100644 --- a/compiler/rustc_infer/src/infer/outlives/mod.rs +++ b/compiler/rustc_infer/src/infer/outlives/mod.rs @@ -6,7 +6,6 @@ pub mod verify; use rustc_middle::traits::query::OutlivesBound; use rustc_middle::ty; -use rustc_middle::ty::fold::TypeFoldable; pub fn explicit_outlives_bounds<'tcx>( param_env: ty::ParamEnv<'tcx>, @@ -16,9 +15,8 @@ pub fn explicit_outlives_bounds<'tcx>( .caller_bounds() .into_iter() .map(ty::Predicate::kind) - .map(ty::Binder::skip_binder) - .filter(|atom| !atom.has_escaping_bound_vars()) - .filter_map(move |atom| match atom { + .filter_map(ty::Binder::no_bound_vars) + .filter_map(move |kind| match kind { ty::PredicateKind::Projection(..) | ty::PredicateKind::Trait(..) | ty::PredicateKind::Subtype(..) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index ee4e7c8f0cc..3c53c426795 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -133,13 +133,13 @@ impl<'tcx> CtxtInterners<'tcx> { } #[inline(never)] - fn intern_predicate(&self, binder: Binder<PredicateKind<'tcx>>) -> &'tcx PredicateInner<'tcx> { + fn intern_predicate(&self, kind: Binder<PredicateKind<'tcx>>) -> &'tcx PredicateInner<'tcx> { self.predicate - .intern(binder, |binder| { - let flags = super::flags::FlagComputation::for_predicate(binder); + .intern(kind, |kind| { + let flags = super::flags::FlagComputation::for_predicate(kind); let predicate_struct = PredicateInner { - binder, + kind, flags: flags.flags, outer_exclusive_binder: flags.outer_exclusive_binder, }; @@ -1936,7 +1936,7 @@ impl<'tcx> Borrow<TyKind<'tcx>> for Interned<'tcx, TyS<'tcx>> { // N.B., an `Interned<PredicateInner>` compares and hashes as a `PredicateKind`. impl<'tcx> PartialEq for Interned<'tcx, PredicateInner<'tcx>> { fn eq(&self, other: &Interned<'tcx, PredicateInner<'tcx>>) -> bool { - self.0.binder == other.0.binder + self.0.kind == other.0.kind } } @@ -1944,13 +1944,13 @@ impl<'tcx> Eq for Interned<'tcx, PredicateInner<'tcx>> {} impl<'tcx> Hash for Interned<'tcx, PredicateInner<'tcx>> { fn hash<H: Hasher>(&self, s: &mut H) { - self.0.binder.hash(s) + self.0.kind.hash(s) } } impl<'tcx> Borrow<Binder<PredicateKind<'tcx>>> for Interned<'tcx, PredicateInner<'tcx>> { fn borrow<'a>(&'a self) -> &'a Binder<PredicateKind<'tcx>> { - &self.0.binder + &self.0.kind } } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index f8ae4a118db..76d3bc7a3d5 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1030,7 +1030,7 @@ impl<'tcx> GenericPredicates<'tcx> { #[derive(Debug)] crate struct PredicateInner<'tcx> { - binder: Binder<PredicateKind<'tcx>>, + kind: Binder<PredicateKind<'tcx>>, flags: TypeFlags, /// See the comment for the corresponding field of [TyS]. outer_exclusive_binder: ty::DebruijnIndex, @@ -1060,21 +1060,21 @@ impl Hash for Predicate<'_> { impl<'tcx> Eq for Predicate<'tcx> {} impl<'tcx> Predicate<'tcx> { - /// Converts this to a `Binder<PredicateKind<'tcx>>`. If the value was an - /// `Atom`, then it is not allowed to contain escaping bound vars. + /// Gets the inner `Binder<PredicateKind<'tcx>>`. pub fn kind(self) -> Binder<PredicateKind<'tcx>> { - self.inner.binder + self.inner.kind } - pub fn kind_ref(self) -> &'tcx Binder<PredicateKind<'tcx>> { - &self.inner.binder + /// Like `kind` but returns a reference. Only needed because of encoding. + pub(super) fn kind_ref(self) -> &'tcx Binder<PredicateKind<'tcx>> { + &self.inner.kind } } impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let PredicateInner { - ref binder, + ref kind, // The other fields just provide fast access to information that is // also contained in `kind`, so no need to hash them. @@ -1082,7 +1082,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> { outer_exclusive_binder: _, } = self.inner; - binder.hash_stable(hcx, hasher); + kind.hash_stable(hcx, hasher); } } @@ -1221,7 +1221,7 @@ impl<'tcx> Predicate<'tcx> { let substs = trait_ref.skip_binder().substs; let pred = self.kind().skip_binder(); let new = pred.subst(tcx, substs); - if new != pred { ty::Binder::bind(new).to_predicate(tcx) } else { self } + tcx.reuse_or_mk_predicate(self, ty::Binder::bind(new)) } } @@ -1352,7 +1352,6 @@ impl ToPredicate<'tcx> for Binder<PredicateKind<'tcx>> { impl ToPredicate<'tcx> for PredicateKind<'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(Binder::dummy(self)) } } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index ed24f2c9bfb..8911de41c6d 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -623,10 +623,6 @@ pub trait PrettyPrinter<'tcx>: p!("impl"); for (predicate, _) in bounds { let predicate = predicate.subst(self.tcx(), substs); - // Note: We can't use `to_opt_poly_trait_ref` here as `predicate` - // may contain unbound variables. We therefore do this manually. - // - // FIXME(lcnr): Find out why exactly this is the case :) let bound_predicate = predicate.kind(); if let ty::PredicateKind::Trait(pred, _) = bound_predicate.skip_binder() { let trait_ref = bound_predicate.rebind(pred.trait_ref); diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index ca625fddc99..44c173e356d 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -1017,12 +1017,12 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> { impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> { fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self { - let new = self.inner.binder.fold_with(folder); + let new = self.inner.kind.fold_with(folder); folder.tcx().reuse_or_mk_predicate(self, new) } fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> { - self.inner.binder.visit_with(visitor) + self.inner.kind.visit_with(visitor) } fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index bbc07e1011b..3ddb2adbf0a 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1684,8 +1684,6 @@ impl<'tcx> Clean<Type> for Ty<'tcx> { let mut bounds = bounds .iter() .filter_map(|bound| { - // Note: The substs of opaque types can contain unbound variables, - // meaning that we have to use `ignore_quantifiers_with_unbound_vars` here. let bound_predicate = bound.kind(); let trait_ref = match bound_predicate.skip_binder() { ty::PredicateKind::Trait(tr, _constness) => { |
