mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-18 01:44:04 +00:00
Cleanup
This commit is contained in:
parent
876192e8cd
commit
e76476afe4
@ -9,7 +9,7 @@ pub fn anonymize_predicate<'tcx>(
|
|||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
pred: ty::Predicate<'tcx>,
|
pred: ty::Predicate<'tcx>,
|
||||||
) -> ty::Predicate<'tcx> {
|
) -> ty::Predicate<'tcx> {
|
||||||
let new = tcx.anonymize_late_bound_regions(pred.kind());
|
let new = tcx.anonymize_late_bound_regions(pred.bound_atom());
|
||||||
tcx.reuse_or_mk_predicate(pred, new)
|
tcx.reuse_or_mk_predicate(pred, new)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ impl<'tcx, E: TyEncoder<'tcx>> EncodableWithShorthand<'tcx, E> for Ty<'tcx> {
|
|||||||
impl<'tcx, E: TyEncoder<'tcx>> EncodableWithShorthand<'tcx, E> for ty::Predicate<'tcx> {
|
impl<'tcx, E: TyEncoder<'tcx>> EncodableWithShorthand<'tcx, E> for ty::Predicate<'tcx> {
|
||||||
type Variant = ty::Binder<ty::PredicateAtom<'tcx>>;
|
type Variant = ty::Binder<ty::PredicateAtom<'tcx>>;
|
||||||
fn variant(&self) -> &Self::Variant {
|
fn variant(&self) -> &Self::Variant {
|
||||||
self.kind_ref()
|
self.bound_atom_ref()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,13 +133,13 @@ impl<'tcx> CtxtInterners<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
fn intern_predicate(&self, kind: Binder<PredicateAtom<'tcx>>) -> &'tcx PredicateInner<'tcx> {
|
fn intern_predicate(&self, binder: Binder<PredicateAtom<'tcx>>) -> &'tcx PredicateInner<'tcx> {
|
||||||
self.predicate
|
self.predicate
|
||||||
.intern(kind, |kind| {
|
.intern(binder, |binder| {
|
||||||
let flags = super::flags::FlagComputation::for_predicate(kind);
|
let flags = super::flags::FlagComputation::for_predicate(binder);
|
||||||
|
|
||||||
let predicate_struct = PredicateInner {
|
let predicate_struct = PredicateInner {
|
||||||
kind,
|
binder,
|
||||||
flags: flags.flags,
|
flags: flags.flags,
|
||||||
outer_exclusive_binder: flags.outer_exclusive_binder,
|
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`.
|
// N.B., an `Interned<PredicateInner>` compares and hashes as a `PredicateKind`.
|
||||||
impl<'tcx> PartialEq for Interned<'tcx, PredicateInner<'tcx>> {
|
impl<'tcx> PartialEq for Interned<'tcx, PredicateInner<'tcx>> {
|
||||||
fn eq(&self, other: &Interned<'tcx, PredicateInner<'tcx>>) -> bool {
|
fn eq(&self, other: &Interned<'tcx, PredicateInner<'tcx>>) -> bool {
|
||||||
self.0.kind == other.0.kind
|
self.0.binder == other.0.binder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1944,13 +1944,13 @@ impl<'tcx> Eq for Interned<'tcx, PredicateInner<'tcx>> {}
|
|||||||
|
|
||||||
impl<'tcx> Hash for Interned<'tcx, PredicateInner<'tcx>> {
|
impl<'tcx> Hash for Interned<'tcx, PredicateInner<'tcx>> {
|
||||||
fn hash<H: Hasher>(&self, s: &mut H) {
|
fn hash<H: Hasher>(&self, s: &mut H) {
|
||||||
self.0.kind.hash(s)
|
self.0.binder.hash(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Borrow<Binder<PredicateAtom<'tcx>>> for Interned<'tcx, PredicateInner<'tcx>> {
|
impl<'tcx> Borrow<Binder<PredicateAtom<'tcx>>> for Interned<'tcx, PredicateInner<'tcx>> {
|
||||||
fn borrow<'a>(&'a self) -> &'a Binder<PredicateAtom<'tcx>> {
|
fn borrow<'a>(&'a self) -> &'a Binder<PredicateAtom<'tcx>> {
|
||||||
&self.0.kind
|
&self.0.binder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2085,8 +2085,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mk_predicate(self, kind: Binder<PredicateAtom<'tcx>>) -> Predicate<'tcx> {
|
pub fn mk_predicate(self, binder: Binder<PredicateAtom<'tcx>>) -> Predicate<'tcx> {
|
||||||
let inner = self.interners.intern_predicate(kind);
|
let inner = self.interners.intern_predicate(binder);
|
||||||
Predicate { inner }
|
Predicate { inner }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2094,9 +2094,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
pub fn reuse_or_mk_predicate(
|
pub fn reuse_or_mk_predicate(
|
||||||
self,
|
self,
|
||||||
pred: Predicate<'tcx>,
|
pred: Predicate<'tcx>,
|
||||||
kind: Binder<PredicateAtom<'tcx>>,
|
binder: Binder<PredicateAtom<'tcx>>,
|
||||||
) -> Predicate<'tcx> {
|
) -> Predicate<'tcx> {
|
||||||
if pred.kind() != kind { self.mk_predicate(kind) } else { pred }
|
if pred.bound_atom() != binder { self.mk_predicate(binder) } else { pred }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mk_mach_int(self, tm: ast::IntTy) -> Ty<'tcx> {
|
pub fn mk_mach_int(self, tm: ast::IntTy) -> Ty<'tcx> {
|
||||||
|
@ -22,9 +22,9 @@ impl FlagComputation {
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn for_predicate(kind: ty::Binder<ty::PredicateAtom<'_>>) -> FlagComputation {
|
pub fn for_predicate(binder: ty::Binder<ty::PredicateAtom<'_>>) -> FlagComputation {
|
||||||
let mut result = FlagComputation::new();
|
let mut result = FlagComputation::new();
|
||||||
result.add_predicate_kind(kind);
|
result.add_predicate(binder);
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,7 +204,7 @@ impl FlagComputation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_predicate_kind(&mut self, binder: ty::Binder<ty::PredicateAtom<'_>>) {
|
fn add_predicate(&mut self, binder: ty::Binder<ty::PredicateAtom<'_>>) {
|
||||||
self.bound_computation(binder, |computation, atom| computation.add_predicate_atom(atom));
|
self.bound_computation(binder, |computation, atom| computation.add_predicate_atom(atom));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1030,7 +1030,7 @@ impl<'tcx> GenericPredicates<'tcx> {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
crate struct PredicateInner<'tcx> {
|
crate struct PredicateInner<'tcx> {
|
||||||
kind: Binder<PredicateAtom<'tcx>>,
|
binder: Binder<PredicateAtom<'tcx>>,
|
||||||
flags: TypeFlags,
|
flags: TypeFlags,
|
||||||
/// See the comment for the corresponding field of [TyS].
|
/// See the comment for the corresponding field of [TyS].
|
||||||
outer_exclusive_binder: ty::DebruijnIndex,
|
outer_exclusive_binder: ty::DebruijnIndex,
|
||||||
@ -1060,16 +1060,6 @@ impl Hash for Predicate<'_> {
|
|||||||
impl<'tcx> Eq for Predicate<'tcx> {}
|
impl<'tcx> Eq for Predicate<'tcx> {}
|
||||||
|
|
||||||
impl<'tcx> Predicate<'tcx> {
|
impl<'tcx> Predicate<'tcx> {
|
||||||
#[inline(always)]
|
|
||||||
pub fn kind(self) -> Binder<PredicateAtom<'tcx>> {
|
|
||||||
self.inner.kind
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn kind_ref(&self) -> &Binder<PredicateAtom<'tcx>> {
|
|
||||||
&self.inner.kind
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the inner `PredicateAtom`.
|
/// Returns the inner `PredicateAtom`.
|
||||||
///
|
///
|
||||||
/// The returned atom may contain unbound variables bound to binders skipped in this method.
|
/// The returned atom may contain unbound variables bound to binders skipped in this method.
|
||||||
@ -1077,8 +1067,7 @@ impl<'tcx> Predicate<'tcx> {
|
|||||||
///
|
///
|
||||||
/// Note that this method panics in case this predicate has unbound variables.
|
/// Note that this method panics in case this predicate has unbound variables.
|
||||||
pub fn skip_binders(self) -> PredicateAtom<'tcx> {
|
pub fn skip_binders(self) -> PredicateAtom<'tcx> {
|
||||||
let binder = self.kind();
|
self.inner.binder.skip_binder()
|
||||||
binder.skip_binder()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the inner `PredicateAtom`.
|
/// Returns the inner `PredicateAtom`.
|
||||||
@ -1088,29 +1077,30 @@ impl<'tcx> Predicate<'tcx> {
|
|||||||
/// Rebinding the returned atom can causes the previously bound variables
|
/// Rebinding the returned atom can causes the previously bound variables
|
||||||
/// to end up at the wrong binding level.
|
/// to end up at the wrong binding level.
|
||||||
pub fn skip_binders_unchecked(self) -> PredicateAtom<'tcx> {
|
pub fn skip_binders_unchecked(self) -> PredicateAtom<'tcx> {
|
||||||
let binder = self.kind();
|
self.inner.binder.skip_binder()
|
||||||
binder.skip_binder()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts this to a `Binder<PredicateAtom<'tcx>>`. If the value was an
|
/// Converts this to a `Binder<PredicateAtom<'tcx>>`. If the value was an
|
||||||
/// `Atom`, then it is not allowed to contain escaping bound vars.
|
/// `Atom`, then it is not allowed to contain escaping bound vars.
|
||||||
pub fn bound_atom(self) -> Binder<PredicateAtom<'tcx>> {
|
pub fn bound_atom(self) -> Binder<PredicateAtom<'tcx>> {
|
||||||
let binder = self.kind();
|
self.inner.binder
|
||||||
binder
|
}
|
||||||
|
|
||||||
|
pub fn bound_atom_ref(self) -> &'tcx Binder<PredicateAtom<'tcx>> {
|
||||||
|
&self.inner.binder
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Allows using a `Binder<PredicateAtom<'tcx>>` even if the given predicate previously
|
/// Allows using a `Binder<PredicateAtom<'tcx>>` even if the given predicate previously
|
||||||
/// contained unbound variables by shifting these variables outwards.
|
/// 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>> {
|
||||||
let binder = self.kind();
|
self.inner.binder
|
||||||
binder
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
|
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
|
||||||
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
|
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
|
||||||
let PredicateInner {
|
let PredicateInner {
|
||||||
ref kind,
|
ref binder,
|
||||||
|
|
||||||
// The other fields just provide fast access to information that is
|
// The other fields just provide fast access to information that is
|
||||||
// also contained in `kind`, so no need to hash them.
|
// also contained in `kind`, so no need to hash them.
|
||||||
@ -1118,7 +1108,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
|
|||||||
outer_exclusive_binder: _,
|
outer_exclusive_binder: _,
|
||||||
} = self.inner;
|
} = self.inner;
|
||||||
|
|
||||||
kind.hash_stable(hcx, hasher);
|
binder.hash_stable(hcx, hasher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2068,7 +2068,7 @@ define_print_and_forward_display! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ty::Predicate<'tcx> {
|
ty::Predicate<'tcx> {
|
||||||
let binder = self.kind();
|
let binder = self.bound_atom();
|
||||||
p!(print(binder))
|
p!(print(binder))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +224,7 @@ impl fmt::Debug for ty::ProjectionPredicate<'tcx> {
|
|||||||
|
|
||||||
impl fmt::Debug for ty::Predicate<'tcx> {
|
impl fmt::Debug for ty::Predicate<'tcx> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "{:?}", self.kind())
|
write!(f, "{:?}", self.bound_atom())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1017,12 +1017,12 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> {
|
|||||||
|
|
||||||
impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
|
impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
|
||||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||||
let new = self.inner.kind.fold_with(folder);
|
let new = self.inner.binder.fold_with(folder);
|
||||||
folder.tcx().reuse_or_mk_predicate(self, new)
|
folder.tcx().reuse_or_mk_predicate(self, new)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||||
self.inner.kind.super_visit_with(visitor)
|
self.inner.binder.visit_with(visitor)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||||
|
@ -345,7 +345,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
|
|||||||
|
|
||||||
let infcx = self.selcx.infcx();
|
let infcx = self.selcx.infcx();
|
||||||
|
|
||||||
let binder = obligation.predicate.kind();
|
let binder = obligation.predicate.bound_atom();
|
||||||
if binder.skip_binder().has_escaping_bound_vars() {
|
if binder.skip_binder().has_escaping_bound_vars() {
|
||||||
match binder.skip_binder() {
|
match binder.skip_binder() {
|
||||||
// Evaluation will discard candidates using the leak check.
|
// Evaluation will discard candidates using the leak check.
|
||||||
|
@ -94,7 +94,7 @@ fn compute_implied_outlives_bounds<'tcx>(
|
|||||||
// region relationships.
|
// region relationships.
|
||||||
implied_bounds.extend(obligations.into_iter().flat_map(|obligation| {
|
implied_bounds.extend(obligations.into_iter().flat_map(|obligation| {
|
||||||
assert!(!obligation.has_escaping_bound_vars());
|
assert!(!obligation.has_escaping_bound_vars());
|
||||||
let binder = obligation.predicate.kind();
|
let binder = obligation.predicate.bound_atom();
|
||||||
if binder.skip_binder().has_escaping_bound_vars() {
|
if binder.skip_binder().has_escaping_bound_vars() {
|
||||||
vec![]
|
vec![]
|
||||||
} else {
|
} else {
|
||||||
|
@ -31,7 +31,7 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate
|
|||||||
let mut pred: Vec<String> = predicates
|
let mut pred: Vec<String> = predicates
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(out_pred, _)| {
|
.map(|(out_pred, _)| {
|
||||||
let binder = out_pred.kind();
|
let binder = out_pred.bound_atom();
|
||||||
match binder.skip_binder() {
|
match binder.skip_binder() {
|
||||||
ty::PredicateAtom::RegionOutlives(p) => p.to_string(),
|
ty::PredicateAtom::RegionOutlives(p) => p.to_string(),
|
||||||
ty::PredicateAtom::TypeOutlives(p) => p.to_string(),
|
ty::PredicateAtom::TypeOutlives(p) => p.to_string(),
|
||||||
|
@ -115,7 +115,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
|
|||||||
.filter(|p| !p.is_global())
|
.filter(|p| !p.is_global())
|
||||||
.filter_map(|obligation| {
|
.filter_map(|obligation| {
|
||||||
// Note that we do not want to deal with qualified predicates here.
|
// Note that we do not want to deal with qualified predicates here.
|
||||||
let binder = obligation.predicate.kind();
|
let binder = obligation.predicate.bound_atom();
|
||||||
match binder.skip_binder() {
|
match binder.skip_binder() {
|
||||||
ty::PredicateAtom::Trait(pred, _) if !binder.has_escaping_bound_vars() => {
|
ty::PredicateAtom::Trait(pred, _) if !binder.has_escaping_bound_vars() => {
|
||||||
if pred.def_id() == sized_trait {
|
if pred.def_id() == sized_trait {
|
||||||
|
Loading…
Reference in New Issue
Block a user