Skip to content

Commit dcad9f1

Browse files
committed
More review comments
1 parent 3dea68d commit dcad9f1

File tree

6 files changed

+20
-29
lines changed

6 files changed

+20
-29
lines changed

compiler/rustc_infer/src/infer/outlives/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pub mod verify;
66

77
use rustc_middle::traits::query::OutlivesBound;
88
use rustc_middle::ty;
9-
use rustc_middle::ty::fold::TypeFoldable;
109

1110
pub fn explicit_outlives_bounds<'tcx>(
1211
param_env: ty::ParamEnv<'tcx>,
@@ -16,9 +15,8 @@ pub fn explicit_outlives_bounds<'tcx>(
1615
.caller_bounds()
1716
.into_iter()
1817
.map(ty::Predicate::kind)
19-
.map(ty::Binder::skip_binder)
20-
.filter(|atom| !atom.has_escaping_bound_vars())
21-
.filter_map(move |atom| match atom {
18+
.filter_map(ty::Binder::no_bound_vars)
19+
.filter_map(move |kind| match kind {
2220
ty::PredicateKind::Projection(..)
2321
| ty::PredicateKind::Trait(..)
2422
| ty::PredicateKind::Subtype(..)

compiler/rustc_middle/src/ty/context.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ impl<'tcx> CtxtInterners<'tcx> {
133133
}
134134

135135
#[inline(never)]
136-
fn intern_predicate(&self, binder: Binder<PredicateKind<'tcx>>) -> &'tcx PredicateInner<'tcx> {
136+
fn intern_predicate(&self, kind: Binder<PredicateKind<'tcx>>) -> &'tcx PredicateInner<'tcx> {
137137
self.predicate
138-
.intern(binder, |binder| {
139-
let flags = super::flags::FlagComputation::for_predicate(binder);
138+
.intern(kind, |kind| {
139+
let flags = super::flags::FlagComputation::for_predicate(kind);
140140

141141
let predicate_struct = PredicateInner {
142-
binder,
142+
kind,
143143
flags: flags.flags,
144144
outer_exclusive_binder: flags.outer_exclusive_binder,
145145
};
@@ -1936,21 +1936,21 @@ impl<'tcx> Borrow<TyKind<'tcx>> for Interned<'tcx, TyS<'tcx>> {
19361936
// N.B., an `Interned<PredicateInner>` compares and hashes as a `PredicateKind`.
19371937
impl<'tcx> PartialEq for Interned<'tcx, PredicateInner<'tcx>> {
19381938
fn eq(&self, other: &Interned<'tcx, PredicateInner<'tcx>>) -> bool {
1939-
self.0.binder == other.0.binder
1939+
self.0.kind == other.0.kind
19401940
}
19411941
}
19421942

19431943
impl<'tcx> Eq for Interned<'tcx, PredicateInner<'tcx>> {}
19441944

19451945
impl<'tcx> Hash for Interned<'tcx, PredicateInner<'tcx>> {
19461946
fn hash<H: Hasher>(&self, s: &mut H) {
1947-
self.0.binder.hash(s)
1947+
self.0.kind.hash(s)
19481948
}
19491949
}
19501950

19511951
impl<'tcx> Borrow<Binder<PredicateKind<'tcx>>> for Interned<'tcx, PredicateInner<'tcx>> {
19521952
fn borrow<'a>(&'a self) -> &'a Binder<PredicateKind<'tcx>> {
1953-
&self.0.binder
1953+
&self.0.kind
19541954
}
19551955
}
19561956

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ impl<'tcx> GenericPredicates<'tcx> {
10301030

10311031
#[derive(Debug)]
10321032
crate struct PredicateInner<'tcx> {
1033-
binder: Binder<PredicateKind<'tcx>>,
1033+
kind: Binder<PredicateKind<'tcx>>,
10341034
flags: TypeFlags,
10351035
/// See the comment for the corresponding field of [TyS].
10361036
outer_exclusive_binder: ty::DebruijnIndex,
@@ -1060,29 +1060,29 @@ impl Hash for Predicate<'_> {
10601060
impl<'tcx> Eq for Predicate<'tcx> {}
10611061

10621062
impl<'tcx> Predicate<'tcx> {
1063-
/// Converts this to a `Binder<PredicateKind<'tcx>>`. If the value was an
1064-
/// `Atom`, then it is not allowed to contain escaping bound vars.
1063+
/// Gets the inner `Binder<PredicateKind<'tcx>>`.
10651064
pub fn kind(self) -> Binder<PredicateKind<'tcx>> {
1066-
self.inner.binder
1065+
self.inner.kind
10671066
}
10681067

1069-
pub fn kind_ref(self) -> &'tcx Binder<PredicateKind<'tcx>> {
1070-
&self.inner.binder
1068+
/// Like `kind` but returns a reference. Only needed because of encoding.
1069+
pub(super) fn kind_ref(self) -> &'tcx Binder<PredicateKind<'tcx>> {
1070+
&self.inner.kind
10711071
}
10721072
}
10731073

10741074
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
10751075
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
10761076
let PredicateInner {
1077-
ref binder,
1077+
ref kind,
10781078

10791079
// The other fields just provide fast access to information that is
10801080
// also contained in `kind`, so no need to hash them.
10811081
flags: _,
10821082
outer_exclusive_binder: _,
10831083
} = self.inner;
10841084

1085-
binder.hash_stable(hcx, hasher);
1085+
kind.hash_stable(hcx, hasher);
10861086
}
10871087
}
10881088

@@ -1221,7 +1221,7 @@ impl<'tcx> Predicate<'tcx> {
12211221
let substs = trait_ref.skip_binder().substs;
12221222
let pred = self.kind().skip_binder();
12231223
let new = pred.subst(tcx, substs);
1224-
if new != pred { ty::Binder::bind(new).to_predicate(tcx) } else { self }
1224+
tcx.reuse_or_mk_predicate(self, ty::Binder::bind(new))
12251225
}
12261226
}
12271227

@@ -1352,7 +1352,6 @@ impl ToPredicate<'tcx> for Binder<PredicateKind<'tcx>> {
13521352
impl ToPredicate<'tcx> for PredicateKind<'tcx> {
13531353
#[inline(always)]
13541354
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1355-
debug_assert!(!self.has_escaping_bound_vars(), "escaping bound vars for {:?}", self);
13561355
tcx.mk_predicate(Binder::dummy(self))
13571356
}
13581357
}

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,6 @@ pub trait PrettyPrinter<'tcx>:
623623
p!("impl");
624624
for (predicate, _) in bounds {
625625
let predicate = predicate.subst(self.tcx(), substs);
626-
// Note: We can't use `to_opt_poly_trait_ref` here as `predicate`
627-
// may contain unbound variables. We therefore do this manually.
628-
//
629-
// FIXME(lcnr): Find out why exactly this is the case :)
630626
let bound_predicate = predicate.kind();
631627
if let ty::PredicateKind::Trait(pred, _) = bound_predicate.skip_binder() {
632628
let trait_ref = bound_predicate.rebind(pred.trait_ref);

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,12 +1017,12 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> {
10171017

10181018
impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
10191019
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
1020-
let new = self.inner.binder.fold_with(folder);
1020+
let new = self.inner.kind.fold_with(folder);
10211021
folder.tcx().reuse_or_mk_predicate(self, new)
10221022
}
10231023

10241024
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1025-
self.inner.binder.visit_with(visitor)
1025+
self.inner.kind.visit_with(visitor)
10261026
}
10271027

10281028
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {

src/librustdoc/clean/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,8 +1684,6 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
16841684
let mut bounds = bounds
16851685
.iter()
16861686
.filter_map(|bound| {
1687-
// Note: The substs of opaque types can contain unbound variables,
1688-
// meaning that we have to use `ignore_quantifiers_with_unbound_vars` here.
16891687
let bound_predicate = bound.kind();
16901688
let trait_ref = match bound_predicate.skip_binder() {
16911689
ty::PredicateKind::Trait(tr, _constness) => {

0 commit comments

Comments
 (0)