More review comments
This commit is contained in:
parent
3dea68de1d
commit
dcad9f1893
6 changed files with 20 additions and 29 deletions
|
@ -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(..)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue