Error(DelaySpanBugEmitted),
}
+impl TyKind<'tcx> {
+ #[inline]
+ pub fn is_primitive(&self) -> bool {
+ match self {
+ Bool | Char | Int(_) | Uint(_) | Float(_) => true,
+ _ => false,
+ }
+ }
+}
+
/// A type that is not publicly constructable. This prevents people from making `TyKind::Error`
/// except through `tcx.err*()`.
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
Binder(value)
}
+ /// Wraps `value` in a binder without actually binding any currently
+ /// unbound variables.
+ ///
+ /// Note that this will shift all debrujin indices of escaping bound variables
+ /// by 1 to avoid accidential captures.
+ pub fn wrap_nonbinding(tcx: TyCtxt<'tcx>, value: T) -> Binder<T>
+ where
+ T: TypeFoldable<'tcx>,
+ {
+ if value.has_escaping_bound_vars() {
+ Binder::bind(super::fold::shift_vars(tcx, &value, 1))
+ } else {
+ Binder::dummy(value)
+ }
+ }
+
/// Skips the binder and returns the "bound" value. This is a
/// risky thing to do because it's easy to get confused about
/// De Bruijn indices and the like. It is usually better to
}
}
+impl<T> Binder<Option<T>> {
+ pub fn transpose(self) -> Option<Binder<T>> {
+ match self.0 {
+ Some(v) => Some(Binder(v)),
+ None => None,
+ }
+ }
+}
+
/// Represents the projection of an associated type. In explicit UFCS
/// form this would be written `<T as Trait<..>>::N`.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
#[inline]
pub fn is_primitive(&self) -> bool {
- match self.kind {
- Bool | Char | Int(_) | Uint(_) | Float(_) => true,
- _ => false,
- }
+ self.kind.is_primitive()
}
#[inline]