From 6b214bbc1128aa6bd9ddf732396fda7230dfeb64 Mon Sep 17 00:00:00 2001 From: Bryan Garza <1396101+bryangarza@users.noreply.github.com> Date: Thu, 29 Jun 2023 15:01:39 -0700 Subject: [PATCH] Enable co-induction support for Safe Transmute This patch adds the `#[rustc_coinductive]` annotation to `BikeshedIntrinsicFrom`, so that it's possible to compute transmutability for recursive types. --- library/core/src/mem/transmutability.rs | 1 + .../recursive-wrapper-types-bit-compatible.rs | 5 ++-- ...ursive-wrapper-types-bit-compatible.stderr | 25 ------------------- .../references/recursive-wrapper-types.rs | 5 ++-- .../references/recursive-wrapper-types.stderr | 25 ------------------- 5 files changed, 5 insertions(+), 56 deletions(-) delete mode 100644 tests/ui/transmutability/references/recursive-wrapper-types-bit-compatible.stderr delete mode 100644 tests/ui/transmutability/references/recursive-wrapper-types.stderr diff --git a/library/core/src/mem/transmutability.rs b/library/core/src/mem/transmutability.rs index 3805d149b704e..aed23119fd293 100644 --- a/library/core/src/mem/transmutability.rs +++ b/library/core/src/mem/transmutability.rs @@ -9,6 +9,7 @@ use crate::marker::ConstParamTy; #[lang = "transmute_trait"] #[cfg_attr(not(bootstrap), rustc_deny_explicit_impl(implement_via_object = false))] #[cfg_attr(bootstrap, rustc_deny_explicit_impl)] +#[rustc_coinductive] pub unsafe trait BikeshedIntrinsicFrom where Src: ?Sized, diff --git a/tests/ui/transmutability/references/recursive-wrapper-types-bit-compatible.rs b/tests/ui/transmutability/references/recursive-wrapper-types-bit-compatible.rs index 3ea80173afaa9..709d8cdc762e9 100644 --- a/tests/ui/transmutability/references/recursive-wrapper-types-bit-compatible.rs +++ b/tests/ui/transmutability/references/recursive-wrapper-types-bit-compatible.rs @@ -1,5 +1,4 @@ -// check-fail -// FIXME(bryangarza): Change to check-pass when coinduction is supported for BikeshedIntrinsicFrom +// check-pass #![feature(transmutability)] mod assert { @@ -22,5 +21,5 @@ mod assert { fn main() { #[repr(C)] struct A(bool, &'static A); #[repr(C)] struct B(u8, &'static B); - assert::is_maybe_transmutable::<&'static A, &'static B>(); //~ ERROR overflow evaluating the requirement + assert::is_maybe_transmutable::<&'static A, &'static B>(); } diff --git a/tests/ui/transmutability/references/recursive-wrapper-types-bit-compatible.stderr b/tests/ui/transmutability/references/recursive-wrapper-types-bit-compatible.stderr deleted file mode 100644 index fae332e6af932..0000000000000 --- a/tests/ui/transmutability/references/recursive-wrapper-types-bit-compatible.stderr +++ /dev/null @@ -1,25 +0,0 @@ -error[E0275]: overflow evaluating the requirement `B: BikeshedIntrinsicFrom` - --> $DIR/recursive-wrapper-types-bit-compatible.rs:25:5 - | -LL | assert::is_maybe_transmutable::<&'static A, &'static B>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: required by a bound in `is_maybe_transmutable` - --> $DIR/recursive-wrapper-types-bit-compatible.rs:11:14 - | -LL | pub fn is_maybe_transmutable() - | --------------------- required by a bound in this function -LL | where -LL | Dst: BikeshedIntrinsicFrom - | |__________^ required by this bound in `is_maybe_transmutable` - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/transmutability/references/recursive-wrapper-types.rs b/tests/ui/transmutability/references/recursive-wrapper-types.rs index 59d1ad84a5d4c..090c1fea6dbdf 100644 --- a/tests/ui/transmutability/references/recursive-wrapper-types.rs +++ b/tests/ui/transmutability/references/recursive-wrapper-types.rs @@ -1,5 +1,4 @@ -// check-fail -// FIXME(bryangarza): Change to check-pass when coinduction is supported for BikeshedIntrinsicFrom +// check-pass #![feature(transmutability)] mod assert { @@ -22,6 +21,6 @@ mod assert { fn main() { #[repr(C)] struct A(&'static B); #[repr(C)] struct B(&'static A); - assert::is_maybe_transmutable::<&'static A, &'static B>(); //~ overflow evaluating the requirement + assert::is_maybe_transmutable::<&'static A, &'static B>(); assert::is_maybe_transmutable::<&'static B, &'static A>(); } diff --git a/tests/ui/transmutability/references/recursive-wrapper-types.stderr b/tests/ui/transmutability/references/recursive-wrapper-types.stderr deleted file mode 100644 index 35a60c226437a..0000000000000 --- a/tests/ui/transmutability/references/recursive-wrapper-types.stderr +++ /dev/null @@ -1,25 +0,0 @@ -error[E0275]: overflow evaluating the requirement `A: BikeshedIntrinsicFrom` - --> $DIR/recursive-wrapper-types.rs:25:5 - | -LL | assert::is_maybe_transmutable::<&'static A, &'static B>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: required by a bound in `is_maybe_transmutable` - --> $DIR/recursive-wrapper-types.rs:11:14 - | -LL | pub fn is_maybe_transmutable() - | --------------------- required by a bound in this function -LL | where -LL | Dst: BikeshedIntrinsicFrom - | |__________^ required by this bound in `is_maybe_transmutable` - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0275`.