forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#134642 - kpreid:pointerlike-cell, r=compile…
…r-errors 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`. Please let me know if there are further sorts of tests that should be written, or other care that should be taken with this change. It is unfortunately not possible without compiler changes to implement `PointerLike` for `Atomic*` types, since they are not `repr(transparent)` (and, in theory if not in practice, `AtomicUsize`'s alignment may be greater than that of an ordinary pointer or `usize`). * Implementing `PointerLike` for `NonNull` is useful for pointer types which wrap `NonNull`. * Implementing `PointerLike` for `isize` is just for completeness; I have no use cases in mind, but I cannot think of any reason not to do this. * Tracking issue: rust-lang#102425 `@rustbot` label +F-dyn_star (there is no label or tracking issue for F-pointer_like_trait)
- Loading branch information
Showing
6 changed files
with
53 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// 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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters