Skip to content

Commit

Permalink
auto merge of #17029 : alexcrichton/rust/vec-stable, r=aturon
Browse files Browse the repository at this point in the history
The following methods, types, and names have become stable:

* Vec
* Vec::as_mut_slice
* Vec::as_slice
* Vec::capacity
* Vec::clear
* Vec::default
* Vec::grow
* Vec::insert
* Vec::len
* Vec::new
* Vec::pop
* Vec::push
* Vec::remove
* Vec::set_len
* Vec::shrink_to_fit
* Vec::truncate
* Vec::with_capacity
* vec::raw
* vec::raw::from_buf
* vec::raw::from_raw_parts

The following have become unstable:

* Vec::dedup        // naming
* Vec::from_fn      // naming and unboxed closures
* Vec::get_mut      // will be removed for IndexMut
* Vec::grow_fn      // unboxed closures and naming
* Vec::retain       // unboxed closures
* Vec::swap_remove  // uncertain naming
* Vec::from_elem    // uncertain semantics
* vec::unzip        // should be generic for all collections

The following have been deprecated

* Vec::append - call .extend()
* Vec::append_one - call .push()
* Vec::from_slice - call .to_vec()
* Vec::grow_set - call .grow() and then .push()
* Vec::into_vec - move the vector instead
* Vec::move_iter - renamed to iter_move()
* Vec::push_all - call .extend()
* Vec::to_vec - call .clone()
* Vec:from_raw_parts - moved to raw::from_raw_parts

This is a breaking change in terms of the signature of the `Vec::grow` function.
The argument used to be taken by reference, but it is now taken by value. Code
must update by removing a leading `&` sigil or by calling `.clone()` to create a
value.

[breaking-change]
  • Loading branch information
bors committed Sep 22, 2014
2 parents 4e5b626 + 0169218 commit cbb07e8
Show file tree
Hide file tree
Showing 39 changed files with 250 additions and 208 deletions.
59 changes: 30 additions & 29 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ fn run_pretty_test(config: &Config, props: &TestProps, testfile: &Path) {
format!("--target={}", config.target),
"-L".to_string(),
aux_dir.as_str().unwrap().to_string());
args.push_all_move(split_maybe_args(&config.target_rustcflags));
args.push_all_move(split_maybe_args(&props.compile_flags));
args.extend(split_maybe_args(&config.target_rustcflags).into_iter());
args.extend(split_maybe_args(&props.compile_flags).into_iter());
return ProcArgs {
prog: config.rustc_path.as_str().unwrap().to_string(),
args: args,
Expand Down Expand Up @@ -321,8 +321,8 @@ actual:\n\
config.build_base.as_str().unwrap().to_string(),
"-L".to_string(),
aux_dir.as_str().unwrap().to_string());
args.push_all_move(split_maybe_args(&config.target_rustcflags));
args.push_all_move(split_maybe_args(&props.compile_flags));
args.extend(split_maybe_args(&config.target_rustcflags).into_iter());
args.extend(split_maybe_args(&props.compile_flags).into_iter());
// FIXME (#9639): This needs to handle non-utf8 paths
return ProcArgs {
prog: config.rustc_path.as_str().unwrap().to_string(),
Expand Down Expand Up @@ -1095,11 +1095,12 @@ fn compile_test_(config: &Config, props: &TestProps,
testfile: &Path, extra_args: &[String]) -> ProcRes {
let aux_dir = aux_output_dir_name(config, testfile);
// FIXME (#9639): This needs to handle non-utf8 paths
let link_args = vec!("-L".to_string(),
aux_dir.as_str().unwrap().to_string());
let mut link_args = vec!("-L".to_string(),
aux_dir.as_str().unwrap().to_string());
link_args.extend(extra_args.iter().map(|s| s.clone()));
let args = make_compile_args(config,
props,
link_args.append(extra_args),
link_args,
|a, b| ThisFile(make_exe_name(a, b)), testfile);
compose_and_run_compiler(config, props, testfile, args, None)
}
Expand Down Expand Up @@ -1146,16 +1147,16 @@ fn compose_and_run_compiler(
for rel_ab in props.aux_builds.iter() {
let abs_ab = config.aux_base.join(rel_ab.as_slice());
let aux_props = header::load_props(&abs_ab);
let crate_type = if aux_props.no_prefer_dynamic {
let mut crate_type = if aux_props.no_prefer_dynamic {
Vec::new()
} else {
vec!("--crate-type=dylib".to_string())
};
crate_type.extend(extra_link_args.clone().into_iter());
let aux_args =
make_compile_args(config,
&aux_props,
crate_type.append(
extra_link_args.as_slice()),
crate_type,
|a,b| {
let f = make_lib_name(a, b, testfile);
ThisDirectory(f.dir_path())
Expand Down Expand Up @@ -1246,11 +1247,11 @@ fn make_compile_args(config: &Config,
};
args.push(path.as_str().unwrap().to_string());
if props.force_host {
args.push_all_move(split_maybe_args(&config.host_rustcflags));
args.extend(split_maybe_args(&config.host_rustcflags).into_iter());
} else {
args.push_all_move(split_maybe_args(&config.target_rustcflags));
args.extend(split_maybe_args(&config.target_rustcflags).into_iter());
}
args.push_all_move(split_maybe_args(&props.compile_flags));
args.extend(split_maybe_args(&props.compile_flags).into_iter());
return ProcArgs {
prog: config.rustc_path.as_str().unwrap().to_string(),
args: args,
Expand All @@ -1267,10 +1268,9 @@ fn make_lib_name(config: &Config, auxfile: &Path, testfile: &Path) -> Path {
fn make_exe_name(config: &Config, testfile: &Path) -> Path {
let mut f = output_base_name(config, testfile);
if !os::consts::EXE_SUFFIX.is_empty() {
match f.filename().map(|s| Vec::from_slice(s).append(os::consts::EXE_SUFFIX.as_bytes())) {
Some(v) => f.set_filename(v),
None => ()
}
let mut fname = f.filename().unwrap().to_vec();
fname.extend(os::consts::EXE_SUFFIX.bytes());
f.set_filename(fname);
}
f
}
Expand All @@ -1286,7 +1286,7 @@ fn make_run_args(config: &Config, props: &TestProps, testfile: &Path) ->
args.push(exe_file.as_str().unwrap().to_string());

// Add the arguments in the run_flags directive
args.push_all_move(split_maybe_args(&props.run_flags));
args.extend(split_maybe_args(&props.run_flags).into_iter());

let prog = args.remove(0).unwrap();
return ProcArgs {
Expand Down Expand Up @@ -1381,12 +1381,10 @@ fn make_out_name(config: &Config, testfile: &Path, extension: &str) -> Path {
}

fn aux_output_dir_name(config: &Config, testfile: &Path) -> Path {
let mut f = output_base_name(config, testfile);
match f.filename().map(|s| Vec::from_slice(s).append(b".libaux")) {
Some(v) => f.set_filename(v),
None => ()
}
f
let f = output_base_name(config, testfile);
let mut fname = f.filename().unwrap().to_vec();
fname.extend("libaux".bytes());
f.with_filename(fname)
}

fn output_testname(testfile: &Path) -> Path {
Expand Down Expand Up @@ -1598,22 +1596,25 @@ fn append_suffix_to_stem(p: &Path, suffix: &str) -> Path {
if suffix.len() == 0 {
(*p).clone()
} else {
let stem = p.filestem().unwrap();
p.with_filename(Vec::from_slice(stem).append(b"-").append(suffix.as_bytes()))
let mut stem = p.filestem().unwrap().to_vec();
stem.extend("-".bytes());
stem.extend(suffix.bytes());
p.with_filename(stem)
}
}

fn compile_test_and_save_bitcode(config: &Config, props: &TestProps,
testfile: &Path) -> ProcRes {
let aux_dir = aux_output_dir_name(config, testfile);
// FIXME (#9639): This needs to handle non-utf8 paths
let link_args = vec!("-L".to_string(),
aux_dir.as_str().unwrap().to_string());
let mut link_args = vec!("-L".to_string(),
aux_dir.as_str().unwrap().to_string());
let llvm_args = vec!("--emit=bc,obj".to_string(),
"--crate-type=lib".to_string());
link_args.extend(llvm_args.into_iter());
let args = make_compile_args(config,
props,
link_args.append(llvm_args.as_slice()),
link_args,
|a, b| ThisDirectory(output_base_name(a, b).dir_path()),
testfile);
compose_and_run_compiler(config, props, testfile, args, None)
Expand Down
5 changes: 3 additions & 2 deletions src/doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -3833,8 +3833,9 @@ fn map<A: Clone, B: Clone>(f: |A| -> B, xs: &[A]) -> Vec<B> {
return vec![];
}
let first: B = f(xs[0].clone());
let rest: Vec<B> = map(f, xs.slice(1, xs.len()));
return vec![first].append(rest.as_slice());
let mut rest: Vec<B> = map(f, xs.slice(1, xs.len()));
rest.insert(0, first);
return rest;
}
~~~~

Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ impl Bitv {
let old_size = self.storage.len();
let size = (size + uint::BITS - 1) / uint::BITS;
if old_size < size {
self.storage.grow(size - old_size, &0);
self.storage.grow(size - old_size, 0);
}
}

Expand Down Expand Up @@ -687,7 +687,7 @@ impl Bitv {
// Allocate new words, if needed
if new_nwords > self.storage.len() {
let to_add = new_nwords - self.storage.len();
self.storage.grow(to_add, &full_value);
self.storage.grow(to_add, full_value);
}
// Adjust internal bit count
self.nbits = new_nbits;
Expand Down
10 changes: 7 additions & 3 deletions src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ pub trait CloneableVector<T> {
impl<'a, T: Clone> CloneableVector<T> for &'a [T] {
/// Returns a copy of `v`.
#[inline]
fn to_vec(&self) -> Vec<T> { Vec::from_slice(*self) }
fn to_vec(&self) -> Vec<T> {
let mut vector = Vec::with_capacity(self.len());
vector.push_all(*self);
vector
}

#[inline(always)]
fn into_vec(self) -> Vec<T> { self.to_vec() }
Expand Down Expand Up @@ -1039,7 +1043,7 @@ mod tests {
fn test_grow() {
// Test on-stack grow().
let mut v = vec![];
v.grow(2u, &1i);
v.grow(2u, 1i);
{
let v = v.as_slice();
assert_eq!(v.len(), 2u);
Expand All @@ -1048,7 +1052,7 @@ mod tests {
}

// Test on-heap grow().
v.grow(3u, &2i);
v.grow(3u, 2i);
{
let v = v.as_slice();
assert_eq!(v.len(), 5u);
Expand Down
3 changes: 2 additions & 1 deletion src/libcollections/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ use core::prelude::{range};
use {Deque, MutableSeq};
use hash;
use ringbuf::RingBuf;
use slice::CloneableVector;
use string::String;
use unicode;
use vec::Vec;
Expand Down Expand Up @@ -754,7 +755,7 @@ pub trait StrAllocating: Str {
#[inline]
fn to_owned(&self) -> String {
unsafe {
mem::transmute(Vec::from_slice(self.as_slice().as_bytes()))
mem::transmute(self.as_slice().as_bytes().to_vec())
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use core::raw::Slice as RawSlice;

use {Mutable, MutableSeq};
use hash;
use slice::CloneableVector;
use str;
use str::{CharRange, StrAllocating, MaybeOwned, Owned};
use str::Slice as MaybeOwnedSlice; // So many `Slice`s...
Expand Down Expand Up @@ -75,9 +76,7 @@ impl String {
/// ```
#[inline]
pub fn from_str(string: &str) -> String {
String {
vec: Vec::from_slice(string.as_bytes())
}
String { vec: string.as_bytes().to_vec() }
}

/// Deprecated. Replaced by `string::raw::from_parts`
Expand Down
Loading

0 comments on commit cbb07e8

Please sign in to comment.