about summary refs log tree commit diff
path: root/src/rustllvm/CoverageMappingWrapper.cpp
diff options
context:
space:
mode:
authorKeno Fischer <keno@alumni.harvard.edu>2020-06-23 22:42:35 -0400
committerGitHub <noreply@github.com>2020-06-23 22:42:35 -0400
commit0c88dd663a7095ccc405a2036047a90981137a51 (patch)
treec7537df9ffecabee18820ad7ac8571fa1c434b02 /src/rustllvm/CoverageMappingWrapper.cpp
parent0c04344d86f9598f20d9ec86fe87ea2a5d6ff8e6 (diff)
downloadrust-0c88dd663a7095ccc405a2036047a90981137a51.tar.gz
rust-0c88dd663a7095ccc405a2036047a90981137a51.zip
Update Box::from_raw example to generalize better
I know very little about rust, so I saw this example and tried to generalize it by writing,
```
    let layout = Layout::new::<T>();
    let new_obj = unsafe {
        let ptr = alloc(layout) as *mut T;
        *ptr = obj;
        Box::from_raw(ptr)
    };
```
for some more complicated `T`, which ended up crashing with SIGSEGV,
because it tried to `drop_in_place` the previous object in `ptr` which is
of course garbage. I also added a comment that explains why `.write`
is used, but I think adding that comment is optional and may be too verbose
here. I do however think that changing this example is a good idea to
suggest the correct generalization. `.write` is also used in most of the rest
of the documentation here, even if the example is `i32`, so it would additionally
be more consistent.
Diffstat (limited to 'src/rustllvm/CoverageMappingWrapper.cpp')
0 files changed, 0 insertions, 0 deletions