Skip to content

Commit

Permalink
Fix fallout from Vec stabilization
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Sep 22, 2014
1 parent 087b928 commit 0169218
Show file tree
Hide file tree
Showing 29 changed files with 141 additions and 156 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
49 changes: 10 additions & 39 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,38 +273,18 @@ impl<T> Vec<T> {
}

impl<T: Clone> Vec<T> {
/// Iterates over the `second` vector, copying each element and appending it to
/// the `first`. Afterwards, the `first` is then returned for use again.
///
/// # Example
///
/// ```
/// let vec = vec![1i, 2i];
/// let vec = vec.append([3i, 4i]);
/// assert_eq!(vec, vec![1, 2, 3, 4]);
/// ```
/// Deprecated, call `extend` instead.
#[inline]
#[deprecated = "this function has been deprecated in favor of extend()"]
pub fn append(mut self, second: &[T]) -> Vec<T> {
self.push_all(second);
self
}

/// Constructs a `Vec` by cloning elements of a slice.
///
/// # Example
///
/// ```
/// let slice = [1i, 2, 3];
/// let vec = Vec::from_slice(slice);
/// ```
/// Deprecated, call `to_vec()` instead
#[inline]
#[deprecated = "this function has been deprecated in favor of to_vec()"]
pub fn from_slice(values: &[T]) -> Vec<T> {
let mut vector = Vec::new();
vector.push_all(values);
vector
}
pub fn from_slice(values: &[T]) -> Vec<T> { values.to_vec() }

/// Constructs a `Vec` with copies of a value.
///
Expand Down Expand Up @@ -442,9 +422,7 @@ impl<T: Clone> Vec<T> {

#[unstable]
impl<T:Clone> Clone for Vec<T> {
fn clone(&self) -> Vec<T> {
Vec::from_slice(self.as_slice())
}
fn clone(&self) -> Vec<T> { self.as_slice().to_vec() }

fn clone_from(&mut self, other: &Vec<T>) {
// drop anything in self that will not be overwritten
Expand Down Expand Up @@ -736,16 +714,7 @@ impl<T> Vec<T> {
}
}

/// Appends one element to the vector provided. The vector itself is then
/// returned for use again.
///
/// # Example
///
/// ```
/// let vec = vec![1i, 2];
/// let vec = vec.append_one(3);
/// assert_eq!(vec, vec![1, 2, 3]);
/// ```
/// Deprecated, call `push` instead
#[inline]
#[deprecated = "call .push() instead"]
pub fn append_one(mut self, x: T) -> Vec<T> {
Expand All @@ -765,7 +734,7 @@ impl<T> Vec<T> {
/// vec.truncate(2);
/// assert_eq!(vec, vec![1, 2]);
/// ```
#[stable]
#[unstable = "waiting on failure semantics"]
pub fn truncate(&mut self, len: uint) {
unsafe {
// drop any extra elements
Expand Down Expand Up @@ -1123,7 +1092,7 @@ impl<T> Vec<T> {
/// vec.insert(4, 5);
/// assert_eq!(vec, vec![1, 4, 2, 3, 5]);
/// ```
#[stable]
#[unstable = "failure semantics need settling"]
pub fn insert(&mut self, index: uint, element: T) {
let len = self.len();
assert!(index <= len);
Expand Down Expand Up @@ -1160,7 +1129,7 @@ impl<T> Vec<T> {
/// // v is unchanged:
/// assert_eq!(v, vec![1, 3]);
/// ```
#[stable]
#[unstable = "failure semantics need settling"]
pub fn remove(&mut self, index: uint) -> Option<T> {
let len = self.len();
if index < len {
Expand Down Expand Up @@ -1192,11 +1161,13 @@ impl<T> Vec<T> {
/// # Example
///
/// ```
/// # #![allow(deprecated)]
/// let mut vec = vec![box 1i];
/// vec.push_all_move(vec![box 2, box 3, box 4]);
/// assert_eq!(vec, vec![box 1, box 2, box 3, box 4]);
/// ```
#[inline]
#[deprecated = "use .extend(other.into_iter())"]
pub fn push_all_move(&mut self, other: Vec<T>) {
self.extend(other.into_iter());
}
Expand Down
2 changes: 1 addition & 1 deletion src/libgraphviz/maybe_owned_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl<'a,T:Clone> MaybeOwnedVector<'a,T> {
pub fn into_vec(self) -> Vec<T> {
match self {
Growable(v) => v,
Borrowed(v) => Vec::from_slice(v),
Borrowed(v) => v.to_vec(),
}
}
}
2 changes: 1 addition & 1 deletion src/librbml/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl Writer for SeekableMemWriter {
// currently are
let difference = self.pos as i64 - self.buf.len() as i64;
if difference > 0 {
self.buf.grow(difference as uint, &0);
self.buf.grow(difference as uint, 0);
}

// Figure out what bytes will be used to overwrite what's currently
Expand Down
2 changes: 1 addition & 1 deletion src/libregex/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl<'r> Compiler<'r> {
Capture(cap, name, x) => {
let len = self.names.len();
if cap >= len {
self.names.grow(10 + cap - len, &None)
self.names.grow(10 + cap - len, None)
}
*self.names.get_mut(cap) = name;

Expand Down
Loading

5 comments on commit 0169218

@bors
Copy link
Contributor

@bors bors commented on 0169218 Sep 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from aturon
at alexcrichton@0169218

@bors
Copy link
Contributor

@bors bors commented on 0169218 Sep 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/vec-stable = 0169218 into auto

@bors
Copy link
Contributor

@bors bors commented on 0169218 Sep 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/vec-stable = 0169218 merged ok, testing candidate = cbb07e8

@bors
Copy link
Contributor

@bors bors commented on 0169218 Sep 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 0169218 Sep 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = cbb07e8

Please sign in to comment.