@@ -29,6 +29,19 @@ pub use intrinsics::transmute;
29
29
/// `mem::drop` function in that it **does not run the destructor**, leaking the
30
30
/// value and any resources that it owns.
31
31
///
32
+ /// There's only a few reasons to use this function. They mainly come
33
+ /// up in unsafe code or FFI code.
34
+ ///
35
+ /// * You have an uninitialized value, perhaps for performance reasons, and
36
+ /// need to prevent the destructor from running on it.
37
+ /// * You have two copies of a value (like when writing something like
38
+ /// [`mem::swap`][swap]), but need the destructor to only run once to
39
+ /// prevent a double `free`.
40
+ /// * Transferring resources across [FFI][ffi] boundries.
41
+ ///
42
+ /// [swap]: fn.swap.html
43
+ /// [ffi]: ../../book/ffi.html
44
+ ///
32
45
/// # Safety
33
46
///
34
47
/// This function is not marked as `unsafe` as Rust does not guarantee that the
@@ -52,20 +65,9 @@ pub use intrinsics::transmute;
52
65
/// * `mpsc::{Sender, Receiver}` cycles (they use `Arc` internally)
53
66
/// * Panicking destructors are likely to leak local resources
54
67
///
55
- /// # When To Use
56
- ///
57
- /// There's only a few reasons to use this function. They mainly come
58
- /// up in unsafe code or FFI code.
59
- ///
60
- /// * You have an uninitialized value, perhaps for performance reasons, and
61
- /// need to prevent the destructor from running on it.
62
- /// * You have two copies of a value (like `std::mem::swap`), but need the
63
- /// destructor to only run once to prevent a double free.
64
- /// * Transferring resources across FFI boundries.
65
- ///
66
68
/// # Example
67
69
///
68
- /// Leak some heap memory by never deallocating it.
70
+ /// Leak some heap memory by never deallocating it:
69
71
///
70
72
/// ```rust
71
73
/// use std::mem;
@@ -74,7 +76,7 @@ pub use intrinsics::transmute;
74
76
/// mem::forget(heap_memory);
75
77
/// ```
76
78
///
77
- /// Leak an I/O object, never closing the file.
79
+ /// Leak an I/O object, never closing the file:
78
80
///
79
81
/// ```rust,no_run
80
82
/// use std::mem;
@@ -84,7 +86,7 @@ pub use intrinsics::transmute;
84
86
/// mem::forget(file);
85
87
/// ```
86
88
///
87
- /// The swap function uses forget to good effect.
89
+ /// The `mem:: swap` function uses `mem:: forget` to good effect:
88
90
///
89
91
/// ```rust
90
92
/// use std::mem;
0 commit comments