Skip to content

Commit 9fb8741

Browse files
committed
Handle breakage after libcore split
API Changes: - &[T] and ~[T] no longer support the addition operator (+)
1 parent 300d865 commit 9fb8741

File tree

23 files changed

+75
-70
lines changed

23 files changed

+75
-70
lines changed

src/compiletest/runtest.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ fn make_lib_name(config: &config, auxfile: &Path, testfile: &Path) -> Path {
997997
fn make_exe_name(config: &config, testfile: &Path) -> Path {
998998
let mut f = output_base_name(config, testfile);
999999
if !os::consts::EXE_SUFFIX.is_empty() {
1000-
match f.filename().map(|s| s + os::consts::EXE_SUFFIX.as_bytes()) {
1000+
match f.filename().map(|s| Vec::from_slice(s).append(os::consts::EXE_SUFFIX.as_bytes())) {
10011001
Some(v) => f.set_filename(v),
10021002
None => ()
10031003
}
@@ -1091,7 +1091,7 @@ fn make_out_name(config: &config, testfile: &Path, extension: &str) -> Path {
10911091

10921092
fn aux_output_dir_name(config: &config, testfile: &Path) -> Path {
10931093
let mut f = output_base_name(config, testfile);
1094-
match f.filename().map(|s| s + bytes!(".libaux")) {
1094+
match f.filename().map(|s| Vec::from_slice(s).append(bytes!(".libaux"))) {
10951095
Some(v) => f.set_filename(v),
10961096
None => ()
10971097
}
@@ -1273,7 +1273,7 @@ fn append_suffix_to_stem(p: &Path, suffix: &str) -> Path {
12731273
(*p).clone()
12741274
} else {
12751275
let stem = p.filestem().unwrap();
1276-
p.with_filename(stem + bytes!("-") + suffix.as_bytes())
1276+
p.with_filename(Vec::from_slice(stem).append(bytes!("-")).append(suffix.as_bytes()))
12771277
}
12781278
}
12791279

src/doc/rust.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3604,7 +3604,7 @@ fn map<A: Clone, B: Clone>(f: |A| -> B, xs: &[A]) -> Vec<B> {
36043604
}
36053605
let first: B = f(xs[0].clone());
36063606
let rest: Vec<B> = map(f, xs.slice(1, xs.len()));
3607-
return [first] + rest;
3607+
return vec![first].append(rest.as_slice());
36083608
}
36093609
~~~~
36103610

src/libcore/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,6 @@ mod std {
111111
#[cfg(test)] pub use realstd::rt; // needed for fail!()
112112
#[cfg(test)] pub use realstd::option; // needed for assert!()
113113
#[cfg(test)] pub use realstd::os; // needed for tests
114+
#[cfg(test)] pub use realstd::slice; // needed for tests
115+
#[cfg(test)] pub use realstd::vec; // needed for vec![]
114116
}

src/libcore/should_not_exist.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ use char::Char;
1313
use clone::Clone;
1414
use container::Container;
1515
use default::Default;
16+
use finally::try_finally;
1617
use intrinsics;
17-
use iter::{Iterator, FromIterator};
18+
use iter::{range, Iterator, FromIterator};
1819
use mem;
1920
use num::{CheckedMul, CheckedAdd};
2021
use option::{Some, None};
@@ -25,7 +26,6 @@ use slice::ImmutableVector;
2526
use str::StrSlice;
2627

2728
#[cfg(not(test))] use ops::Add;
28-
#[cfg(not(test))] use slice::Vector;
2929

3030
#[allow(ctypes)]
3131
extern {
@@ -147,6 +147,34 @@ impl<'a> Add<&'a str,~str> for &'a str {
147147
impl<A: Clone> Clone for ~[A] {
148148
#[inline]
149149
fn clone(&self) -> ~[A] {
150-
self.iter().map(|a| a.clone()).collect()
150+
let len = self.len();
151+
let data_size = len.checked_mul(&mem::size_of::<A>()).unwrap();
152+
let size = mem::size_of::<Vec<()>>().checked_add(&data_size).unwrap();
153+
154+
unsafe {
155+
let ret = alloc(size) as *mut Vec<A>;
156+
157+
(*ret).fill = len * mem::nonzero_size_of::<A>();
158+
(*ret).alloc = len * mem::nonzero_size_of::<A>();
159+
160+
let mut i = 0;
161+
let p = &mut (*ret).data as *mut _ as *mut A;
162+
try_finally(
163+
&mut i, (),
164+
|i, ()| while *i < len {
165+
mem::move_val_init(
166+
&mut(*p.offset(*i as int)),
167+
self.unsafe_ref(*i).clone());
168+
*i += 1;
169+
},
170+
|i| if *i < len {
171+
// we must be failing, clean up after ourselves
172+
for j in range(0, *i as int) {
173+
ptr::read(&*p.offset(j));
174+
}
175+
free(ret as *u8);
176+
});
177+
cast::transmute(ret)
178+
}
151179
}
152180
}

src/librustc/middle/trans/base.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,11 +2110,11 @@ pub fn write_metadata(cx: &CrateContext, krate: &ast::Crate) -> Vec<u8> {
21102110

21112111
let encode_parms = crate_ctxt_to_encode_parms(cx, encode_inlined_item);
21122112
let metadata = encoder::encode_metadata(encode_parms, krate);
2113-
let compressed = encoder::metadata_encoding_version +
2114-
match flate::deflate_bytes(metadata.as_slice()) {
2115-
Some(compressed) => compressed,
2116-
None => cx.sess().fatal(format!("failed to compress metadata", ))
2117-
}.as_slice();
2113+
let compressed = Vec::from_slice(encoder::metadata_encoding_version)
2114+
.append(match flate::deflate_bytes(metadata.as_slice()) {
2115+
Some(compressed) => compressed,
2116+
None => cx.sess().fatal(format!("failed to compress metadata"))
2117+
}.as_slice());
21182118
let llmeta = C_bytes(cx, compressed.as_slice());
21192119
let llconst = C_struct(cx, [llmeta], false);
21202120
let name = format!("rust_metadata_{}_{}_{}", cx.link_meta.crateid.name,

src/librustc/middle/trans/monomorphize.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,9 @@ pub fn monomorphic_fn(ccx: &CrateContext,
157157
// This is a bit unfortunate.
158158

159159
let idx = real_substs.tps.len() - num_method_ty_params;
160-
let substs = real_substs.tps.slice(0, idx) +
161-
&[real_substs.self_ty.unwrap()] + real_substs.tps.tailn(idx);
160+
let substs = Vec::from_slice(real_substs.tps.slice(0, idx))
161+
.append([real_substs.self_ty.unwrap()])
162+
.append(real_substs.tps.tailn(idx));
162163
debug!("static default: changed substitution to {}",
163164
substs.repr(ccx.tcx()));
164165

src/librustdoc/html/render.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,8 @@ impl<'a> SourceCollector<'a> {
549549
root_path.push_str("../");
550550
});
551551

552-
cur.push(p.filename().expect("source has no filename") + bytes!(".html"));
552+
cur.push(Vec::from_slice(p.filename().expect("source has no filename"))
553+
.append(bytes!(".html")));
553554
let mut w = BufferedWriter::new(try!(File::create(&cur)));
554555

555556
let title = format!("{} -- source", cur.filename_display());

src/libstd/ascii.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use to_str::{IntoStr};
1414
use str;
1515
use str::Str;
16-
use str::StrSlice;
16+
use str::{StrAllocating, StrSlice};
1717
use str::OwnedStr;
1818
use container::Container;
1919
use cast;

src/libstd/num/i16.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
//! Operations and constants for signed 16-bits integers (`i16` type)
1212
1313
use from_str::FromStr;
14-
use iter::Iterator;
1514
use num::{ToStrRadix, FromStrRadix};
1615
use num::strconv;
1716
use option::Option;
18-
use slice::{ImmutableVector, OwnedVector};
17+
use slice::ImmutableVector;
1918
use str;
2019

2120
pub use core::i16::{BITS, BYTES, MIN, MAX};

src/libstd/num/i32.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
//! Operations and constants for signed 32-bits integers (`i32` type)
1212
1313
use from_str::FromStr;
14-
use iter::Iterator;
1514
use num::{ToStrRadix, FromStrRadix};
1615
use num::strconv;
1716
use option::Option;
18-
use slice::{ImmutableVector, OwnedVector};
17+
use slice::ImmutableVector;
1918
use str;
2019

2120
pub use core::i32::{BITS, BYTES, MIN, MAX};

src/libstd/num/i64.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
//! Operations and constants for signed 64-bits integers (`i64` type)
1212
1313
use from_str::FromStr;
14-
use iter::Iterator;
1514
use num::{ToStrRadix, FromStrRadix};
1615
use num::strconv;
1716
use option::Option;
18-
use slice::{ImmutableVector, OwnedVector};
17+
use slice::ImmutableVector;
1918
use str;
2019

2120
pub use core::i64::{BITS, BYTES, MIN, MAX};

src/libstd/num/i8.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
//! Operations and constants for signed 8-bits integers (`i8` type)
1212
1313
use from_str::FromStr;
14-
use iter::Iterator;
1514
use num::{ToStrRadix, FromStrRadix};
1615
use num::strconv;
1716
use option::Option;
18-
use slice::{ImmutableVector, OwnedVector};
17+
use slice::ImmutableVector;
1918
use str;
2019

2120
pub use core::i8::{BITS, BYTES, MIN, MAX};

src/libstd/num/int.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
//! Operations and constants for architecture-sized signed integers (`int` type)
1212
1313
use from_str::FromStr;
14-
use iter::Iterator;
1514
use num::{ToStrRadix, FromStrRadix};
1615
use num::strconv;
1716
use option::Option;
18-
use slice::{ImmutableVector, OwnedVector};
17+
use slice::ImmutableVector;
1918
use str;
2019

2120
pub use core::int::{BITS, BYTES, MIN, MAX};

src/libstd/num/int_macros.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ impl ToStrRadix for $T {
7777
/// Convert to a string in a given base.
7878
#[inline]
7979
fn to_str_radix(&self, radix: uint) -> ~str {
80+
use slice::Vector;
81+
use str::StrAllocating;
82+
8083
let mut buf = ::vec::Vec::new();
8184
strconv::int_to_str_bytes_common(*self, radix, strconv::SignNeg, |i| {
8285
buf.push(i);

src/libstd/num/strconv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use ops::{Add, Sub, Mul, Div, Rem, Neg};
2121
use option::{None, Option, Some};
2222
use slice::{CloneableVector, ImmutableVector, MutableVector};
2323
use std::cmp::{Ord, Eq};
24-
use str::{Str, StrSlice};
24+
use str::{StrAllocating, StrSlice};
2525
use strbuf::StrBuf;
2626
use vec::Vec;
2727

src/libstd/num/u16.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
//! Operations and constants for unsigned 16-bits integers (`u16` type)
1212
1313
use from_str::FromStr;
14-
use iter::Iterator;
1514
use num::{ToStrRadix, FromStrRadix};
1615
use num::strconv;
1716
use option::Option;
18-
use slice::{ImmutableVector, OwnedVector};
17+
use slice::ImmutableVector;
1918
use str;
2019

2120
pub use core::u16::{BITS, BYTES, MIN, MAX};

src/libstd/num/u32.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
//! Operations and constants for unsigned 32-bits integers (`u32` type)
1212
1313
use from_str::FromStr;
14-
use iter::Iterator;
1514
use num::{ToStrRadix, FromStrRadix};
1615
use num::strconv;
1716
use option::Option;
18-
use slice::{ImmutableVector, OwnedVector};
17+
use slice::ImmutableVector;
1918
use str;
2019

2120
pub use core::u32::{BITS, BYTES, MIN, MAX};

src/libstd/num/u64.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
//! Operations and constants for unsigned 64-bits integer (`u64` type)
1212
1313
use from_str::FromStr;
14-
use iter::Iterator;
1514
use num::{ToStrRadix, FromStrRadix};
1615
use num::strconv;
1716
use option::Option;
18-
use slice::{ImmutableVector, OwnedVector};
17+
use slice::ImmutableVector;
1918
use str;
2019

2120
pub use core::u64::{BITS, BYTES, MIN, MAX};

src/libstd/num/u8.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
//! Operations and constants for unsigned 8-bits integers (`u8` type)
1212
1313
use from_str::FromStr;
14-
use iter::Iterator;
1514
use num::{ToStrRadix, FromStrRadix};
1615
use num::strconv;
1716
use option::Option;
18-
use slice::{ImmutableVector, OwnedVector};
17+
use slice::ImmutableVector;
1918
use str;
2019

2120
pub use core::u8::{BITS, BYTES, MIN, MAX};

src/libstd/num/uint.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
//! Operations and constants for architecture-sized unsigned integers (`uint` type)
1212
1313
use from_str::FromStr;
14-
use iter::Iterator;
1514
use num::{ToStrRadix, FromStrRadix};
1615
use num::strconv;
1716
use option::Option;
18-
use slice::{ImmutableVector, OwnedVector};
17+
use slice::ImmutableVector;
1918
use str;
2019

2120
pub use core::uint::{BITS, BYTES, MIN, MAX};

src/libstd/num/uint_macros.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ impl ToStrRadix for $T {
7878
/// Convert to a string in a given base.
7979
#[inline]
8080
fn to_str_radix(&self, radix: uint) -> ~str {
81+
use slice::Vector;
82+
use str::StrAllocating;
83+
8184
let mut buf = ::vec::Vec::new();
8285
strconv::int_to_str_bytes_common(*self, radix, strconv::SignNone, |i| {
8386
buf.push(i);

src/libstd/slice.rs

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -279,26 +279,6 @@ impl<T: Clone> Iterator<~[T]> for Permutations<T> {
279279
}
280280
}
281281

282-
#[cfg(not(test))]
283-
impl<'a,T:Clone, V: Vector<T>> Add<V, Vec<T>> for &'a [T] {
284-
#[inline]
285-
fn add(&self, rhs: &V) -> Vec<T> {
286-
let rhs = rhs.as_slice();
287-
let mut res = Vec::with_capacity(self.len() + rhs.len());
288-
res.push_all(*self);
289-
res.push_all(rhs);
290-
res
291-
}
292-
}
293-
294-
#[cfg(not(test))]
295-
impl<T:Clone, V: Vector<T>> Add<V, Vec<T>> for ~[T] {
296-
#[inline]
297-
fn add(&self, rhs: &V) -> Vec<T> {
298-
self.as_slice() + rhs.as_slice()
299-
}
300-
}
301-
302282
/// Extension methods for vector slices with cloneable elements
303283
pub trait CloneableVector<T> {
304284
/// Copy `self` into a new owned vector
@@ -313,6 +293,11 @@ impl<'a, T: Clone> CloneableVector<T> for &'a [T] {
313293
/// Returns a copy of `v`.
314294
#[inline]
315295
fn to_owned(&self) -> ~[T] {
296+
use RawVec = core::raw::Vec;
297+
use rt::global_heap::{malloc_raw, exchange_free};
298+
use num::{CheckedAdd, CheckedMul};
299+
use option::Expect;
300+
316301
let len = self.len();
317302
let data_size = len.checked_mul(&mem::size_of::<T>());
318303
let data_size = data_size.expect("overflow in to_owned()");
@@ -2142,15 +2127,6 @@ mod bench {
21422127
})
21432128
}
21442129

2145-
#[bench]
2146-
fn add(b: &mut Bencher) {
2147-
let xs: &[int] = [5, ..10];
2148-
let ys: &[int] = [5, ..10];
2149-
b.iter(|| {
2150-
xs + ys;
2151-
});
2152-
}
2153-
21542130
#[bench]
21552131
fn concat(b: &mut Bencher) {
21562132
let xss: Vec<Vec<uint>> = Vec::from_fn(100, |i| range(0, i).collect());

src/libstd/str.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,12 +667,11 @@ impl<'a> fmt::Show for MaybeOwned<'a> {
667667
/// Unsafe operations
668668
pub mod raw {
669669
use cast;
670-
use iter::Iterator;
671670
use libc;
672671
use ptr::RawPtr;
673672
use raw::Slice;
674-
use slice::ImmutableVector;
675-
use str::is_utf8;
673+
use slice::CloneableVector;
674+
use str::{is_utf8, StrAllocating};
676675

677676
pub use core::str::raw::{from_utf8, c_str_to_static_slice, slice_bytes};
678677
pub use core::str::raw::{slice_unchecked};
@@ -821,8 +820,10 @@ pub trait StrAllocating: Str {
821820
/// Copy a slice into a new owned str.
822821
#[inline]
823822
fn to_owned(&self) -> ~str {
823+
use slice::Vector;
824+
824825
unsafe {
825-
::cast::transmute(self.as_bytes().to_owned())
826+
::cast::transmute(self.as_slice().as_bytes().to_owned())
826827
}
827828
}
828829

0 commit comments

Comments
 (0)