Make everything builtin!
This commit is contained in:
parent
de81007d13
commit
a7ed9c1da7
23 changed files with 345 additions and 444 deletions
|
@ -43,7 +43,7 @@ macro_rules! span_bug {
|
|||
|
||||
#[macro_export]
|
||||
macro_rules! CloneLiftImpls {
|
||||
($($ty:ty,)+) => {
|
||||
($($ty:ty),+ $(,)?) => {
|
||||
$(
|
||||
impl<'tcx> $crate::ty::Lift<'tcx> for $ty {
|
||||
type Lifted = Self;
|
||||
|
@ -59,7 +59,7 @@ macro_rules! CloneLiftImpls {
|
|||
/// allocated data** (i.e., don't need to be folded).
|
||||
#[macro_export]
|
||||
macro_rules! TrivialTypeTraversalImpls {
|
||||
($($ty:ty,)+) => {
|
||||
($($ty:ty),+ $(,)?) => {
|
||||
$(
|
||||
impl<'tcx> $crate::ty::fold::TypeFoldable<$crate::ty::TyCtxt<'tcx>> for $ty {
|
||||
fn try_fold_with<F: $crate::ty::fold::FallibleTypeFolder<$crate::ty::TyCtxt<'tcx>>>(
|
||||
|
|
|
@ -178,9 +178,7 @@ impl<'tcx> graph::WithPredecessors for BasicBlocks<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
TrivialTypeTraversalAndLiftImpls! {
|
||||
Cache,
|
||||
}
|
||||
TrivialTypeTraversalAndLiftImpls! { Cache }
|
||||
|
||||
impl<S: Encoder> Encodable<S> for Cache {
|
||||
#[inline]
|
||||
|
|
|
@ -66,9 +66,7 @@ impl Into<ErrorGuaranteed> for ReportedErrorInfo {
|
|||
}
|
||||
}
|
||||
|
||||
TrivialTypeTraversalAndLiftImpls! {
|
||||
ErrorHandled,
|
||||
}
|
||||
TrivialTypeTraversalAndLiftImpls! { ErrorHandled }
|
||||
|
||||
pub type EvalToAllocationRawResult<'tcx> = Result<ConstAlloc<'tcx>, ErrorHandled>;
|
||||
pub type EvalToConstValueResult<'tcx> = Result<ConstValue<'tcx>, ErrorHandled>;
|
||||
|
|
|
@ -706,9 +706,7 @@ pub enum BindingForm<'tcx> {
|
|||
RefForGuard,
|
||||
}
|
||||
|
||||
TrivialTypeTraversalAndLiftImpls! {
|
||||
BindingForm<'tcx>,
|
||||
}
|
||||
TrivialTypeTraversalAndLiftImpls! { BindingForm<'tcx> }
|
||||
|
||||
mod binding_form_impl {
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
|
|
|
@ -649,46 +649,31 @@ pub enum ImplSource<'tcx, N> {
|
|||
/// for some type parameter. The `Vec<N>` represents the
|
||||
/// obligations incurred from normalizing the where-clause (if
|
||||
/// any).
|
||||
Param(Vec<N>, ty::BoundConstness),
|
||||
Param(ty::BoundConstness, Vec<N>),
|
||||
|
||||
/// Virtual calls through an object.
|
||||
Object(ImplSourceObjectData<N>),
|
||||
|
||||
/// Successful resolution for a builtin trait.
|
||||
Builtin(Vec<N>),
|
||||
|
||||
// Unsizing a tuple like `(A, B, ..., X)` to `(A, B, ..., Y)` if `X` unsizes to `Y`
|
||||
TupleUnsizing(Vec<N>),
|
||||
|
||||
/// ImplSource for trait upcasting coercion
|
||||
TraitUpcasting(ImplSourceTraitUpcastingData<N>),
|
||||
/// Successful resolution for a builtin impl.
|
||||
Builtin(BuiltinImplSource, Vec<N>),
|
||||
}
|
||||
|
||||
impl<'tcx, N> ImplSource<'tcx, N> {
|
||||
pub fn nested_obligations(self) -> Vec<N> {
|
||||
match self {
|
||||
ImplSource::UserDefined(i) => i.nested,
|
||||
ImplSource::Param(n, _) | ImplSource::Builtin(n) | ImplSource::TupleUnsizing(n) => n,
|
||||
ImplSource::Object(d) => d.nested,
|
||||
ImplSource::TraitUpcasting(d) => d.nested,
|
||||
ImplSource::Param(_, n) | ImplSource::Builtin(_, n) => n,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn borrow_nested_obligations(&self) -> &[N] {
|
||||
match self {
|
||||
ImplSource::UserDefined(i) => &i.nested,
|
||||
ImplSource::Param(n, _) | ImplSource::Builtin(n) | ImplSource::TupleUnsizing(n) => &n,
|
||||
ImplSource::Object(d) => &d.nested,
|
||||
ImplSource::TraitUpcasting(d) => &d.nested,
|
||||
ImplSource::Param(_, n) | ImplSource::Builtin(_, n) => &n,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn borrow_nested_obligations_mut(&mut self) -> &mut [N] {
|
||||
match self {
|
||||
ImplSource::UserDefined(i) => &mut i.nested,
|
||||
ImplSource::Param(n, _) | ImplSource::Builtin(n) | ImplSource::TupleUnsizing(n) => n,
|
||||
ImplSource::Object(d) => &mut d.nested,
|
||||
ImplSource::TraitUpcasting(d) => &mut d.nested,
|
||||
ImplSource::Param(_, n) | ImplSource::Builtin(_, n) => n,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -702,20 +687,9 @@ impl<'tcx, N> ImplSource<'tcx, N> {
|
|||
args: i.args,
|
||||
nested: i.nested.into_iter().map(f).collect(),
|
||||
}),
|
||||
ImplSource::Param(n, ct) => ImplSource::Param(n.into_iter().map(f).collect(), ct),
|
||||
ImplSource::Builtin(n) => ImplSource::Builtin(n.into_iter().map(f).collect()),
|
||||
ImplSource::TupleUnsizing(n) => {
|
||||
ImplSource::TupleUnsizing(n.into_iter().map(f).collect())
|
||||
}
|
||||
ImplSource::Object(o) => ImplSource::Object(ImplSourceObjectData {
|
||||
vtable_base: o.vtable_base,
|
||||
nested: o.nested.into_iter().map(f).collect(),
|
||||
}),
|
||||
ImplSource::TraitUpcasting(d) => {
|
||||
ImplSource::TraitUpcasting(ImplSourceTraitUpcastingData {
|
||||
vtable_vptr_slot: d.vtable_vptr_slot,
|
||||
nested: d.nested.into_iter().map(f).collect(),
|
||||
})
|
||||
ImplSource::Param(ct, n) => ImplSource::Param(ct, n.into_iter().map(f).collect()),
|
||||
ImplSource::Builtin(source, n) => {
|
||||
ImplSource::Builtin(source, n.into_iter().map(f).collect())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -739,30 +713,32 @@ pub struct ImplSourceUserDefinedData<'tcx, N> {
|
|||
pub nested: Vec<N>,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, Lift)]
|
||||
#[derive(TypeFoldable, TypeVisitable)]
|
||||
pub struct ImplSourceTraitUpcastingData<N> {
|
||||
/// The vtable is formed by concatenating together the method lists of
|
||||
/// the base object trait and all supertraits, pointers to supertrait vtable will
|
||||
/// be provided when necessary; this is the position of `upcast_trait_ref`'s vtable
|
||||
/// within that vtable.
|
||||
pub vtable_vptr_slot: Option<usize>,
|
||||
|
||||
pub nested: Vec<N>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, TyEncodable, TyDecodable, HashStable, Lift)]
|
||||
#[derive(TypeFoldable, TypeVisitable)]
|
||||
pub struct ImplSourceObjectData<N> {
|
||||
#[derive(Copy, Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, Debug)]
|
||||
pub enum BuiltinImplSource {
|
||||
/// Some builtin impl we don't need to differentiate. This should be used
|
||||
/// unless more specific information is necessary.
|
||||
Misc,
|
||||
/// A builtin impl for trait objects.
|
||||
///
|
||||
/// The vtable is formed by concatenating together the method lists of
|
||||
/// the base object trait and all supertraits, pointers to supertrait vtable will
|
||||
/// be provided when necessary; this is the start of `upcast_trait_ref`'s methods
|
||||
/// in that vtable.
|
||||
pub vtable_base: usize,
|
||||
|
||||
pub nested: Vec<N>,
|
||||
Object { vtable_base: usize },
|
||||
/// The vtable is formed by concatenating together the method lists of
|
||||
/// the base object trait and all supertraits, pointers to supertrait vtable will
|
||||
/// be provided when necessary; this is the position of `upcast_trait_ref`'s vtable
|
||||
/// within that vtable.
|
||||
TraitUpcasting { vtable_vptr_slot: Option<usize> },
|
||||
/// Unsizing a tuple like `(A, B, ..., X)` to `(A, B, ..., Y)` if `X` unsizes to `Y`.
|
||||
///
|
||||
/// This needs to be a separate variant as it is still unstable and we need to emit
|
||||
/// a feature error when using it on stable.
|
||||
TupleUnsizing,
|
||||
}
|
||||
|
||||
TrivialTypeTraversalAndLiftImpls! { BuiltinImplSource }
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, HashStable, PartialOrd, Ord)]
|
||||
pub enum ObjectSafetyViolation {
|
||||
/// `Self: Sized` declared on the trait.
|
||||
|
|
|
@ -304,9 +304,7 @@ impl From<ErrorGuaranteed> for OverflowError {
|
|||
}
|
||||
}
|
||||
|
||||
TrivialTypeTraversalAndLiftImpls! {
|
||||
OverflowError,
|
||||
}
|
||||
TrivialTypeTraversalAndLiftImpls! { OverflowError }
|
||||
|
||||
impl<'tcx> From<OverflowError> for SelectionError<'tcx> {
|
||||
fn from(overflow_error: OverflowError) -> SelectionError<'tcx> {
|
||||
|
|
|
@ -6,20 +6,16 @@ use std::fmt;
|
|||
|
||||
impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSource<'tcx, N> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match *self {
|
||||
super::ImplSource::UserDefined(ref v) => write!(f, "{:?}", v),
|
||||
match self {
|
||||
super::ImplSource::UserDefined(v) => write!(f, "{:?}", v),
|
||||
|
||||
super::ImplSource::Builtin(ref d) => write!(f, "{:?}", d),
|
||||
|
||||
super::ImplSource::Object(ref d) => write!(f, "{:?}", d),
|
||||
|
||||
super::ImplSource::Param(ref n, ct) => {
|
||||
write!(f, "ImplSourceParamData({:?}, {:?})", n, ct)
|
||||
super::ImplSource::Builtin(source, d) => {
|
||||
write!(f, "Builtin({source:?}, {d:?})")
|
||||
}
|
||||
|
||||
super::ImplSource::TupleUnsizing(ref d) => write!(f, "{:?}", d),
|
||||
|
||||
super::ImplSource::TraitUpcasting(ref d) => write!(f, "{:?}", d),
|
||||
super::ImplSource::Param(ct, n) => {
|
||||
write!(f, "ImplSourceParamData({:?}, {:?})", n, ct)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,23 +29,3 @@ impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceUserDefinedData<'tcx,
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: fmt::Debug> fmt::Debug for traits::ImplSourceTraitUpcastingData<N> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"ImplSourceTraitUpcastingData(vtable_vptr_slot={:?}, nested={:?})",
|
||||
self.vtable_vptr_slot, self.nested
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: fmt::Debug> fmt::Debug for traits::ImplSourceObjectData<N> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"ImplSourceObjectData(vtable_base={}, nested={:?})",
|
||||
self.vtable_base, self.nested
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,9 +27,7 @@ impl From<ErrorGuaranteed> for NotConstEvaluatable {
|
|||
}
|
||||
}
|
||||
|
||||
TrivialTypeTraversalAndLiftImpls! {
|
||||
NotConstEvaluatable,
|
||||
}
|
||||
TrivialTypeTraversalAndLiftImpls! { NotConstEvaluatable }
|
||||
|
||||
pub type BoundAbstractConst<'tcx> = Result<Option<EarlyBinder<ty::Const<'tcx>>>, ErrorGuaranteed>;
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ pub enum BindingMode {
|
|||
BindByValue(Mutability),
|
||||
}
|
||||
|
||||
TrivialTypeTraversalAndLiftImpls! { BindingMode, }
|
||||
TrivialTypeTraversalAndLiftImpls! { BindingMode }
|
||||
|
||||
impl BindingMode {
|
||||
pub fn convert(BindingAnnotation(by_ref, mutbl): BindingAnnotation) -> BindingMode {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue