Add u32 for bound variables to Binder

This commit is contained in:
Jack Huey 2020-06-01 19:23:23 -04:00
parent 4955d755d3
commit 97a22a4f9c
3 changed files with 14 additions and 13 deletions

View File

@ -341,7 +341,7 @@ impl ObligationCauseCode<'_> {
// `ObligationCauseCode` is used a lot. Make sure it doesn't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
static_assert_size!(ObligationCauseCode<'_>, 32);
static_assert_size!(ObligationCauseCode<'_>, 40);
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum StatementAsExpression {

View File

@ -302,7 +302,7 @@ impl<'tcx> TyS<'tcx> {
// `TyS` is used a lot. Make sure it doesn't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
static_assert_size!(TyS<'_>, 32);
static_assert_size!(TyS<'_>, 40);
impl<'tcx> Ord for TyS<'tcx> {
fn cmp(&self, other: &TyS<'tcx>) -> Ordering {
@ -366,7 +366,7 @@ crate struct PredicateInner<'tcx> {
}
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
static_assert_size!(PredicateInner<'_>, 40);
static_assert_size!(PredicateInner<'_>, 48);
#[derive(Clone, Copy, Lift)]
pub struct Predicate<'tcx> {

View File

@ -232,7 +232,7 @@ impl TyKind<'tcx> {
// `TyKind` is used a lot. Make sure it doesn't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
static_assert_size!(TyKind<'_>, 24);
static_assert_size!(TyKind<'_>, 32);
/// A closure can be modeled as a struct that looks like:
///
@ -957,7 +957,7 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> {
///
/// `Decodable` and `Encodable` are implemented for `Binder<T>` using the `impl_binder_encode_decode!` macro.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct Binder<T>(T);
pub struct Binder<T>(T, u32);
impl<T> Binder<T> {
/// Wraps `value` in a binder, asserting that `value` does not
@ -969,12 +969,12 @@ impl<T> Binder<T> {
T: TypeFoldable<'tcx>,
{
debug_assert!(!value.has_escaping_bound_vars());
Binder(value)
Binder(value, 0)
}
/// Wraps `value` in a binder, binding higher-ranked vars (if any).
pub fn bind(value: T) -> Binder<T> {
Binder(value)
Binder(value, 0)
}
/// Skips the binder and returns the "bound" value. This is a
@ -998,7 +998,7 @@ impl<T> Binder<T> {
}
pub fn as_ref(&self) -> Binder<&T> {
Binder(&self.0)
Binder(&self.0, self.1)
}
pub fn map_bound_ref<F, U>(&self, f: F) -> Binder<U>
@ -1012,7 +1012,7 @@ impl<T> Binder<T> {
where
F: FnOnce(T) -> U,
{
Binder(f(self.0))
Binder(f(self.0), self.1)
}
/// Wraps a `value` in a binder, using the same bound variables as the
@ -1025,7 +1025,7 @@ impl<T> Binder<T> {
/// because bound vars aren't allowed to change here, whereas they are
/// in `bind`. This may be (debug) asserted in the future.
pub fn rebind<U>(&self, value: U) -> Binder<U> {
Binder(value)
Binder(value, self.1)
}
/// Unwraps and returns the value within, but only if it contains
@ -1056,7 +1056,7 @@ impl<T> Binder<T> {
where
F: FnOnce(T, U) -> R,
{
Binder(f(self.0, u.0))
Binder(f(self.0, u.0), self.1)
}
/// Splits the contents into two things that share the same binder
@ -1070,13 +1070,14 @@ impl<T> Binder<T> {
F: FnOnce(T) -> (U, V),
{
let (u, v) = f(self.0);
(Binder(u), Binder(v))
(Binder(u, self.1), Binder(v, self.1))
}
}
impl<T> Binder<Option<T>> {
pub fn transpose(self) -> Option<Binder<T>> {
self.0.map(Binder)
let bound_vars = self.1;
self.0.map(|v| Binder(v, bound_vars))
}
}