Skip to content

Commit 6b214bb

Browse files
committed
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.
1 parent a20a04e commit 6b214bb

File tree

5 files changed

+5
-56
lines changed

5 files changed

+5
-56
lines changed

library/core/src/mem/transmutability.rs

+1
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,

tests/ui/transmutability/references/recursive-wrapper-types-bit-compatible.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// check-fail
2-
// FIXME(bryangarza): Change to check-pass when coinduction is supported for BikeshedIntrinsicFrom
1+
// check-pass
32
#![feature(transmutability)]
43

54
mod assert {
@@ -22,5 +21,5 @@ mod assert {
2221
fn main() {
2322
#[repr(C)] struct A(bool, &'static A);
2423
#[repr(C)] struct B(u8, &'static B);
25-
assert::is_maybe_transmutable::<&'static A, &'static B>(); //~ ERROR overflow evaluating the requirement
24+
assert::is_maybe_transmutable::<&'static A, &'static B>();
2625
}

tests/ui/transmutability/references/recursive-wrapper-types-bit-compatible.stderr

-25
This file was deleted.

tests/ui/transmutability/references/recursive-wrapper-types.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// check-fail
2-
// FIXME(bryangarza): Change to check-pass when coinduction is supported for BikeshedIntrinsicFrom
1+
// check-pass
32
#![feature(transmutability)]
43

54
mod assert {
@@ -22,6 +21,6 @@ mod assert {
2221
fn main() {
2322
#[repr(C)] struct A(&'static B);
2423
#[repr(C)] struct B(&'static A);
25-
assert::is_maybe_transmutable::<&'static A, &'static B>(); //~ overflow evaluating the requirement
24+
assert::is_maybe_transmutable::<&'static A, &'static B>();
2625
assert::is_maybe_transmutable::<&'static B, &'static A>();
2726
}

tests/ui/transmutability/references/recursive-wrapper-types.stderr

-25
This file was deleted.

0 commit comments

Comments
 (0)