2025-01-31 01:24:37 +00:00
|
|
|
#![feature(unsafe_binders)]
|
2025-02-06 21:19:21 +00:00
|
|
|
//~^ WARN the feature `unsafe_binders` is incomplete
|
2025-01-31 01:24:37 +00:00
|
|
|
|
2025-02-06 21:19:21 +00:00
|
|
|
use std::mem::{ManuallyDrop, drop};
|
|
|
|
use std::unsafe_binder::{unwrap_binder, wrap_binder};
|
2025-01-31 01:24:37 +00:00
|
|
|
|
2025-02-06 21:19:21 +00:00
|
|
|
#[derive(Default)]
|
2025-01-31 02:04:10 +00:00
|
|
|
struct NotCopyInner;
|
|
|
|
type NotCopy = ManuallyDrop<NotCopyInner>;
|
2025-01-31 01:24:37 +00:00
|
|
|
|
|
|
|
fn use_after_wrap() {
|
|
|
|
unsafe {
|
2025-02-06 21:19:21 +00:00
|
|
|
let base = NotCopy::default();
|
2025-01-31 01:24:37 +00:00
|
|
|
let binder: unsafe<> NotCopy = wrap_binder!(base);
|
|
|
|
drop(base);
|
2025-02-06 21:19:21 +00:00
|
|
|
//~^ ERROR use of moved value: `base`
|
2025-01-31 01:24:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn move_out_of_wrap() {
|
|
|
|
unsafe {
|
2025-02-06 21:19:21 +00:00
|
|
|
let binder: unsafe<> NotCopy = wrap_binder!(NotCopy::default());
|
2025-01-31 01:24:37 +00:00
|
|
|
drop(unwrap_binder!(binder));
|
|
|
|
drop(unwrap_binder!(binder));
|
2025-02-06 21:19:21 +00:00
|
|
|
//~^ ERROR use of moved value: `binder`
|
2025-01-31 01:24:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn not_conflicting() {
|
|
|
|
unsafe {
|
2025-02-06 21:19:21 +00:00
|
|
|
let binder: unsafe<> (NotCopy, NotCopy) =
|
|
|
|
wrap_binder!((NotCopy::default(), NotCopy::default()));
|
2025-01-31 01:24:37 +00:00
|
|
|
drop(unwrap_binder!(binder).0);
|
|
|
|
drop(unwrap_binder!(binder).1);
|
2025-02-06 21:19:21 +00:00
|
|
|
// ^ NOT a problem, since the moves are disjoint.
|
2025-01-31 01:24:37 +00:00
|
|
|
drop(unwrap_binder!(binder).0);
|
2025-02-06 21:19:21 +00:00
|
|
|
//~^ ERROR use of moved value: `binder.0`
|
2025-01-31 01:24:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|