about summary refs log tree commit diff
path: root/src/rustllvm/RustWrapper.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-09-24 18:55:00 +0000
committerbors <bors@rust-lang.org>2015-09-24 18:55:00 +0000
commit6a2187414a8c25f485dc788088b4466f595a7dd9 (patch)
tree26bd8b8f482cf15530b6417cd499fa09ce36d704 /src/rustllvm/RustWrapper.cpp
parente9801294a1e24ec8812b8bb827a5d6df5f9078a9 (diff)
parentb30d8969e86fa2c9dd3b8e2e28ddda2202331f0f (diff)
downloadrust-6a2187414a8c25f485dc788088b4466f595a7dd9.tar.gz
rust-6a2187414a8c25f485dc788088b4466f595a7dd9.zip
Auto merge of #28538 - alevy:make_fixedsizearray_unsafe, r=alexcrichton
[breaking-change]

`FixedSizeArray` is meant to be implemented for arrays of fixed size only, but can be implemented for anything at the moment. Marking the trait unsafe would make it more reasonable to write unsafe code which operates on fixed size arrays of any size.

For example, using `uninitialized` to create a fixed size array and immediately filling it with a fixed value is externally safe:

```
pub fn init_with_nones<T, A: FixedSizeArray<Option<T>>>() -> A {
    let mut res = unsafe { mem::uninitialized() };
    for elm in res.as_mut_slice().iter_mut() {
        *elm = None;
    }
    res
}
```

But the same code is not safe if `FixedSizeArray` is implemented for other types:

```
struct Foo { foo: usize }
impl FixedSizeArray<Option<usize>> for Foo {
    fn as_slice(&self) -> &[usize] { &[] }
    fn as_mut_slice(&self) -> &mut [usize] { &mut [] }
}
```

now `init_with_nones() : Foo` returns a `Foo` with an undefined value for the field `foo`.
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions