Skip to content

Commit e24fe5b

Browse files
committed
std: Remove deprecated ptr functions
The method with which backwards compatibility was retained ended up leading to documentation that rustdoc didn't handle well and largely ended up confusing.
1 parent ecf8c64 commit e24fe5b

File tree

8 files changed

+49
-41
lines changed

8 files changed

+49
-41
lines changed

src/libcollectionstest/slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,7 @@ mod bench {
14281428
let mut v = Vec::<u8>::with_capacity(1024);
14291429
unsafe {
14301430
let vp = v.as_mut_ptr();
1431-
ptr::set_memory(vp, 0, 1024);
1431+
ptr::write_bytes(vp, 0, 1024);
14321432
v.set_len(1024);
14331433
}
14341434
v

src/libcore/intrinsics.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444

4545
use marker::Sized;
4646

47+
#[cfg(stage0)] pub use self::copy_memory as copy;
48+
#[cfg(stage0)] pub use self::set_memory as write_bytes;
49+
#[cfg(stage0)] pub use self::copy_nonoverlapping_memory as copy_nonoverlapping;
50+
4751
extern "rust-intrinsic" {
4852

4953
// NB: These intrinsics take unsafe pointers because they mutate aliased
@@ -246,7 +250,7 @@ extern "rust-intrinsic" {
246250
/// Copies `count * size_of<T>` bytes from `src` to `dst`. The source
247251
/// and destination may *not* overlap.
248252
///
249-
/// `copy_nonoverlapping_memory` is semantically equivalent to C's `memcpy`.
253+
/// `copy_nonoverlapping` is semantically equivalent to C's `memcpy`.
250254
///
251255
/// # Safety
252256
///
@@ -271,9 +275,9 @@ extern "rust-intrinsic" {
271275
/// let mut t: T = mem::uninitialized();
272276
///
273277
/// // Perform the swap, `&mut` pointers never alias
274-
/// ptr::copy_nonoverlapping_memory(&mut t, &*x, 1);
275-
/// ptr::copy_nonoverlapping_memory(x, &*y, 1);
276-
/// ptr::copy_nonoverlapping_memory(y, &t, 1);
278+
/// ptr::copy_nonoverlapping(&mut t, &*x, 1);
279+
/// ptr::copy_nonoverlapping(x, &*y, 1);
280+
/// ptr::copy_nonoverlapping(y, &t, 1);
277281
///
278282
/// // y and t now point to the same thing, but we need to completely forget `tmp`
279283
/// // because it's no longer relevant.
@@ -282,12 +286,18 @@ extern "rust-intrinsic" {
282286
/// }
283287
/// ```
284288
#[stable(feature = "rust1", since = "1.0.0")]
289+
#[cfg(not(stage0))]
290+
pub fn copy_nonoverlapping<T>(dst: *mut T, src: *const T, count: usize);
291+
292+
/// dox
293+
#[stable(feature = "rust1", since = "1.0.0")]
294+
#[cfg(stage0)]
285295
pub fn copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: usize);
286296

287297
/// Copies `count * size_of<T>` bytes from `src` to `dst`. The source
288298
/// and destination may overlap.
289299
///
290-
/// `copy_memory` is semantically equivalent to C's `memmove`.
300+
/// `copy` is semantically equivalent to C's `memmove`.
291301
///
292302
/// # Safety
293303
///
@@ -306,16 +316,28 @@ extern "rust-intrinsic" {
306316
/// unsafe fn from_buf_raw<T>(ptr: *const T, elts: uint) -> Vec<T> {
307317
/// let mut dst = Vec::with_capacity(elts);
308318
/// dst.set_len(elts);
309-
/// ptr::copy_memory(dst.as_mut_ptr(), ptr, elts);
319+
/// ptr::copy(dst.as_mut_ptr(), ptr, elts);
310320
/// dst
311321
/// }
312322
/// ```
313323
///
324+
#[cfg(not(stage0))]
325+
#[stable(feature = "rust1", since = "1.0.0")]
326+
pub fn copy<T>(dst: *mut T, src: *const T, count: usize);
327+
328+
/// dox
329+
#[cfg(stage0)]
314330
#[stable(feature = "rust1", since = "1.0.0")]
315331
pub fn copy_memory<T>(dst: *mut T, src: *const T, count: usize);
316332

317333
/// Invokes memset on the specified pointer, setting `count * size_of::<T>()`
318334
/// bytes of memory starting at `dst` to `c`.
335+
#[cfg(not(stage0))]
336+
#[stable(feature = "rust1", since = "1.0.0")]
337+
pub fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
338+
339+
/// dox
340+
#[cfg(stage0)]
319341
#[stable(feature = "rust1", since = "1.0.0")]
320342
pub fn set_memory<T>(dst: *mut T, val: u8, count: usize);
321343

src/libcore/ptr.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,27 +105,13 @@ use cmp::Ordering::{self, Less, Equal, Greater};
105105
// FIXME #19649: intrinsic docs don't render, so these have no docs :(
106106

107107
#[stable(feature = "rust1", since = "1.0.0")]
108-
pub use intrinsics::copy_nonoverlapping_memory as copy_nonoverlapping;
108+
pub use intrinsics::copy_nonoverlapping;
109109

110110
#[stable(feature = "rust1", since = "1.0.0")]
111-
pub use intrinsics::copy_memory as copy;
111+
pub use intrinsics::copy;
112112

113113
#[stable(feature = "rust1", since = "1.0.0")]
114-
pub use intrinsics::set_memory as write_bytes;
115-
116-
extern "rust-intrinsic" {
117-
#[unstable(feature = "core")]
118-
#[deprecated(since = "1.0.0", reason = "renamed to `copy_nonoverlapping`")]
119-
pub fn copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: usize);
120-
#[unstable(feature = "core")]
121-
#[deprecated(since = "1.0.0", reason = "renamed to `copy`")]
122-
pub fn copy_memory<T>(dst: *mut T, src: *const T, count: usize);
123-
124-
#[unstable(feature = "core",
125-
reason = "uncertain about naming and semantics")]
126-
#[deprecated(since = "1.0.0", reason = "renamed to `write_bytes`")]
127-
pub fn set_memory<T>(dst: *mut T, val: u8, count: usize);
128-
}
114+
pub use intrinsics::write_bytes;
129115

130116
/// Creates a null raw pointer.
131117
///

src/libcoretest/ptr.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ fn test() {
3535
let v0 = vec![32000u16, 32001u16, 32002u16];
3636
let mut v1 = vec![0u16, 0u16, 0u16];
3737

38-
copy_memory(v1.as_mut_ptr().offset(1),
39-
v0.as_ptr().offset(1), 1);
38+
copy(v1.as_mut_ptr().offset(1),
39+
v0.as_ptr().offset(1), 1);
4040
assert!((v1[0] == 0u16 &&
4141
v1[1] == 32001u16 &&
4242
v1[2] == 0u16));
43-
copy_memory(v1.as_mut_ptr(),
44-
v0.as_ptr().offset(2), 1);
43+
copy(v1.as_mut_ptr(),
44+
v0.as_ptr().offset(2), 1);
4545
assert!((v1[0] == 32002u16 &&
4646
v1[1] == 32001u16 &&
4747
v1[2] == 0u16));
48-
copy_memory(v1.as_mut_ptr().offset(2),
49-
v0.as_ptr(), 1);
48+
copy(v1.as_mut_ptr().offset(2),
49+
v0.as_ptr(), 1);
5050
assert!((v1[0] == 32002u16 &&
5151
v1[1] == 32001u16 &&
5252
v1[2] == 32000u16));
@@ -164,7 +164,7 @@ fn test_ptr_subtraction() {
164164
fn test_set_memory() {
165165
let mut xs = [0u8; 20];
166166
let ptr = xs.as_mut_ptr();
167-
unsafe { set_memory(ptr, 5u8, xs.len()); }
167+
unsafe { write_bytes(ptr, 5u8, xs.len()); }
168168
assert!(xs == [5u8; 20]);
169169
}
170170

src/librustc_trans/trans/intrinsic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
386386
InBoundsGEP(bcx, ptr, &[offset])
387387
}
388388

389-
(_, "copy_nonoverlapping_memory") => {
389+
(_, "copy_nonoverlapping") => {
390390
copy_intrinsic(bcx,
391391
false,
392392
false,
@@ -396,7 +396,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
396396
llargs[2],
397397
call_debug_location)
398398
}
399-
(_, "copy_memory") => {
399+
(_, "copy") => {
400400
copy_intrinsic(bcx,
401401
true,
402402
false,
@@ -406,7 +406,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
406406
llargs[2],
407407
call_debug_location)
408408
}
409-
(_, "set_memory") => {
409+
(_, "write_bytes") => {
410410
memset_intrinsic(bcx,
411411
false,
412412
*substs.types.get(FnSpace, 0),

src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5365,7 +5365,7 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) {
53655365
mutbl: ast::MutImmutable
53665366
}))
53675367
}
5368-
"copy_memory" | "copy_nonoverlapping_memory" |
5368+
"copy" | "copy_nonoverlapping" |
53695369
"volatile_copy_memory" | "volatile_copy_nonoverlapping_memory" => {
53705370
(1,
53715371
vec!(
@@ -5381,7 +5381,7 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) {
53815381
),
53825382
ty::mk_nil(tcx))
53835383
}
5384-
"set_memory" | "volatile_set_memory" => {
5384+
"write_bytes" | "volatile_set_memory" => {
53855385
(1,
53865386
vec!(
53875387
ty::mk_ptr(tcx, ty::mt {

src/libstd/old_io/extensions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub fn u64_to_be_bytes<T, F>(n: u64, size: uint, f: F) -> T where
159159
/// that many bytes are parsed. For example, if `size` is 4, then a
160160
/// 32-bit value is parsed.
161161
pub fn u64_from_be_bytes(data: &[u8], start: uint, size: uint) -> u64 {
162-
use ptr::{copy_nonoverlapping_memory};
162+
use ptr::{copy_nonoverlapping};
163163

164164
assert!(size <= 8);
165165

@@ -171,7 +171,7 @@ pub fn u64_from_be_bytes(data: &[u8], start: uint, size: uint) -> u64 {
171171
unsafe {
172172
let ptr = data.as_ptr().offset(start as int);
173173
let out = buf.as_mut_ptr();
174-
copy_nonoverlapping_memory(out.offset((8 - size) as int), ptr, size);
174+
copy_nonoverlapping(out.offset((8 - size) as int), ptr, size);
175175
(*(out as *const u64)).to_be()
176176
}
177177
}

src/test/bench/shootout-reverse-complement.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ extern crate libc;
4646

4747
use std::old_io::stdio::{stdin_raw, stdout_raw};
4848
use std::old_io::*;
49-
use std::ptr::{copy_memory, Unique};
49+
use std::ptr::{copy, Unique};
5050
use std::thread;
5151

5252
struct Tables {
@@ -181,8 +181,8 @@ fn reverse_complement(seq: &mut [u8], tables: &Tables) {
181181
let mut i = LINE_LEN;
182182
while i < len {
183183
unsafe {
184-
copy_memory(seq.as_mut_ptr().offset((i - off + 1) as int),
185-
seq.as_ptr().offset((i - off) as int), off);
184+
copy(seq.as_mut_ptr().offset((i - off + 1) as int),
185+
seq.as_ptr().offset((i - off) as int), off);
186186
*seq.get_unchecked_mut(i - off) = b'\n';
187187
}
188188
i += LINE_LEN + 1;

0 commit comments

Comments
 (0)