rust/tests/ui/dyn-star/cell.rs
Kevin Reid 5c04151c6c Implement PointerLike for isize, NonNull, Cell, UnsafeCell, and SyncUnsafeCell.
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.
2024-12-22 11:18:56 -08:00

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);
}