Skip to content

Commit 8d52dfb

Browse files
committed
auto merge of #10984 : huonw/rust/clean-raw, r=cmr
See commits for details.
2 parents ef7969e + 164f7a2 commit 8d52dfb

32 files changed

+231
-302
lines changed

doc/po/ja/tutorial-ffi.md.po

+7-7
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ msgid ""
168168
"~~~~ {.xfail-test}\n"
169169
"pub fn validate_compressed_buffer(src: &[u8]) -> bool {\n"
170170
" unsafe {\n"
171-
" snappy_validate_compressed_buffer(vec::raw::to_ptr(src), src.len() as size_t) == 0\n"
171+
" snappy_validate_compressed_buffer(src.as_ptr(), src.len() as size_t) == 0\n"
172172
" }\n"
173173
"}\n"
174174
"~~~~\n"
@@ -207,7 +207,7 @@ msgid ""
207207
"pub fn compress(src: &[u8]) -> ~[u8] {\n"
208208
" unsafe {\n"
209209
" let srclen = src.len() as size_t;\n"
210-
" let psrc = vec::raw::to_ptr(src);\n"
210+
" let psrc = src.as_ptr();\n"
211211
msgstr ""
212212

213213
#. type: Plain text
@@ -216,15 +216,15 @@ msgstr ""
216216
msgid ""
217217
" let mut dstlen = snappy_max_compressed_length(srclen);\n"
218218
" let mut dst = vec::with_capacity(dstlen as uint);\n"
219-
" let pdst = vec::raw::to_mut_ptr(dst);\n"
219+
" let pdst = dst.as_mut_ptr();\n"
220220
msgstr ""
221221

222222
#. type: Plain text
223223
#: doc/tutorial-ffi.md:113
224224
#, no-wrap
225225
msgid ""
226226
" snappy_compress(psrc, srclen, pdst, &mut dstlen);\n"
227-
" vec::raw::set_len(&mut dst, dstlen as uint);\n"
227+
" dst.set_len(dstlen as uint);\n"
228228
" dst\n"
229229
" }\n"
230230
"}\n"
@@ -247,7 +247,7 @@ msgid ""
247247
"pub fn uncompress(src: &[u8]) -> Option<~[u8]> {\n"
248248
" unsafe {\n"
249249
" let srclen = src.len() as size_t;\n"
250-
" let psrc = vec::raw::to_ptr(src);\n"
250+
" let psrc = src.as_ptr();\n"
251251
msgstr ""
252252

253253
#. type: Plain text
@@ -263,15 +263,15 @@ msgstr ""
263263
#, no-wrap
264264
msgid ""
265265
" let mut dst = vec::with_capacity(dstlen as uint);\n"
266-
" let pdst = vec::raw::to_mut_ptr(dst);\n"
266+
" let pdst = dst.as_mut_ptr();\n"
267267
msgstr ""
268268

269269
#. type: Plain text
270270
#: doc/tutorial-ffi.md:138
271271
#, no-wrap
272272
msgid ""
273273
" if snappy_uncompress(psrc, srclen, pdst, &mut dstlen) == 0 {\n"
274-
" vec::raw::set_len(&mut dst, dstlen as uint);\n"
274+
" dst.set_len(dstlen as uint);\n"
275275
" Some(dst)\n"
276276
" } else {\n"
277277
" None // SNAPPY_INVALID_INPUT\n"

doc/po/tutorial-ffi.md.pot

+7-7
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ msgid ""
168168
"~~~~ {.xfail-test}\n"
169169
"pub fn validate_compressed_buffer(src: &[u8]) -> bool {\n"
170170
" unsafe {\n"
171-
" snappy_validate_compressed_buffer(vec::raw::to_ptr(src), src.len() as size_t) == 0\n"
171+
" snappy_validate_compressed_buffer(src.as_ptr(), src.len() as size_t) == 0\n"
172172
" }\n"
173173
"}\n"
174174
"~~~~\n"
@@ -207,7 +207,7 @@ msgid ""
207207
"pub fn compress(src: &[u8]) -> ~[u8] {\n"
208208
" unsafe {\n"
209209
" let srclen = src.len() as size_t;\n"
210-
" let psrc = vec::raw::to_ptr(src);\n"
210+
" let psrc = src.as_ptr();\n"
211211
msgstr ""
212212

213213
#. type: Plain text
@@ -216,15 +216,15 @@ msgstr ""
216216
msgid ""
217217
" let mut dstlen = snappy_max_compressed_length(srclen);\n"
218218
" let mut dst = vec::with_capacity(dstlen as uint);\n"
219-
" let pdst = vec::raw::to_mut_ptr(dst);\n"
219+
" let pdst = dst.as_mut_ptr();\n"
220220
msgstr ""
221221

222222
#. type: Plain text
223223
#: doc/tutorial-ffi.md:113
224224
#, no-wrap
225225
msgid ""
226226
" snappy_compress(psrc, srclen, pdst, &mut dstlen);\n"
227-
" vec::raw::set_len(&mut dst, dstlen as uint);\n"
227+
" dst.set_len(dstlen as uint);\n"
228228
" dst\n"
229229
" }\n"
230230
"}\n"
@@ -247,7 +247,7 @@ msgid ""
247247
"pub fn uncompress(src: &[u8]) -> Option<~[u8]> {\n"
248248
" unsafe {\n"
249249
" let srclen = src.len() as size_t;\n"
250-
" let psrc = vec::raw::to_ptr(src);\n"
250+
" let psrc = src.as_ptr();\n"
251251
msgstr ""
252252

253253
#. type: Plain text
@@ -263,15 +263,15 @@ msgstr ""
263263
#, no-wrap
264264
msgid ""
265265
" let mut dst = vec::with_capacity(dstlen as uint);\n"
266-
" let pdst = vec::raw::to_mut_ptr(dst);\n"
266+
" let pdst = dst.as_mut_ptr();\n"
267267
msgstr ""
268268

269269
#. type: Plain text
270270
#: doc/tutorial-ffi.md:138
271271
#, no-wrap
272272
msgid ""
273273
" if snappy_uncompress(psrc, srclen, pdst, &mut dstlen) == 0 {\n"
274-
" vec::raw::set_len(&mut dst, dstlen as uint);\n"
274+
" dst.set_len(dstlen as uint);\n"
275275
" Some(dst)\n"
276276
" } else {\n"
277277
" None // SNAPPY_INVALID_INPUT\n"

doc/tutorial-ffi.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ the allocated memory. The length is less than or equal to the capacity.
7979
~~~~ {.xfail-test}
8080
pub fn validate_compressed_buffer(src: &[u8]) -> bool {
8181
unsafe {
82-
snappy_validate_compressed_buffer(vec::raw::to_ptr(src), src.len() as size_t) == 0
82+
snappy_validate_compressed_buffer(src.as_ptr(), src.len() as size_t) == 0
8383
}
8484
}
8585
~~~~
@@ -100,14 +100,14 @@ the true length after compression for setting the length.
100100
pub fn compress(src: &[u8]) -> ~[u8] {
101101
unsafe {
102102
let srclen = src.len() as size_t;
103-
let psrc = vec::raw::to_ptr(src);
103+
let psrc = src.as_ptr();
104104
105105
let mut dstlen = snappy_max_compressed_length(srclen);
106106
let mut dst = vec::with_capacity(dstlen as uint);
107-
let pdst = vec::raw::to_mut_ptr(dst);
107+
let pdst = dst.as_mut_ptr();
108108
109109
snappy_compress(psrc, srclen, pdst, &mut dstlen);
110-
vec::raw::set_len(&mut dst, dstlen as uint);
110+
dst.set_len(dstlen as uint);
111111
dst
112112
}
113113
}
@@ -120,16 +120,16 @@ format and `snappy_uncompressed_length` will retrieve the exact buffer size requ
120120
pub fn uncompress(src: &[u8]) -> Option<~[u8]> {
121121
unsafe {
122122
let srclen = src.len() as size_t;
123-
let psrc = vec::raw::to_ptr(src);
123+
let psrc = src.as_ptr();
124124
125125
let mut dstlen: size_t = 0;
126126
snappy_uncompressed_length(psrc, srclen, &mut dstlen);
127127
128128
let mut dst = vec::with_capacity(dstlen as uint);
129-
let pdst = vec::raw::to_mut_ptr(dst);
129+
let pdst = dst.as_mut_ptr();
130130
131131
if snappy_uncompress(psrc, srclen, pdst, &mut dstlen) == 0 {
132-
vec::raw::set_len(&mut dst, dstlen as uint);
132+
dst.set_len(dstlen as uint);
133133
Some(dst)
134134
} else {
135135
None // SNAPPY_INVALID_INPUT

src/libextra/arena.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ use std::num;
4444
use std::ptr;
4545
use std::mem;
4646
use std::uint;
47-
use std::vec;
4847
use std::unstable::intrinsics;
4948
use std::unstable::intrinsics::{TyDesc, get_tydesc};
5049

@@ -115,7 +114,7 @@ fn round_up_to(base: uint, align: uint) -> uint {
115114
// in it.
116115
unsafe fn destroy_chunk(chunk: &Chunk) {
117116
let mut idx = 0;
118-
let buf = vec::raw::to_ptr(chunk.data);
117+
let buf = chunk.data.as_ptr();
119118
let fill = chunk.fill;
120119

121120
while idx < fill {
@@ -179,7 +178,7 @@ impl Arena {
179178
//debug!("idx = {}, size = {}, align = {}, fill = {}",
180179
// start, n_bytes, align, head.fill);
181180

182-
ptr::offset(vec::raw::to_ptr(this.pod_head.data), start as int)
181+
ptr::offset(this.pod_head.data.as_ptr(), start as int)
183182
}
184183
}
185184

@@ -235,7 +234,7 @@ impl Arena {
235234
//debug!("idx = {}, size = {}, align = {}, fill = {}",
236235
// start, n_bytes, align, head.fill);
237236

238-
let buf = vec::raw::to_ptr(self.head.data);
237+
let buf = self.head.data.as_ptr();
239238
return (ptr::offset(buf, tydesc_start as int), ptr::offset(buf, start as int));
240239
}
241240
}

src/libextra/uuid.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl Uuid {
175175
pub fn new_v4() -> Uuid {
176176
let ub = rand::task_rng().gen_vec(16);
177177
let mut uuid = Uuid{ bytes: [0, .. 16] };
178-
vec::bytes::copy_memory(uuid.bytes, ub, 16);
178+
vec::bytes::copy_memory(uuid.bytes, ub);
179179
uuid.set_variant(VariantRFC4122);
180180
uuid.set_version(Version4Random);
181181
uuid
@@ -202,7 +202,7 @@ impl Uuid {
202202
fields.data1 = to_be32(d1 as i32) as u32;
203203
fields.data2 = to_be16(d2 as i16) as u16;
204204
fields.data3 = to_be16(d3 as i16) as u16;
205-
vec::bytes::copy_memory(fields.data4, d4, 8);
205+
vec::bytes::copy_memory(fields.data4, d4);
206206

207207
unsafe {
208208
transmute(fields)
@@ -220,7 +220,7 @@ impl Uuid {
220220

221221
let mut uuid = Uuid{ bytes: [0, .. 16] };
222222
unsafe {
223-
vec::raw::copy_memory(uuid.bytes, b, 16);
223+
vec::raw::copy_memory(uuid.bytes, b);
224224
}
225225
Some(uuid)
226226
}
@@ -442,11 +442,7 @@ impl Zero for Uuid {
442442

443443
impl Clone for Uuid {
444444
/// Returns a copy of the UUID
445-
fn clone(&self) -> Uuid {
446-
let mut clone = Uuid{ bytes: [0, .. 16] };
447-
vec::bytes::copy_memory(clone.bytes, self.bytes, 16);
448-
clone
449-
}
445+
fn clone(&self) -> Uuid { *self }
450446
}
451447

452448
impl FromStr for Uuid {
@@ -509,7 +505,7 @@ impl rand::Rand for Uuid {
509505
fn rand<R: rand::Rng>(rng: &mut R) -> Uuid {
510506
let ub = rng.gen_vec(16);
511507
let mut uuid = Uuid{ bytes: [0, .. 16] };
512-
vec::bytes::copy_memory(uuid.bytes, ub, 16);
508+
vec::bytes::copy_memory(uuid.bytes, ub);
513509
uuid.set_variant(VariantRFC4122);
514510
uuid.set_version(Version4Random);
515511
uuid

src/librustc/back/lto.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use metadata::cstore;
1616
use util::common::time;
1717

1818
use std::libc;
19-
use std::vec;
2019

2120
pub fn run(sess: session::Session, llmod: ModuleRef,
2221
tm: TargetMachineRef, reachable: &[~str]) {
@@ -48,7 +47,7 @@ pub fn run(sess: session::Session, llmod: ModuleRef,
4847
debug!("reading {}", name);
4948
let bc = time(sess.time_passes(), format!("read {}.bc", name), (), |_|
5049
archive.read(format!("{}.bc", name)));
51-
let ptr = vec::raw::to_ptr(bc);
50+
let ptr = bc.as_ptr();
5251
debug!("linking {}", name);
5352
time(sess.time_passes(), format!("ll link {}", name), (), |()| unsafe {
5453
if !llvm::LLVMRustLinkInExternalBitcode(llmod,
@@ -62,7 +61,7 @@ pub fn run(sess: session::Session, llmod: ModuleRef,
6261
// Internalize everything but the reachable symbols of the current module
6362
let cstrs = reachable.map(|s| s.to_c_str());
6463
let arr = cstrs.map(|c| c.with_ref(|p| p));
65-
let ptr = vec::raw::to_ptr(arr);
64+
let ptr = arr.as_ptr();
6665
unsafe {
6766
llvm::LLVMRustRunRestrictionPass(llmod, ptr as **libc::c_char,
6867
arr.len() as libc::size_t);

src/librustc/middle/trans/builder.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use middle::trans::type_::Type;
2020
use std::cast;
2121
use std::hashmap::HashMap;
2222
use std::libc::{c_uint, c_ulonglong, c_char};
23-
use std::vec;
2423
use syntax::codemap::Span;
2524
use std::ptr::is_not_null;
2625

@@ -118,7 +117,7 @@ impl Builder {
118117
pub fn aggregate_ret(&self, ret_vals: &[ValueRef]) {
119118
unsafe {
120119
llvm::LLVMBuildAggregateRet(self.llbuilder,
121-
vec::raw::to_ptr(ret_vals),
120+
ret_vals.as_ptr(),
122121
ret_vals.len() as c_uint);
123122
}
124123
}
@@ -161,7 +160,7 @@ impl Builder {
161160
unsafe {
162161
let v = llvm::LLVMBuildInvoke(self.llbuilder,
163162
llfn,
164-
vec::raw::to_ptr(args),
163+
args.as_ptr(),
165164
args.len() as c_uint,
166165
then,
167166
catch,
@@ -500,7 +499,7 @@ impl Builder {
500499
pub fn gep(&self, ptr: ValueRef, indices: &[ValueRef]) -> ValueRef {
501500
self.count_insn("gep");
502501
unsafe {
503-
llvm::LLVMBuildGEP(self.llbuilder, ptr, vec::raw::to_ptr(indices),
502+
llvm::LLVMBuildGEP(self.llbuilder, ptr, indices.as_ptr(),
504503
indices.len() as c_uint, noname())
505504
}
506505
}
@@ -528,7 +527,7 @@ impl Builder {
528527
self.count_insn("inboundsgep");
529528
unsafe {
530529
llvm::LLVMBuildInBoundsGEP(
531-
self.llbuilder, ptr, vec::raw::to_ptr(indices), indices.len() as c_uint, noname())
530+
self.llbuilder, ptr, indices.as_ptr(), indices.len() as c_uint, noname())
532531
}
533532
}
534533

@@ -716,8 +715,8 @@ impl Builder {
716715
let phi = self.empty_phi(ty);
717716
self.count_insn("addincoming");
718717
unsafe {
719-
llvm::LLVMAddIncoming(phi, vec::raw::to_ptr(vals),
720-
vec::raw::to_ptr(bbs),
718+
llvm::LLVMAddIncoming(phi, vals.as_ptr(),
719+
bbs.as_ptr(),
721720
vals.len() as c_uint);
722721
phi
723722
}
@@ -775,7 +774,7 @@ impl Builder {
775774
attributes: &[(uint, lib::llvm::Attribute)]) -> ValueRef {
776775
self.count_insn("call");
777776
unsafe {
778-
let v = llvm::LLVMBuildCall(self.llbuilder, llfn, vec::raw::to_ptr(args),
777+
let v = llvm::LLVMBuildCall(self.llbuilder, llfn, args.as_ptr(),
779778
args.len() as c_uint, noname());
780779
for &(idx, attr) in attributes.iter() {
781780
llvm::LLVMAddInstrAttribute(v, idx as c_uint, attr as c_uint);
@@ -885,7 +884,7 @@ impl Builder {
885884
let args: &[ValueRef] = [];
886885
self.count_insn("trap");
887886
llvm::LLVMBuildCall(
888-
self.llbuilder, T, vec::raw::to_ptr(args), args.len() as c_uint, noname());
887+
self.llbuilder, T, args.as_ptr(), args.len() as c_uint, noname());
889888
}
890889
}
891890

src/librustc/middle/trans/common.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ pub fn C_zero_byte_arr(size: uint) -> ValueRef {
946946
let mut elts: ~[ValueRef] = ~[];
947947
while i < size { elts.push(C_u8(0u)); i += 1u; }
948948
return llvm::LLVMConstArray(Type::i8().to_ref(),
949-
vec::raw::to_ptr(elts), elts.len() as c_uint);
949+
elts.as_ptr(), elts.len() as c_uint);
950950
}
951951
}
952952

@@ -968,13 +968,13 @@ pub fn C_named_struct(T: Type, elts: &[ValueRef]) -> ValueRef {
968968

969969
pub fn C_array(ty: Type, elts: &[ValueRef]) -> ValueRef {
970970
unsafe {
971-
return llvm::LLVMConstArray(ty.to_ref(), vec::raw::to_ptr(elts), elts.len() as c_uint);
971+
return llvm::LLVMConstArray(ty.to_ref(), elts.as_ptr(), elts.len() as c_uint);
972972
}
973973
}
974974

975975
pub fn C_bytes(bytes: &[u8]) -> ValueRef {
976976
unsafe {
977-
let ptr = cast::transmute(vec::raw::to_ptr(bytes));
977+
let ptr = cast::transmute(bytes.as_ptr());
978978
return llvm::LLVMConstStringInContext(base::task_llcx(), ptr, bytes.len() as c_uint, True);
979979
}
980980
}

src/librustc/middle/trans/context.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use util::sha2::Sha256;
3131
use std::c_str::ToCStr;
3232
use std::hashmap::{HashMap, HashSet};
3333
use std::local_data;
34-
use std::vec;
3534
use std::libc::c_uint;
3635
use syntax::ast;
3736

@@ -261,7 +260,7 @@ impl CrateContext {
261260
indices.iter().map(|i| C_i32(*i as i32)).collect();
262261
unsafe {
263262
llvm::LLVMConstInBoundsGEP(pointer,
264-
vec::raw::to_ptr(v),
263+
v.as_ptr(),
265264
indices.len() as c_uint)
266265
}
267266
}

0 commit comments

Comments
 (0)