Skip to content

Commit 5d1d3ee

Browse files
committed
Break examples up to three pieces
This breaks the examples up into three pieces. The last piece isn't compiling for some reason.
1 parent 935f7a5 commit 5d1d3ee

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/libcore/mem.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,32 @@ pub use intrinsics::transmute;
6565
///
6666
/// # Example
6767
///
68-
/// ```rust,no_run
68+
/// ```rust
6969
/// use std::mem;
70-
/// use std::fs::File;
7170
///
7271
/// // Leak some heap memory by never deallocating it
7372
/// let heap_memory = Box::new(3);
7473
/// mem::forget(heap_memory);
74+
///```
75+
///
76+
/// ```rust,no_run
77+
/// use std::mem;
78+
/// use std::fs::File;
7579
///
7680
/// // Leak an I/O object, never closing the file
7781
/// let file = File::open("foo.txt").unwrap();
7882
/// mem::forget(file);
83+
///```
84+
///
85+
///```rust
86+
/// use std::mem;
87+
/// use std::ptr;
7988
///
8089
/// // 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) {
8291
/// unsafe {
8392
/// // Give ourselves some scratch space to work with
84-
/// let mut t: T = uninitialized();
93+
/// let mut t: T = mem::uninitialized();
8594
///
8695
/// // Perform the swap, `&mut` pointers never alias
8796
/// ptr::copy_nonoverlapping(&*x, &mut t, 1);
@@ -91,7 +100,7 @@ pub use intrinsics::transmute;
91100
/// // y and t now point to the same thing, but we need to completely
92101
/// // forget `t` because we do not want to run the destructor for `T`
93102
/// // on its value, which is still owned somewhere outside this function.
94-
/// forget(t);
103+
/// mem::forget(t);
95104
/// }
96105
/// }
97106
/// ```

0 commit comments

Comments
 (0)