rust/src/liballoc
Manish Goregaokar 6556f26991
Rollup merge of #73678 - Keno:patch-1, r=LukasKalbertodt
Update Box::from_raw example to generalize better

I know very little about rust, so I saw the example here
```
use std::alloc::{alloc, Layout};

unsafe {
    let ptr = alloc(Layout:🆕:<i32>()) as *mut i32;
    *ptr = 5;
    let x = Box::from_raw(ptr);
}
```
and tried to generalize it by writing,
```
    let layout = Layout:🆕:<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 think that changing this example to use `.write` instead
would be a good idea to suggest the correct generalization. It is also more
consistent with other documentation items in this file, which use `.write`.
I also added a comment to explain it, but I'm not too attached to that,
and can see it being too verbose in this place.
2020-07-01 07:42:42 -07:00
..
alloc liballoc tests: Miri supports threads now 2020-05-01 11:16:38 +02:00
benches disable collectionbenches for android 2020-06-25 11:14:16 -07:00
collections Shortcuts for min/max on ordinary BTreeMap/BTreeSet iterators 2020-06-26 10:05:21 +02:00
prelude Format liballoc with rustfmt 2019-11-29 20:25:07 -08:00
raw_vec Remove blank line 2020-06-26 06:22:35 -07:00
rc Migrate to numeric associated consts 2020-06-10 01:35:47 +00:00
sync Migrate to numeric associated consts 2020-06-10 01:35:47 +00:00
tests Rollup merge of #73466 - matthiaskrgr:char_into_string, r=dtolnay 2020-07-01 07:42:36 -07:00
alloc.rs Apply suggestions from code review 2020-06-19 13:47:04 +02:00
borrow.rs Format the world 2019-12-22 17:42:47 -05:00
boxed.rs Rollup merge of #73678 - Keno:patch-1, r=LukasKalbertodt 2020-07-01 07:42:42 -07:00
Cargo.toml Ensure std benchmarks get tested. 2020-06-18 09:11:15 -07:00
fmt.rs grammar: dealing-with 2020-05-06 19:01:27 -04:00
lib.rs Remove const_if_match feature gate from libraries 2020-06-28 10:08:09 -07:00
macros.rs make vec![,] uncompilable 2020-04-14 10:27:55 +03:00
raw_vec.rs Auto merge of #73391 - pickfire:liballoc-panic-doc, r=Mark-Simulacrum 2020-06-29 12:00:31 +00:00
rc.rs #[deny(unsafe_op_in_unsafe_fn)] in liballoc 2020-06-19 13:47:01 +02:00
slice.rs #[deny(unsafe_op_in_unsafe_fn)] in liballoc 2020-06-19 13:47:01 +02:00
str.rs #[deny(unsafe_op_in_unsafe_fn)] in liballoc 2020-06-19 13:47:01 +02:00
string.rs Rollup merge of #73466 - matthiaskrgr:char_into_string, r=dtolnay 2020-07-01 07:42:36 -07:00
sync.rs #[deny(unsafe_op_in_unsafe_fn)] in liballoc 2020-06-19 13:47:01 +02:00
task.rs #[deny(unsafe_op_in_unsafe_fn)] in liballoc 2020-06-19 13:47:01 +02:00
tests.rs Stop importing integer modules in liballoc 2020-04-05 11:22:01 +02:00
vec.rs Auto merge of #73391 - pickfire:liballoc-panic-doc, r=Mark-Simulacrum 2020-06-29 12:00:31 +00:00