Skip to content

Commit fe8bc17

Browse files
committed
auto merge of #15208 : alexcrichton/rust/snapshots, r=pcwalton
This change registers new snapshots, allowing `*T` to be removed from the language. This is a large breaking change, and it is recommended that if compiler errors are seen that any FFI calls are audited to determine whether they should be actually taking `*mut T`.
2 parents de337f3 + 0dfc90a commit fe8bc17

File tree

228 files changed

+1811
-1683
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

228 files changed

+1811
-1683
lines changed

src/compiletest/compiletest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub mod common;
4242
pub mod errors;
4343

4444
#[start]
45-
fn start(argc: int, argv: **u8) -> int {
45+
fn start(argc: int, argv: *const *const u8) -> int {
4646
green::start(argc, argv, rustuv::event_loop, main)
4747
}
4848

src/doc/guide-ffi.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@ use libc::{c_int, size_t};
5050
5151
#[link(name = "snappy")]
5252
extern {
53-
fn snappy_compress(input: *u8,
53+
fn snappy_compress(input: *const u8,
5454
input_length: size_t,
5555
compressed: *mut u8,
5656
compressed_length: *mut size_t) -> c_int;
57-
fn snappy_uncompress(compressed: *u8,
57+
fn snappy_uncompress(compressed: *const u8,
5858
compressed_length: size_t,
5959
uncompressed: *mut u8,
6060
uncompressed_length: *mut size_t) -> c_int;
6161
fn snappy_max_compressed_length(source_length: size_t) -> size_t;
62-
fn snappy_uncompressed_length(compressed: *u8,
62+
fn snappy_uncompressed_length(compressed: *const u8,
6363
compressed_length: size_t,
6464
result: *mut size_t) -> c_int;
65-
fn snappy_validate_compressed_buffer(compressed: *u8,
65+
fn snappy_validate_compressed_buffer(compressed: *const u8,
6666
compressed_length: size_t) -> c_int;
6767
}
6868
# fn main() {}
@@ -82,7 +82,7 @@ the allocated memory. The length is less than or equal to the capacity.
8282
~~~~
8383
# extern crate libc;
8484
# use libc::{c_int, size_t};
85-
# unsafe fn snappy_validate_compressed_buffer(_: *u8, _: size_t) -> c_int { 0 }
85+
# unsafe fn snappy_validate_compressed_buffer(_: *const u8, _: size_t) -> c_int { 0 }
8686
# fn main() {}
8787
pub fn validate_compressed_buffer(src: &[u8]) -> bool {
8888
unsafe {
@@ -106,7 +106,7 @@ the true length after compression for setting the length.
106106
~~~~
107107
# extern crate libc;
108108
# use libc::{size_t, c_int};
109-
# unsafe fn snappy_compress(a: *u8, b: size_t, c: *mut u8,
109+
# unsafe fn snappy_compress(a: *const u8, b: size_t, c: *mut u8,
110110
# d: *mut size_t) -> c_int { 0 }
111111
# unsafe fn snappy_max_compressed_length(a: size_t) -> size_t { a }
112112
# fn main() {}
@@ -132,11 +132,11 @@ format and `snappy_uncompressed_length` will retrieve the exact buffer size requ
132132
~~~~
133133
# extern crate libc;
134134
# use libc::{size_t, c_int};
135-
# unsafe fn snappy_uncompress(compressed: *u8,
135+
# unsafe fn snappy_uncompress(compressed: *const u8,
136136
# compressed_length: size_t,
137137
# uncompressed: *mut u8,
138138
# uncompressed_length: *mut size_t) -> c_int { 0 }
139-
# unsafe fn snappy_uncompressed_length(compressed: *u8,
139+
# unsafe fn snappy_uncompressed_length(compressed: *const u8,
140140
# compressed_length: size_t,
141141
# result: *mut size_t) -> c_int { 0 }
142142
# fn main() {}
@@ -418,7 +418,7 @@ Unsafe functions, on the other hand, advertise it to the world. An unsafe functi
418418
this:
419419
420420
~~~~
421-
unsafe fn kaboom(ptr: *int) -> int { *ptr }
421+
unsafe fn kaboom(ptr: *const int) -> int { *ptr }
422422
~~~~
423423
424424
This function can only be called from an `unsafe` block or another `unsafe` function.
@@ -453,7 +453,7 @@ use std::ptr;
453453
454454
#[link(name = "readline")]
455455
extern {
456-
static mut rl_prompt: *libc::c_char;
456+
static mut rl_prompt: *const libc::c_char;
457457
}
458458
459459
fn main() {
@@ -478,7 +478,7 @@ extern crate libc;
478478
#[link(name = "kernel32")]
479479
#[allow(non_snake_case_functions)]
480480
extern "stdcall" {
481-
fn SetEnvironmentVariableA(n: *u8, v: *u8) -> libc::c_int;
481+
fn SetEnvironmentVariableA(n: *const u8, v: *const u8) -> libc::c_int;
482482
}
483483
# fn main() { }
484484
~~~~

src/doc/guide-runtime.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ extern crate green;
245245
extern crate rustuv;
246246
247247
#[start]
248-
fn start(argc: int, argv: **u8) -> int {
248+
fn start(argc: int, argv: *const *const u8) -> int {
249249
green::start(argc, argv, rustuv::event_loop, main)
250250
}
251251
@@ -261,7 +261,9 @@ inside of an OS thread.
261261
extern crate native;
262262
263263
#[start]
264-
fn start(argc: int, argv: **u8) -> int { native::start(argc, argv, main) }
264+
fn start(argc: int, argv: *const *const u8) -> int {
265+
native::start(argc, argv, main)
266+
}
265267
266268
fn main() {}
267269
~~~

src/doc/guide-unsafe.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ let ref_2: &mut u8 = unsafe { mem::transmute(&mut *ref_1) };
7979
## Raw pointers
8080

8181
Rust 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*`
8383
respectively; indeed, one of their most common uses is for FFI,
8484
interfacing 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

105105
Fortunately, they come with a redeeming feature: the weaker guarantees
106106
mean weaker restrictions. The missing restrictions make raw pointers
@@ -131,13 +131,13 @@ unsafe, and neither is converting to an integer.
131131

132132
At runtime, a raw pointer `*` and a reference pointing to the same
133133
piece 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
135135
and 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
139139
safe. 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,
141141
the resulting pointer must satisfy the aliasing and mutability laws of
142142
references. The compiler assumes these properties are true for any
143143
references, no matter how they are created, and so any conversion from
@@ -149,7 +149,7 @@ The recommended method for the conversion is
149149
```
150150
let i: u32 = 1;
151151
// explicit cast
152-
let p_imm: *u32 = &i as *u32;
152+
let p_imm: *const u32 = &i as *const u32;
153153
let mut m: u32 = 2;
154154
// implicit coercion
155155
let 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:
482482
extern 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;
540540
use 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
627627
extern "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

src/doc/rust.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,7 @@ extern crate libc;
16141614
use libc::{c_char, FILE};
16151615
16161616
extern {
1617-
fn fopen(filename: *c_char, mode: *c_char) -> *FILE;
1617+
fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE;
16181618
}
16191619
# fn main() {}
16201620
~~~~

src/liballoc/heap.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub static mut EMPTY: uint = 12345;
9999
#[inline]
100100
unsafe fn exchange_malloc(size: uint, align: uint) -> *mut u8 {
101101
if size == 0 {
102-
&EMPTY as *uint as *mut u8
102+
&EMPTY as *const uint as *mut u8
103103
} else {
104104
allocate(size, align)
105105
}
@@ -144,9 +144,10 @@ mod imp {
144144
flags: c_int) -> size_t;
145145
fn je_dallocx(ptr: *mut c_void, flags: c_int);
146146
fn je_nallocx(size: size_t, flags: c_int) -> size_t;
147-
fn je_malloc_stats_print(write_cb: Option<extern "C" fn(cbopaque: *mut c_void, *c_char)>,
147+
fn je_malloc_stats_print(write_cb: Option<extern "C" fn(cbopaque: *mut c_void,
148+
*const c_char)>,
148149
cbopaque: *mut c_void,
149-
opts: *c_char);
150+
opts: *const c_char);
150151
}
151152

152153
// -lpthread needs to occur after -ljemalloc, the earlier argument isn't enough
@@ -226,7 +227,7 @@ mod imp {
226227
// a block of memory, so we special case everything under `*uint` to
227228
// just pass it to malloc, which is guaranteed to align to at least the
228229
// size of `*uint`.
229-
if align < mem::size_of::<*uint>() {
230+
if align < mem::size_of::<uint>() {
230231
libc_heap::malloc_raw(size)
231232
} else {
232233
let mut out = 0 as *mut libc::c_void;
@@ -244,7 +245,7 @@ mod imp {
244245
pub unsafe fn reallocate(ptr: *mut u8, size: uint, align: uint,
245246
old_size: uint) -> *mut u8 {
246247
let new_ptr = allocate(size, align);
247-
ptr::copy_memory(new_ptr, ptr as *u8, old_size);
248+
ptr::copy_memory(new_ptr, ptr as *const u8, old_size);
248249
deallocate(ptr, old_size, align);
249250
return new_ptr;
250251
}

src/liballoc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070

7171
#![no_std]
7272
#![feature(lang_items, phase, unsafe_destructor)]
73-
#![allow(unknown_features)] // NOTE: remove after a stage0 snap
7473

7574
#[phase(plugin, link)]
7675
extern crate core;

src/liballoc/owned.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub static HEAP: () = ();
3737

3838
/// A type that represents a uniquely-owned value.
3939
#[lang="owned_box"]
40-
pub struct Box<T>(*T);
40+
pub struct Box<T>(*mut T);
4141

4242
impl<T: Default> Default for Box<T> {
4343
fn default() -> Box<T> { box Default::default() }

0 commit comments

Comments
 (0)