Skip to content

Commit 4e82610

Browse files
committed
auto merge of #6487 : recrack/rust/vec_len, r=thestinger
Rename vec::len(var) to var.len() ``` libcore, libfuzzer, librustc, librustdoc, libstd, libsyntax test/auxiliary test/bench test/run-pass ```
2 parents 803c12d + a2a8596 commit 4e82610

Some content is hidden

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

58 files changed

+128
-134
lines changed

.swo

72 KB
Binary file not shown.

src/compiletest/runtest.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
264264
fatal(~"gdb failed to execute");
265265
}
266266

267-
let num_check_lines = vec::len(check_lines);
267+
let num_check_lines = check_lines.len();
268268
if num_check_lines > 0 {
269269
// check if each line in props.check_lines appears in the
270270
// output (in order)
@@ -303,7 +303,7 @@ fn check_error_patterns(props: &TestProps,
303303
if str::contains(line, *next_err_pat) {
304304
debug!("found error pattern %s", *next_err_pat);
305305
next_err_idx += 1u;
306-
if next_err_idx == vec::len(props.error_patterns) {
306+
if next_err_idx == props.error_patterns.len() {
307307
debug!("found all error patterns");
308308
done = true;
309309
break;
@@ -315,8 +315,8 @@ fn check_error_patterns(props: &TestProps,
315315

316316
let missing_patterns =
317317
vec::slice(props.error_patterns, next_err_idx,
318-
vec::len(props.error_patterns));
319-
if vec::len(missing_patterns) == 1u {
318+
props.error_patterns.len());
319+
if missing_patterns.len() == 1u {
320320
fatal_ProcRes(fmt!("error pattern '%s' not found!",
321321
missing_patterns[0]), ProcRes);
322322
} else {
@@ -333,7 +333,7 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
333333

334334
// true if we found the error in question
335335
let mut found_flags = vec::from_elem(
336-
vec::len(expected_errors), false);
336+
expected_errors.len(), false);
337337

338338
if ProcRes.status == 0 {
339339
fatal(~"process did not return an error status");
@@ -377,7 +377,7 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
377377
}
378378
}
379379

380-
for uint::range(0u, vec::len(found_flags)) |i| {
380+
for uint::range(0u, found_flags.len()) |i| {
381381
if !found_flags[i] {
382382
let ee = &expected_errors[i];
383383
fatal_ProcRes(fmt!("expected %s on line %u not found: %s",

src/libcore/either.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,14 @@ fn test_lefts() {
201201
fn test_lefts_none() {
202202
let input: ~[Either<int, int>] = ~[Right(10), Right(10)];
203203
let result = lefts(input);
204-
assert_eq!(vec::len(result), 0u);
204+
assert_eq!(result.len(), 0u);
205205
}
206206

207207
#[test]
208208
fn test_lefts_empty() {
209209
let input: ~[Either<int, int>] = ~[];
210210
let result = lefts(input);
211-
assert_eq!(vec::len(result), 0u);
211+
assert_eq!(result.len(), 0u);
212212
}
213213

214214
#[test]
@@ -222,14 +222,14 @@ fn test_rights() {
222222
fn test_rights_none() {
223223
let input: ~[Either<int, int>] = ~[Left(10), Left(10)];
224224
let result = rights(input);
225-
assert_eq!(vec::len(result), 0u);
225+
assert_eq!(result.len(), 0u);
226226
}
227227

228228
#[test]
229229
fn test_rights_empty() {
230230
let input: ~[Either<int, int>] = ~[];
231231
let result = rights(input);
232-
assert_eq!(vec::len(result), 0u);
232+
assert_eq!(result.len(), 0u);
233233
}
234234

235235
#[test]
@@ -247,22 +247,22 @@ fn test_partition() {
247247
fn test_partition_no_lefts() {
248248
let input: ~[Either<int, int>] = ~[Right(10), Right(11)];
249249
let (lefts, rights) = partition(input);
250-
assert_eq!(vec::len(lefts), 0u);
251-
assert_eq!(vec::len(rights), 2u);
250+
assert_eq!(lefts.len(), 0u);
251+
assert_eq!(rights.len(), 2u);
252252
}
253253

254254
#[test]
255255
fn test_partition_no_rights() {
256256
let input: ~[Either<int, int>] = ~[Left(10), Left(11)];
257257
let (lefts, rights) = partition(input);
258-
assert_eq!(vec::len(lefts), 2u);
259-
assert_eq!(vec::len(rights), 0u);
258+
assert_eq!(lefts.len(), 2u);
259+
assert_eq!(rights.len(), 0u);
260260
}
261261

262262
#[test]
263263
fn test_partition_empty() {
264264
let input: ~[Either<int, int>] = ~[];
265265
let (lefts, rights) = partition(input);
266-
assert_eq!(vec::len(lefts), 0u);
267-
assert_eq!(vec::len(rights), 0u);
266+
assert_eq!(lefts.len(), 0u);
267+
assert_eq!(rights.len(), 0u);
268268
}

src/libcore/io.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -673,10 +673,10 @@ impl<T:Reader> ReaderUtil for T {
673673

674674
fn read_char(&self) -> char {
675675
let c = self.read_chars(1);
676-
if vec::len(c) == 0 {
676+
if c.len() == 0 {
677677
return -1 as char; // FIXME will this stay valid? // #2004
678678
}
679-
assert!((vec::len(c) == 1));
679+
assert!(c.len() == 1);
680680
return c[0];
681681
}
682682

@@ -1802,7 +1802,7 @@ mod tests {
18021802
fn test_readchars_empty() {
18031803
do io::with_str_reader(~"") |inp| {
18041804
let res : ~[char] = inp.read_chars(128);
1805-
assert!((vec::len(res) == 0));
1805+
assert!(res.len() == 0);
18061806
}
18071807
}
18081808

@@ -1841,10 +1841,10 @@ mod tests {
18411841
fn check_read_ln(len : uint, s: &str, ivals: &[int]) {
18421842
do io::with_str_reader(s) |inp| {
18431843
let res : ~[char] = inp.read_chars(len);
1844-
if (len <= vec::len(ivals)) {
1845-
assert!((vec::len(res) == len));
1844+
if len <= ivals.len() {
1845+
assert!(res.len() == len);
18461846
}
1847-
assert!(vec::slice(ivals, 0u, vec::len(res)) ==
1847+
assert!(vec::slice(ivals, 0u, res.len()) ==
18481848
vec::map(res, |x| *x as int));
18491849
}
18501850
}

src/libcore/os.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ pub fn self_exe_path() -> Option<Path> {
410410
KERN_PROC as c_int,
411411
KERN_PROC_PATHNAME as c_int, -1 as c_int];
412412
let mut sz = sz;
413-
sysctl(vec::raw::to_ptr(mib), vec::len(mib) as ::libc::c_uint,
413+
sysctl(vec::raw::to_ptr(mib), mib.len() as ::libc::c_uint,
414414
buf as *mut c_void, &mut sz, ptr::null(),
415415
0u as size_t) == (0 as c_int)
416416
}
@@ -1490,7 +1490,7 @@ mod tests {
14901490
#[ignore]
14911491
fn test_env_getenv() {
14921492
let e = env();
1493-
assert!(vec::len(e) > 0u);
1493+
assert!(e.len() > 0u);
14941494
for e.each |p| {
14951495
let (n, v) = copy *p;
14961496
debug!(copy n);
@@ -1581,7 +1581,7 @@ mod tests {
15811581
fn list_dir() {
15821582
let dirs = os::list_dir(&Path("."));
15831583
// Just assuming that we've got some contents in the current directory
1584-
assert!((vec::len(dirs) > 0u));
1584+
assert!(dirs.len() > 0u);
15851585
15861586
for dirs.each |dir| {
15871587
debug!(copy *dir);

src/libcore/ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ pub mod ptr_tests {
441441
let arr_ptr = &arr[0];
442442
let mut ctr = 0;
443443
let mut iteration_count = 0;
444-
array_each_with_len(arr_ptr, vec::len(arr),
444+
array_each_with_len(arr_ptr, arr.len(),
445445
|e| {
446446
let actual = str::raw::from_c_str(e);
447447
let expected = copy expected_arr[ctr];

src/libcore/rt/uvll.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ pub unsafe fn accept(server: *c_void, client: *c_void) -> c_int {
221221

222222
pub unsafe fn write<T>(req: *uv_write_t, stream: *T, buf_in: &[uv_buf_t], cb: *u8) -> c_int {
223223
let buf_ptr = vec::raw::to_ptr(buf_in);
224-
let buf_cnt = vec::len(buf_in) as i32;
224+
let buf_cnt = buf_in.len() as i32;
225225
return rust_uv_write(req as *c_void, stream as *c_void, buf_ptr, buf_cnt, cb);
226226
}
227227
pub unsafe fn read_start(stream: *uv_stream_t, on_alloc: *u8, on_read: *u8) -> c_int {

src/libcore/str.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2059,7 +2059,7 @@ pub fn is_utf8(v: &const [u8]) -> bool {
20592059

20602060
/// Determines if a vector of `u16` contains valid UTF-16
20612061
pub fn is_utf16(v: &[u16]) -> bool {
2062-
let len = vec::len(v);
2062+
let len = v.len();
20632063
let mut i = 0u;
20642064
while (i < len) {
20652065
let u = v[i];
@@ -2103,7 +2103,7 @@ pub fn to_utf16(s: &str) -> ~[u16] {
21032103
}
21042104

21052105
pub fn utf16_chars(v: &[u16], f: &fn(char)) {
2106-
let len = vec::len(v);
2106+
let len = v.len();
21072107
let mut i = 0u;
21082108
while (i < len && v[i] != 0u16) {
21092109
let u = v[i];
@@ -2128,7 +2128,7 @@ pub fn utf16_chars(v: &[u16], f: &fn(char)) {
21282128

21292129
pub fn from_utf16(v: &[u16]) -> ~str {
21302130
let mut buf = ~"";
2131-
reserve(&mut buf, vec::len(v));
2131+
reserve(&mut buf, v.len());
21322132
utf16_chars(v, |ch| push_char(&mut buf, ch));
21332133
buf
21342134
}
@@ -2398,7 +2398,7 @@ static tag_six_b: uint = 252u;
23982398
* # Example
23992399
*
24002400
* ~~~
2401-
* let i = str::as_bytes("Hello World") { |bytes| vec::len(bytes) };
2401+
* let i = str::as_bytes("Hello World") { |bytes| bytes.len() };
24022402
* ~~~
24032403
*/
24042404
#[inline]

src/libfuzzer/ast_match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ fn vec_equal<T>(v: ~[T],
1515
u: ~[T],
1616
element_equality_test: @fn(&&T, &&T) -> bool) ->
1717
bool {
18-
let Lv = vec::len(v);
19-
if Lv != vec::len(u) { return false; }
18+
let Lv = v.len();
19+
if Lv != u.len() { return false; }
2020
let i = 0u;
2121
while i < Lv {
2222
if !element_equality_test(v[i], u[i]) { return false; }

src/libfuzzer/cycles.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn under(r : rand::rng, n : uint) -> uint {
1919

2020
// random choice from a vec
2121
fn choice<T:copy>(r : rand::rng, v : ~[const T]) -> T {
22-
assert!(vec::len(v) != 0u); v[under(r, vec::len(v))]
22+
assert!(v.len() != 0u); v[under(r, v.len())]
2323
}
2424

2525
// k in n chance of being true

src/libfuzzer/rand_util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ fn under(r : rand::rng, n : uint) -> uint {
1818

1919
// random choice from a vec
2020
fn choice<T:copy>(r : rand::rng, v : ~[T]) -> T {
21-
assert!(vec::len(v) != 0u); v[under(r, vec::len(v))]
21+
assert!(v.len() != 0u); v[under(r, v.len())]
2222
}
2323

2424
// 1 in n chance of being true
2525
fn unlikely(r : rand::rng, n : uint) -> bool { under(r, n) == 0u }
2626

2727
// shuffle a vec in place
2828
fn shuffle<T>(r : rand::rng, &v : ~[T]) {
29-
let i = vec::len(v);
29+
let i = v.len();
3030
while i >= 2u {
3131
// Loop invariant: elements with index >= i have been locked in place.
3232
i -= 1u;
@@ -49,7 +49,7 @@ fn shuffled<T:copy>(r : rand::rng, v : ~[T]) -> ~[T] {
4949
// * weighted_vec is O(total weight) space
5050
type weighted<T> = { weight: uint, item: T };
5151
fn weighted_choice<T:copy>(r : rand::rng, v : ~[weighted<T>]) -> T {
52-
assert!(vec::len(v) != 0u);
52+
assert!(v.len() != 0u);
5353
let total = 0u;
5454
for {weight: weight, item: _} in v {
5555
total += weight;

src/librustc/back/rpath.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ pub fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {
137137
abs1.to_str(), abs2.to_str());
138138
let split1: &[~str] = abs1.components;
139139
let split2: &[~str] = abs2.components;
140-
let len1 = vec::len(split1);
141-
let len2 = vec::len(split2);
140+
let len1 = split1.len();
141+
let len2 = split2.len();
142142
assert!(len1 > 0);
143143
assert!(len2 > 0);
144144

src/librustc/driver/driver.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,6 @@ mod test {
905905
use driver::driver::{build_configuration, build_session};
906906
use driver::driver::{build_session_options, optgroups, str_input};
907907

908-
use core::vec;
909908
use std::getopts::groups::getopts;
910909
use std::getopts;
911910
use syntax::attr;
@@ -942,6 +941,6 @@ mod test {
942941
let sess = build_session(sessopts, diagnostic::emit);
943942
let cfg = build_configuration(sess, @~"whatever", &str_input(~""));
944943
let test_items = attr::find_meta_items_by_name(cfg, ~"test");
945-
assert!((vec::len(test_items) == 1u));
944+
assert!(test_items.len() == 1u);
946945
}
947946
}

src/librustc/front/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ fn is_bench_fn(i: @ast::item) -> bool {
206206
fn has_test_signature(i: @ast::item) -> bool {
207207
match i.node {
208208
ast::item_fn(ref decl, _, _, ref generics, _) => {
209-
let input_cnt = vec::len(decl.inputs);
209+
let input_cnt = decl.inputs.len();
210210
let no_output = match decl.output.node {
211211
ast::ty_nil => true,
212212
_ => false

src/librustc/metadata/decoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ fn get_attributes(md: ebml::Doc) -> ~[ast::attribute] {
10631063
let meta_items = get_meta_items(attr_doc);
10641064
// Currently it's only possible to have a single meta item on
10651065
// an attribute
1066-
assert!((vec::len(meta_items) == 1u));
1066+
assert!(meta_items.len() == 1u);
10671067
let meta_item = meta_items[0];
10681068
attrs.push(
10691069
codemap::spanned {

src/librustc/metadata/loader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ pub fn metadata_matches(extern_metas: &[@ast::meta_item],
171171
local_metas: &[@ast::meta_item]) -> bool {
172172

173173
debug!("matching %u metadata requirements against %u items",
174-
vec::len(local_metas), vec::len(extern_metas));
174+
local_metas.len(), extern_metas.len());
175175

176176
for local_metas.each |needed| {
177177
if !attr::contains(extern_metas, *needed) {

src/librustc/metadata/tydecode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ fn parse_sig(st: @mut PState, conv: conv_did) -> ty::FnSig {
507507
// Rust metadata parsing
508508
pub fn parse_def_id(buf: &[u8]) -> ast::def_id {
509509
let mut colon_idx = 0u;
510-
let len = vec::len(buf);
510+
let len = buf.len();
511511
while colon_idx < len && buf[colon_idx] != ':' as u8 { colon_idx += 1u; }
512512
if colon_idx == len {
513513
error!("didn't find ':' when parsing def id");

src/librustc/middle/kind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ fn is_nullary_variant(cx: Context, ex: @expr) -> bool {
360360
expr_path(_) => {
361361
match cx.tcx.def_map.get_copy(&ex.id) {
362362
def_variant(edid, vdid) => {
363-
vec::len(ty::enum_variant_with_id(cx.tcx, edid, vdid).args) == 0u
363+
vec::len(ty::enum_variant_with_id(cx.tcx, edid, vdid).args) == 0u
364364
}
365365
_ => false
366366
}

src/librustc/middle/region.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ pub impl RegionMaps {
283283

284284
let a_ancestors = ancestors_of(self, scope_a);
285285
let b_ancestors = ancestors_of(self, scope_b);
286-
let mut a_index = vec::len(a_ancestors) - 1u;
287-
let mut b_index = vec::len(b_ancestors) - 1u;
286+
let mut a_index = a_ancestors.len() - 1u;
287+
let mut b_index = b_ancestors.len() - 1u;
288288

289289
// Here, ~[ab]_ancestors is a vector going from narrow to broad.
290290
// The end of each vector will be the item where the scope is

src/librustc/middle/resolve.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4706,7 +4706,7 @@ pub impl Resolver {
47064706
}
47074707
}
47084708

4709-
if vec::len(values) > 0 &&
4709+
if values.len() > 0 &&
47104710
values[smallest] != uint::max_value &&
47114711
values[smallest] < str::len(name) + 2 &&
47124712
values[smallest] <= max_distance &&

src/librustc/middle/resolve_stage0.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4720,7 +4720,7 @@ pub impl Resolver {
47204720
}
47214721
}
47224722

4723-
if vec::len(values) > 0 &&
4723+
if values.len() > 0 &&
47244724
values[smallest] != uint::max_value &&
47254725
values[smallest] < str::len(name) + 2 &&
47264726
values[smallest] <= max_distance &&

0 commit comments

Comments
 (0)