diff options
| author | Ulrik Sverdrup <root@localhost> | 2015-02-13 20:31:09 +0100 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2015-02-14 11:32:42 +1100 |
| commit | 7a52932f4cd65f57bcc8d77f12e32066b2a9c432 (patch) | |
| tree | 383cdfcd296f2d0eb92f59fbfbfe3048d14b425c /src/libcore | |
| parent | 5e3ae102dbeeb646e8c7d2d423cea263337a76af (diff) | |
| download | rust-7a52932f4cd65f57bcc8d77f12e32066b2a9c432.tar.gz rust-7a52932f4cd65f57bcc8d77f12e32066b2a9c432.zip | |
Make std::raw::Repr an unsafe trait
The default implementation of .repr() will call conveniently call transmute_copy which should be appropriate for all implementors, but is memory unsafe if used wrong. Fixes #22260 You need to use `unsafe impl` to implement the Repr trait now. [breaking-change]
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/raw.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/libcore/raw.rs b/src/libcore/raw.rs index 81edfe7d6e2..bb0c22d3561 100644 --- a/src/libcore/raw.rs +++ b/src/libcore/raw.rs @@ -154,7 +154,7 @@ pub struct TraitObject { /// This trait is meant to map equivalences between raw structs and their /// corresponding rust values. -pub trait Repr<T> { +pub unsafe trait Repr<T> { /// This function "unwraps" a rust value (without consuming it) into its raw /// struct representation. This can be used to read/write different values /// for the struct. This is a safe method because by default it does not @@ -163,5 +163,5 @@ pub trait Repr<T> { fn repr(&self) -> T { unsafe { mem::transmute_copy(&self) } } } -impl<T> Repr<Slice<T>> for [T] {} -impl Repr<Slice<u8>> for str {} +unsafe impl<T> Repr<Slice<T>> for [T] {} +unsafe impl Repr<Slice<u8>> for str {} |
