File tree 1 file changed +14
-5
lines changed
1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -65,23 +65,32 @@ pub use intrinsics::transmute;
65
65
///
66
66
/// # Example
67
67
///
68
- /// ```rust,no_run
68
+ /// ```rust
69
69
/// use std::mem;
70
- /// use std::fs::File;
71
70
///
72
71
/// // Leak some heap memory by never deallocating it
73
72
/// let heap_memory = Box::new(3);
74
73
/// mem::forget(heap_memory);
74
+ ///```
75
+ ///
76
+ /// ```rust,no_run
77
+ /// use std::mem;
78
+ /// use std::fs::File;
75
79
///
76
80
/// // Leak an I/O object, never closing the file
77
81
/// let file = File::open("foo.txt").unwrap();
78
82
/// mem::forget(file);
83
+ ///```
84
+ ///
85
+ ///```rust
86
+ /// use std::mem;
87
+ /// use std::ptr;
79
88
///
80
89
/// // The swap function uses forget
81
- /// fn swap<T>(x: &mut T, y: &mut T) {
90
+ /// pub fn swap<T>(x: &mut T, y: &mut T) {
82
91
/// unsafe {
83
92
/// // Give ourselves some scratch space to work with
84
- /// let mut t: T = uninitialized();
93
+ /// let mut t: T = mem:: uninitialized();
85
94
///
86
95
/// // Perform the swap, `&mut` pointers never alias
87
96
/// ptr::copy_nonoverlapping(&*x, &mut t, 1);
@@ -91,7 +100,7 @@ pub use intrinsics::transmute;
91
100
/// // y and t now point to the same thing, but we need to completely
92
101
/// // forget `t` because we do not want to run the destructor for `T`
93
102
/// // on its value, which is still owned somewhere outside this function.
94
- /// forget(t);
103
+ /// mem:: forget(t);
95
104
/// }
96
105
/// }
97
106
/// ```
You can’t perform that action at this time.
0 commit comments