Skip to content

Commit fcf25ae

Browse files
committed
auto merge of #14019 : brson/rust/docs, r=alexcrichton
Just small bits of polish.
2 parents a990920 + 2aa4253 commit fcf25ae

File tree

4 files changed

+28
-47
lines changed

4 files changed

+28
-47
lines changed

src/libcore/cast.rs

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,6 @@ use mem;
1414
use intrinsics;
1515
use ptr::copy_nonoverlapping_memory;
1616

17-
/// Casts the value at `src` to U. The two types must have the same length.
18-
#[inline]
19-
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
20-
let mut dest: U = mem::uninit();
21-
let dest_ptr: *mut u8 = transmute(&mut dest);
22-
let src_ptr: *u8 = transmute(src);
23-
copy_nonoverlapping_memory(dest_ptr, src_ptr, mem::size_of::<U>());
24-
dest
25-
}
26-
27-
/**
28-
* Move a thing into the void
29-
*
30-
* The forget function will take ownership of the provided value but neglect
31-
* to run any required cleanup or memory-management operations on it.
32-
*/
33-
#[inline]
34-
pub unsafe fn forget<T>(thing: T) { intrinsics::forget(thing); }
35-
36-
/**
37-
* Force-increment the reference count on a shared box. If used
38-
* carelessly, this can leak the box.
39-
*/
40-
#[inline]
41-
pub unsafe fn bump_box_refcount<T>(t: @T) { forget(t); }
42-
4317
/**
4418
* Transform a value of one type into a value of another type.
4519
* Both types must have the same size and alignment.
@@ -54,10 +28,29 @@ pub unsafe fn bump_box_refcount<T>(t: @T) { forget(t); }
5428
* ```
5529
*/
5630
#[inline]
57-
pub unsafe fn transmute<L, G>(thing: L) -> G {
31+
pub unsafe fn transmute<T, U>(thing: T) -> U {
5832
intrinsics::transmute(thing)
5933
}
6034

35+
/**
36+
* Move a thing into the void
37+
*
38+
* The forget function will take ownership of the provided value but neglect
39+
* to run any required cleanup or memory-management operations on it.
40+
*/
41+
#[inline]
42+
pub unsafe fn forget<T>(thing: T) { intrinsics::forget(thing); }
43+
44+
/// Casts the value at `src` to U. The two types must have the same length.
45+
#[inline]
46+
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
47+
let mut dest: U = mem::uninit();
48+
let dest_ptr: *mut u8 = transmute(&mut dest);
49+
let src_ptr: *u8 = transmute(src);
50+
copy_nonoverlapping_memory(dest_ptr, src_ptr, mem::size_of::<U>());
51+
dest
52+
}
53+
6154
/// Coerce an immutable reference to be mutable.
6255
#[inline]
6356
#[deprecated="casting &T to &mut T is undefined behaviour: use Cell<T>, RefCell<T> or Unsafe<T>"]
@@ -106,7 +99,7 @@ pub unsafe fn copy_lifetime_vec<'a,S,T>(_ptr: &'a [S], ptr: &T) -> &'a T {
10699

107100
#[cfg(test)]
108101
mod tests {
109-
use cast::{bump_box_refcount, transmute};
102+
use cast::transmute;
110103
use raw;
111104
use realstd::str::StrAllocating;
112105

@@ -115,21 +108,6 @@ mod tests {
115108
assert_eq!(1u, unsafe { ::cast::transmute_copy(&1) });
116109
}
117110

118-
#[test]
119-
fn test_bump_managed_refcount() {
120-
unsafe {
121-
let managed = @"box box box".to_owned(); // refcount 1
122-
bump_box_refcount(managed); // refcount 2
123-
let ptr: *int = transmute(managed); // refcount 2
124-
let _box1: @~str = ::cast::transmute_copy(&ptr);
125-
let _box2: @~str = ::cast::transmute_copy(&ptr);
126-
assert!(*_box1 == "box box box".to_owned());
127-
assert!(*_box2 == "box box box".to_owned());
128-
// Will destroy _box1 and _box2. Without the bump, this would
129-
// use-after-free. With too many bumps, it would leak.
130-
}
131-
}
132-
133111
#[test]
134112
fn test_transmute() {
135113
unsafe {

src/libcore/cell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Types dealing with dynamic mutability
11+
//! Types that provide interior mutability.
1212
1313
use clone::Clone;
1414
use cmp::Eq;

src/libcore/ptr.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// FIXME: talk about offset, copy_memory, copy_nonoverlapping_memory
12+
1113
//! Conveniences for working with unsafe pointers, the `*T`, and `*mut T` types.
1214
//!
1315
//! Working with unsafe pointers in Rust is fairly uncommon,

src/libstd/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
//! memory types, including [`atomics`](sync/atomics/index.html).
8282
//!
8383
//! Common types of I/O, including files, TCP, UPD, pipes, Unix domain sockets,
84-
//! timers, and process spawning, are defined in the [`io`](io/index.html).
84+
//! timers, and process spawning, are defined in the [`io`](io/index.html) module.
8585
//!
8686
//! Rust's I/O and concurrency depends on a small runtime interface
8787
//! that lives, along with its support code, in mod [`rt`](rt/index.html).
@@ -90,10 +90,11 @@
9090
//!
9191
//! ## The Rust prelude and macros
9292
//!
93-
//! Finally, the [`prelude`](prelude/index.html) defines a set of
93+
//! Finally, the [`prelude`](prelude/index.html) defines a
9494
//! common set of traits, types, and functions that are made available
9595
//! to all code by default. [`macros`](macros/index.html) contains
96-
//! all the standard macros, such as `assert!`, `fail!`, `println!`.
96+
//! all the standard macros, such as `assert!`, `fail!`, `println!`,
97+
//! and `format!`, also available to all Rust code.
9798
9899
#![crate_id = "std#0.11-pre"]
99100
#![comment = "The Rust standard library"]

0 commit comments

Comments
 (0)