about summary refs log tree commit diff
path: root/compiler/rustc_transmute/src/layout/mod.rs
diff options
context:
space:
mode:
authorBryan Garza <1396101+bryangarza@users.noreply.github.com>2023-04-28 14:06:10 -0700
committerBryan Garza <1396101+bryangarza@users.noreply.github.com>2023-05-24 15:00:06 -0700
commit62663582375d7dedf42c0a30bfe04c7b53b452d7 (patch)
tree13ef5c8eff65f92a698a0d29e87823cbfda92d45 /compiler/rustc_transmute/src/layout/mod.rs
parentdb3275c962eae006a7502f89f2eaf07af2d0f1dd (diff)
downloadrust-62663582375d7dedf42c0a30bfe04c7b53b452d7.tar.gz
rust-62663582375d7dedf42c0a30bfe04c7b53b452d7.zip
Safe Transmute: Check mutability before creating dst -> src obligation
- Only create dst -> src obligation if Dst is mutable
- Add some long comments to explain parts of the transmutability code that were
  unclear to me when reading
- Update/add tests
Diffstat (limited to 'compiler/rustc_transmute/src/layout/mod.rs')
-rw-r--r--compiler/rustc_transmute/src/layout/mod.rs15
1 files changed, 9 insertions, 6 deletions
diff --git a/compiler/rustc_transmute/src/layout/mod.rs b/compiler/rustc_transmute/src/layout/mod.rs
index b318447e581..76d97e0e6e7 100644
--- a/compiler/rustc_transmute/src/layout/mod.rs
+++ b/compiler/rustc_transmute/src/layout/mod.rs
@@ -31,18 +31,21 @@ impl fmt::Debug for Byte {
 
 pub(crate) trait Def: Debug + Hash + Eq + PartialEq + Copy + Clone {}
 pub trait Ref: Debug + Hash + Eq + PartialEq + Copy + Clone {
+    fn min_align(&self) -> usize;
+
+    fn is_mutable(&self) -> bool;
+}
+
+impl Def for ! {}
+impl Ref for ! {
     fn min_align(&self) -> usize {
-        1
+        unreachable!()
     }
-
     fn is_mutable(&self) -> bool {
-        false
+        unreachable!()
     }
 }
 
-impl Def for ! {}
-impl Ref for ! {}
-
 #[cfg(feature = "rustc")]
 pub mod rustc {
     use rustc_middle::mir::Mutability;