Skip to content

Commit 64bee8c

Browse files
committed
Auto merge of #113175 - bryangarza:safe-transmute-rustc-coinductive, r=compiler-errors
Enable coinduction support for Safe Transmute This patch adds the `#[rustc_coinductive]` annotation to `BikeshedIntrinsicFrom`, so that it's possible to compute transmutability for recursive types. ## Motivation Safe Transmute currently already supports references (#110662). However, if a type is implemented recursively, it leads to an infinite loop when we try to check if transmutation is safe. A couple simple examples that one might want to write, that are currently not possible to check transmutability for: ```rs #[repr(C)] struct A(&'static B); #[repr(C)] struct B(&'static A); ``` ```rs #[repr(C)] enum IList<'a> { Nil, Cons(isize, &'a IList<'a>) } #[repr(C)] enum UList<'a> { Nil, Cons(usize, &'a UList<'a>) } ``` Previously, `@jswrenn` was considering writing a co-inductive solver from scratch, just for the `rustc_tranmsute` crate. Later on as I started working on Safe Transmute myself, I came across the `#[rustc_coinductive]` annotation, which is currently only being used for the `Sized` trait. Leveraging this trait actually solved the problem entirely, and it saves a lot of duplicate work that would have had to happen in `rustc_transmute`.
2 parents 046c106 + 693211a commit 64bee8c

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

core/src/mem/transmutability.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::marker::ConstParamTy;
99
#[lang = "transmute_trait"]
1010
#[cfg_attr(not(bootstrap), rustc_deny_explicit_impl(implement_via_object = false))]
1111
#[cfg_attr(bootstrap, rustc_deny_explicit_impl)]
12+
#[rustc_coinductive]
1213
pub unsafe trait BikeshedIntrinsicFrom<Src, Context, const ASSUME: Assume = { Assume::NOTHING }>
1314
where
1415
Src: ?Sized,

0 commit comments

Comments
 (0)