Initial (incomplete) implementation of transmutability trait.

This initial implementation handles transmutations between types with specified layouts, except when references are involved.

Co-authored-by: Igor null <m1el.2027@gmail.com>
This commit is contained in:
Jack Wrenn
2021-07-03 12:18:13 -04:00
parent 2a220937c2
commit bc4a1dea41
91 changed files with 5691 additions and 2 deletions

View File

@@ -109,6 +109,10 @@ pub enum SelectionCandidate<'tcx> {
/// `false` if there are no *further* obligations.
has_nested: bool,
},
/// Implementation of transmutability trait.
TransmutabilityCandidate,
ParamCandidate(ty::PolyTraitPredicate<'tcx>),
ImplCandidate(DefId),
AutoImplCandidate(DefId),

View File

@@ -48,7 +48,7 @@ pub use subst::*;
pub use vtable::*;
use std::fmt::Debug;
use std::hash::Hash;
use std::hash::{Hash, Hasher};
use std::ops::ControlFlow;
use std::{fmt, str};
@@ -1724,6 +1724,26 @@ impl VariantDef {
}
}
/// There should be only one VariantDef for each `def_id`, therefore
/// it is fine to implement `PartialEq` only based on `def_id`.
impl PartialEq for VariantDef {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.def_id == other.def_id
}
}
impl Eq for VariantDef {}
/// There should be only one VariantDef for each `def_id`, therefore
/// it is fine to implement `Hash` only based on `def_id`.
impl Hash for VariantDef {
#[inline]
fn hash<H: Hasher>(&self, s: &mut H) {
self.def_id.hash(s)
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, HashStable)]
pub enum VariantDiscr {
/// Explicit value for this variant, i.e., `X = 123`.
@@ -1744,6 +1764,26 @@ pub struct FieldDef {
pub vis: Visibility,
}
/// There should be only one FieldDef for each `did`, therefore
/// it is fine to implement `PartialEq` only based on `did`.
impl PartialEq for FieldDef {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.did == other.did
}
}
impl Eq for FieldDef {}
/// There should be only one FieldDef for each `did`, therefore
/// it is fine to implement `Hash` only based on `did`.
impl Hash for FieldDef {
#[inline]
fn hash<H: Hasher>(&self, s: &mut H) {
self.did.hash(s)
}
}
bitflags! {
#[derive(TyEncodable, TyDecodable, Default, HashStable)]
pub struct ReprFlags: u8 {