Skip to content

Rename vec::len(var) to var.len() #6487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .swo
Binary file not shown.
12 changes: 6 additions & 6 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
fatal(~"gdb failed to execute");
}

let num_check_lines = vec::len(check_lines);
let num_check_lines = check_lines.len();
if num_check_lines > 0 {
// check if each line in props.check_lines appears in the
// output (in order)
Expand Down Expand Up @@ -303,7 +303,7 @@ fn check_error_patterns(props: &TestProps,
if str::contains(line, *next_err_pat) {
debug!("found error pattern %s", *next_err_pat);
next_err_idx += 1u;
if next_err_idx == vec::len(props.error_patterns) {
if next_err_idx == props.error_patterns.len() {
debug!("found all error patterns");
done = true;
break;
Expand All @@ -315,8 +315,8 @@ fn check_error_patterns(props: &TestProps,

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

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

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

for uint::range(0u, vec::len(found_flags)) |i| {
for uint::range(0u, found_flags.len()) |i| {
if !found_flags[i] {
let ee = &expected_errors[i];
fatal_ProcRes(fmt!("expected %s on line %u not found: %s",
Expand Down
20 changes: 10 additions & 10 deletions src/libcore/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,14 @@ fn test_lefts() {
fn test_lefts_none() {
let input: ~[Either<int, int>] = ~[Right(10), Right(10)];
let result = lefts(input);
assert_eq!(vec::len(result), 0u);
assert_eq!(result.len(), 0u);
}

#[test]
fn test_lefts_empty() {
let input: ~[Either<int, int>] = ~[];
let result = lefts(input);
assert_eq!(vec::len(result), 0u);
assert_eq!(result.len(), 0u);
}

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

#[test]
fn test_rights_empty() {
let input: ~[Either<int, int>] = ~[];
let result = rights(input);
assert_eq!(vec::len(result), 0u);
assert_eq!(result.len(), 0u);
}

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

#[test]
fn test_partition_no_rights() {
let input: ~[Either<int, int>] = ~[Left(10), Left(11)];
let (lefts, rights) = partition(input);
assert_eq!(vec::len(lefts), 2u);
assert_eq!(vec::len(rights), 0u);
assert_eq!(lefts.len(), 2u);
assert_eq!(rights.len(), 0u);
}

#[test]
fn test_partition_empty() {
let input: ~[Either<int, int>] = ~[];
let (lefts, rights) = partition(input);
assert_eq!(vec::len(lefts), 0u);
assert_eq!(vec::len(rights), 0u);
assert_eq!(lefts.len(), 0u);
assert_eq!(rights.len(), 0u);
}
12 changes: 6 additions & 6 deletions src/libcore/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,10 +673,10 @@ impl<T:Reader> ReaderUtil for T {

fn read_char(&self) -> char {
let c = self.read_chars(1);
if vec::len(c) == 0 {
if c.len() == 0 {
return -1 as char; // FIXME will this stay valid? // #2004
}
assert!((vec::len(c) == 1));
assert!(c.len() == 1);
return c[0];
}

Expand Down Expand Up @@ -1802,7 +1802,7 @@ mod tests {
fn test_readchars_empty() {
do io::with_str_reader(~"") |inp| {
let res : ~[char] = inp.read_chars(128);
assert!((vec::len(res) == 0));
assert!(res.len() == 0);
}
}

Expand Down Expand Up @@ -1841,10 +1841,10 @@ mod tests {
fn check_read_ln(len : uint, s: &str, ivals: &[int]) {
do io::with_str_reader(s) |inp| {
let res : ~[char] = inp.read_chars(len);
if (len <= vec::len(ivals)) {
assert!((vec::len(res) == len));
if len <= ivals.len() {
assert!(res.len() == len);
}
assert!(vec::slice(ivals, 0u, vec::len(res)) ==
assert!(vec::slice(ivals, 0u, res.len()) ==
vec::map(res, |x| *x as int));
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ pub fn self_exe_path() -> Option<Path> {
KERN_PROC as c_int,
KERN_PROC_PATHNAME as c_int, -1 as c_int];
let mut sz = sz;
sysctl(vec::raw::to_ptr(mib), vec::len(mib) as ::libc::c_uint,
sysctl(vec::raw::to_ptr(mib), mib.len() as ::libc::c_uint,
buf as *mut c_void, &mut sz, ptr::null(),
0u as size_t) == (0 as c_int)
}
Expand Down Expand Up @@ -1490,7 +1490,7 @@ mod tests {
#[ignore]
fn test_env_getenv() {
let e = env();
assert!(vec::len(e) > 0u);
assert!(e.len() > 0u);
for e.each |p| {
let (n, v) = copy *p;
debug!(copy n);
Expand Down Expand Up @@ -1581,7 +1581,7 @@ mod tests {
fn list_dir() {
let dirs = os::list_dir(&Path("."));
// Just assuming that we've got some contents in the current directory
assert!((vec::len(dirs) > 0u));
assert!(dirs.len() > 0u);

for dirs.each |dir| {
debug!(copy *dir);
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ pub mod ptr_tests {
let arr_ptr = &arr[0];
let mut ctr = 0;
let mut iteration_count = 0;
array_each_with_len(arr_ptr, vec::len(arr),
array_each_with_len(arr_ptr, arr.len(),
|e| {
let actual = str::raw::from_c_str(e);
let expected = copy expected_arr[ctr];
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/rt/uvll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pub unsafe fn accept(server: *c_void, client: *c_void) -> c_int {

pub unsafe fn write<T>(req: *uv_write_t, stream: *T, buf_in: &[uv_buf_t], cb: *u8) -> c_int {
let buf_ptr = vec::raw::to_ptr(buf_in);
let buf_cnt = vec::len(buf_in) as i32;
let buf_cnt = buf_in.len() as i32;
return rust_uv_write(req as *c_void, stream as *c_void, buf_ptr, buf_cnt, cb);
}
pub unsafe fn read_start(stream: *uv_stream_t, on_alloc: *u8, on_read: *u8) -> c_int {
Expand Down
8 changes: 4 additions & 4 deletions src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2059,7 +2059,7 @@ pub fn is_utf8(v: &const [u8]) -> bool {

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

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

pub fn from_utf16(v: &[u16]) -> ~str {
let mut buf = ~"";
reserve(&mut buf, vec::len(v));
reserve(&mut buf, v.len());
utf16_chars(v, |ch| push_char(&mut buf, ch));
buf
}
Expand Down Expand Up @@ -2398,7 +2398,7 @@ static tag_six_b: uint = 252u;
* # Example
*
* ~~~
* let i = str::as_bytes("Hello World") { |bytes| vec::len(bytes) };
* let i = str::as_bytes("Hello World") { |bytes| bytes.len() };
* ~~~
*/
#[inline]
Expand Down
4 changes: 2 additions & 2 deletions src/libfuzzer/ast_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ fn vec_equal<T>(v: ~[T],
u: ~[T],
element_equality_test: @fn(&&T, &&T) -> bool) ->
bool {
let Lv = vec::len(v);
if Lv != vec::len(u) { return false; }
let Lv = v.len();
if Lv != u.len() { return false; }
let i = 0u;
while i < Lv {
if !element_equality_test(v[i], u[i]) { return false; }
Expand Down
2 changes: 1 addition & 1 deletion src/libfuzzer/cycles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn under(r : rand::rng, n : uint) -> uint {

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

// k in n chance of being true
Expand Down
6 changes: 3 additions & 3 deletions src/libfuzzer/rand_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ fn under(r : rand::rng, n : uint) -> uint {

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

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

// shuffle a vec in place
fn shuffle<T>(r : rand::rng, &v : ~[T]) {
let i = vec::len(v);
let i = v.len();
while i >= 2u {
// Loop invariant: elements with index >= i have been locked in place.
i -= 1u;
Expand All @@ -49,7 +49,7 @@ fn shuffled<T:copy>(r : rand::rng, v : ~[T]) -> ~[T] {
// * weighted_vec is O(total weight) space
type weighted<T> = { weight: uint, item: T };
fn weighted_choice<T:copy>(r : rand::rng, v : ~[weighted<T>]) -> T {
assert!(vec::len(v) != 0u);
assert!(v.len() != 0u);
let total = 0u;
for {weight: weight, item: _} in v {
total += weight;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/back/rpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ pub fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {
abs1.to_str(), abs2.to_str());
let split1: &[~str] = abs1.components;
let split2: &[~str] = abs2.components;
let len1 = vec::len(split1);
let len2 = vec::len(split2);
let len1 = split1.len();
let len2 = split2.len();
assert!(len1 > 0);
assert!(len2 > 0);

Expand Down
3 changes: 1 addition & 2 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,6 @@ mod test {
use driver::driver::{build_configuration, build_session};
use driver::driver::{build_session_options, optgroups, str_input};

use core::vec;
use std::getopts::groups::getopts;
use std::getopts;
use syntax::attr;
Expand Down Expand Up @@ -942,6 +941,6 @@ mod test {
let sess = build_session(sessopts, diagnostic::emit);
let cfg = build_configuration(sess, @~"whatever", &str_input(~""));
let test_items = attr::find_meta_items_by_name(cfg, ~"test");
assert!((vec::len(test_items) == 1u));
assert!(test_items.len() == 1u);
}
}
2 changes: 1 addition & 1 deletion src/librustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ fn is_bench_fn(i: @ast::item) -> bool {
fn has_test_signature(i: @ast::item) -> bool {
match i.node {
ast::item_fn(ref decl, _, _, ref generics, _) => {
let input_cnt = vec::len(decl.inputs);
let input_cnt = decl.inputs.len();
let no_output = match decl.output.node {
ast::ty_nil => true,
_ => false
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ fn get_attributes(md: ebml::Doc) -> ~[ast::attribute] {
let meta_items = get_meta_items(attr_doc);
// Currently it's only possible to have a single meta item on
// an attribute
assert!((vec::len(meta_items) == 1u));
assert!(meta_items.len() == 1u);
let meta_item = meta_items[0];
attrs.push(
codemap::spanned {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub fn metadata_matches(extern_metas: &[@ast::meta_item],
local_metas: &[@ast::meta_item]) -> bool {

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

for local_metas.each |needed| {
if !attr::contains(extern_metas, *needed) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ fn parse_sig(st: @mut PState, conv: conv_did) -> ty::FnSig {
// Rust metadata parsing
pub fn parse_def_id(buf: &[u8]) -> ast::def_id {
let mut colon_idx = 0u;
let len = vec::len(buf);
let len = buf.len();
while colon_idx < len && buf[colon_idx] != ':' as u8 { colon_idx += 1u; }
if colon_idx == len {
error!("didn't find ':' when parsing def id");
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ fn is_nullary_variant(cx: Context, ex: @expr) -> bool {
expr_path(_) => {
match cx.tcx.def_map.get_copy(&ex.id) {
def_variant(edid, vdid) => {
vec::len(ty::enum_variant_with_id(cx.tcx, edid, vdid).args) == 0u
vec::len(ty::enum_variant_with_id(cx.tcx, edid, vdid).args) == 0u
}
_ => false
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ pub impl RegionMaps {

let a_ancestors = ancestors_of(self, scope_a);
let b_ancestors = ancestors_of(self, scope_b);
let mut a_index = vec::len(a_ancestors) - 1u;
let mut b_index = vec::len(b_ancestors) - 1u;
let mut a_index = a_ancestors.len() - 1u;
let mut b_index = b_ancestors.len() - 1u;

// Here, ~[ab]_ancestors is a vector going from narrow to broad.
// The end of each vector will be the item where the scope is
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4693,7 +4693,7 @@ pub impl Resolver {
}
}

if vec::len(values) > 0 &&
if values.len() > 0 &&
values[smallest] != uint::max_value &&
values[smallest] < str::len(name) + 2 &&
values[smallest] <= max_distance &&
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/resolve_stage0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4720,7 +4720,7 @@ pub impl Resolver {
}
}

if vec::len(values) > 0 &&
if values.len() > 0 &&
values[smallest] != uint::max_value &&
values[smallest] < str::len(name) + 2 &&
values[smallest] <= max_distance &&
Expand Down
Loading