mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-13 10:29:16 +00:00

Implementing `PointerLike` for `UnsafeCell` enables the possibility of interior mutable `dyn*` values. Since this means potentially exercising new codegen behavior, I added a test for it in `tests/ui/dyn-star/cell.rs`. Also updated UI tests to account for the `isize` implementation changing error messages.
35 lines
577 B
Rust
35 lines
577 B
Rust
// This test with Cell also indirectly exercises UnsafeCell in dyn*.
|
|
//
|
|
//@ run-pass
|
|
|
|
#![feature(dyn_star)]
|
|
#![allow(incomplete_features)]
|
|
|
|
use std::cell::Cell;
|
|
|
|
trait Rw<T> {
|
|
fn read(&self) -> T;
|
|
fn write(&self, v: T);
|
|
}
|
|
|
|
impl<T: Copy> Rw<T> for Cell<T> {
|
|
fn read(&self) -> T {
|
|
self.get()
|
|
}
|
|
fn write(&self, v: T) {
|
|
self.set(v)
|
|
}
|
|
}
|
|
|
|
fn make_dyn_star() -> dyn* Rw<usize> {
|
|
Cell::new(42usize) as dyn* Rw<usize>
|
|
}
|
|
|
|
fn main() {
|
|
let x = make_dyn_star();
|
|
|
|
assert_eq!(x.read(), 42);
|
|
x.write(24);
|
|
assert_eq!(x.read(), 24);
|
|
}
|