@@ -79,7 +79,7 @@ let ref_2: &mut u8 = unsafe { mem::transmute(&mut *ref_1) };
7979## Raw pointers
8080
8181Rust offers two additional pointer types "raw pointers", written as
82- ` *T ` and ` *mut T ` . They're an approximation of C's ` const T* ` and ` T* `
82+ ` *const T ` and ` *mut T ` . They're an approximation of C's ` const T* ` and ` T* `
8383respectively; indeed, one of their most common uses is for FFI,
8484interfacing with external C libraries.
8585
@@ -100,7 +100,7 @@ offered by the Rust language and libraries. For example, they
100100- lack any form of lifetimes, unlike ` & ` , and so the compiler cannot
101101 reason about dangling pointers; and
102102- have no guarantees about aliasing or mutability other than mutation
103- not being allowed directly through a ` *T ` .
103+ not being allowed directly through a ` *const T ` .
104104
105105Fortunately, they come with a redeeming feature: the weaker guarantees
106106mean weaker restrictions. The missing restrictions make raw pointers
@@ -131,13 +131,13 @@ unsafe, and neither is converting to an integer.
131131
132132At runtime, a raw pointer ` * ` and a reference pointing to the same
133133piece of data have an identical representation. In fact, an ` &T `
134- reference will implicitly coerce to an ` *T ` raw pointer in safe code
134+ reference will implicitly coerce to an ` *const T ` raw pointer in safe code
135135and similarly for the ` mut ` variants (both coercions can be performed
136- explicitly with, respectively, ` value as *T ` and ` value as *mut T ` ).
136+ explicitly with, respectively, ` value as *const T ` and ` value as *mut T ` ).
137137
138- Going the opposite direction, from ` * ` to a reference ` & ` , is not
138+ Going the opposite direction, from ` *const ` to a reference ` & ` , is not
139139safe. A ` &T ` is always valid, and so, at a minimum, the raw pointer
140- ` *T ` has to be a valid to a valid instance of type ` T ` . Furthermore,
140+ ` *const T ` has to be a valid to a valid instance of type ` T ` . Furthermore,
141141the resulting pointer must satisfy the aliasing and mutability laws of
142142references. The compiler assumes these properties are true for any
143143references, no matter how they are created, and so any conversion from
@@ -149,7 +149,7 @@ The recommended method for the conversion is
149149```
150150let i: u32 = 1;
151151// explicit cast
152- let p_imm: *u32 = &i as *u32;
152+ let p_imm: *const u32 = &i as *const u32;
153153let mut m: u32 = 2;
154154// implicit coercion
155155let p_mut: *mut u32 = &mut m;
@@ -256,7 +256,7 @@ impl<T: Send> Drop for Unique<T> {
256256 // Copy the object out from the pointer onto the stack,
257257 // where it is covered by normal Rust destructor semantics
258258 // and cleans itself up, if necessary
259- ptr::read(self.ptr as *T);
259+ ptr::read(self.ptr as *const T);
260260
261261 // clean-up our allocation
262262 free(self.ptr as *mut c_void)
@@ -457,7 +457,7 @@ extern crate libc;
457457
458458// Entry point for this program
459459#[start]
460- fn start(_argc: int, _argv: ** u8) -> int {
460+ fn start(_argc: int, _argv: *const *const u8) -> int {
461461 0
462462}
463463
@@ -482,7 +482,7 @@ compiler's name mangling too:
482482extern crate libc;
483483
484484#[no_mangle] // ensure that this symbol is called `main` in the output
485- pub extern fn main(argc: int, argv: ** u8) -> int {
485+ pub extern fn main(argc: int, argv: *const *const u8) -> int {
486486 0
487487}
488488
@@ -540,8 +540,8 @@ use core::mem;
540540use core::raw::Slice;
541541
542542#[no_mangle]
543- pub extern fn dot_product(a: *u32, a_len: u32,
544- b: *u32, b_len: u32) -> u32 {
543+ pub extern fn dot_product(a: *const u32, a_len: u32,
544+ b: *const u32, b_len: u32) -> u32 {
545545 // Convert the provided arrays into Rust slices.
546546 // The core::raw module guarantees that the Slice
547547 // structure has the same memory layout as a &[T]
@@ -573,7 +573,7 @@ extern fn begin_unwind(args: &core::fmt::Arguments,
573573
574574#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
575575#[lang = "eh_personality"] extern fn eh_personality() {}
576- # #[start] fn start(argc: int, argv: ** u8) -> int { 0 }
576+ # #[start] fn start(argc: int, argv: *const *const u8) -> int { 0 }
577577# fn main() {}
578578```
579579
@@ -595,7 +595,7 @@ standard library itself.
595595> parts of the language may never be full specified and so details may
596596> differ wildly between implementations (and even versions of ` rustc `
597597> itself).
598- >
598+ >
599599> Furthermore, this is just an overview; the best form of
600600> documentation for specific instances of these features are their
601601> definitions and uses in ` std ` .
@@ -627,7 +627,7 @@ via a declaration like
627627extern "rust-intrinsic" {
628628 fn transmute<T, U>(x: T) -> U;
629629
630- fn offset<T>(dst: *T, offset: int) -> *T;
630+ fn offset<T>(dst: *const T, offset: int) -> *const T;
631631}
632632```
633633
@@ -677,7 +677,7 @@ unsafe fn deallocate(ptr: *mut u8, _size: uint, _align: uint) {
677677}
678678
679679#[start]
680- fn main(argc: int, argv: ** u8) -> int {
680+ fn main(argc: int, argv: *const *const u8) -> int {
681681 let x = box 1;
682682
683683 0
0 commit comments