Skip to content

Commit 1854256

Browse files
committed
std: rename .connect/.concat in VectorVector to avoid conflicting with StrVector.
This is caused by StrVector having a generic implementation for &[S] and so #5898 means that method resolution of ~[~[1]].concat() sees that both StrVector and VectorVector have methods that (superficially) match. They are now connect_vec and concat_vec, which means that they can actually be called.
1 parent 38e0574 commit 1854256

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/libstd/vec.rs

+18-16
Original file line numberDiff line numberDiff line change
@@ -1002,31 +1002,33 @@ pub fn retain<T>(v: &mut ~[T], f: &fn(t: &T) -> bool) {
10021002
}
10031003

10041004
/// Flattens a vector of vectors of T into a single vector of T.
1005-
pub fn concat<T:Copy>(v: &[~[T]]) -> ~[T] { v.concat() }
1005+
pub fn concat<T:Copy>(v: &[~[T]]) -> ~[T] { v.concat_vec() }
10061006

10071007
/// Concatenate a vector of vectors, placing a given separator between each
1008-
pub fn connect<T:Copy>(v: &[~[T]], sep: &T) -> ~[T] { v.connect(sep) }
1008+
pub fn connect<T:Copy>(v: &[~[T]], sep: &T) -> ~[T] { v.connect_vec(sep) }
10091009

10101010
/// Flattens a vector of vectors of T into a single vector of T.
1011-
pub fn concat_slices<T:Copy>(v: &[&[T]]) -> ~[T] { v.concat() }
1011+
pub fn concat_slices<T:Copy>(v: &[&[T]]) -> ~[T] { v.concat_vec() }
10121012

10131013
/// Concatenate a vector of vectors, placing a given separator between each
1014-
pub fn connect_slices<T:Copy>(v: &[&[T]], sep: &T) -> ~[T] { v.connect(sep) }
1014+
pub fn connect_slices<T:Copy>(v: &[&[T]], sep: &T) -> ~[T] { v.connect_vec(sep) }
10151015

10161016
#[allow(missing_doc)]
10171017
pub trait VectorVector<T> {
1018-
pub fn concat(&self) -> ~[T];
1019-
pub fn connect(&self, sep: &T) -> ~[T];
1018+
// FIXME #5898: calling these .concat and .connect conflicts with
1019+
// StrVector::con{cat,nect}, since they have generic contents.
1020+
pub fn concat_vec(&self) -> ~[T];
1021+
pub fn connect_vec(&self, sep: &T) -> ~[T];
10201022
}
10211023

10221024
impl<'self, T:Copy> VectorVector<T> for &'self [~[T]] {
10231025
/// Flattens a vector of slices of T into a single vector of T.
1024-
pub fn concat(&self) -> ~[T] {
1026+
pub fn concat_vec(&self) -> ~[T] {
10251027
self.flat_map(|&inner| inner)
10261028
}
10271029

10281030
/// Concatenate a vector of vectors, placing a given separator between each.
1029-
pub fn connect(&self, sep: &T) -> ~[T] {
1031+
pub fn connect_vec(&self, sep: &T) -> ~[T] {
10301032
let mut r = ~[];
10311033
let mut first = true;
10321034
for self.each |&inner| {
@@ -1039,12 +1041,12 @@ impl<'self, T:Copy> VectorVector<T> for &'self [~[T]] {
10391041

10401042
impl<'self, T:Copy> VectorVector<T> for &'self [&'self [T]] {
10411043
/// Flattens a vector of slices of T into a single vector of T.
1042-
pub fn concat(&self) -> ~[T] {
1044+
pub fn concat_vec(&self) -> ~[T] {
10431045
self.flat_map(|&inner| inner.to_owned())
10441046
}
10451047

10461048
/// Concatenate a vector of slices, placing a given separator between each.
1047-
pub fn connect(&self, sep: &T) -> ~[T] {
1049+
pub fn connect_vec(&self, sep: &T) -> ~[T] {
10481050
let mut r = ~[];
10491051
let mut first = true;
10501052
for self.each |&inner| {
@@ -3704,25 +3706,25 @@ mod tests {
37043706
#[test]
37053707
fn test_concat() {
37063708
assert_eq!(concat([~[1], ~[2,3]]), ~[1, 2, 3]);
3707-
assert_eq!([~[1], ~[2,3]].concat(), ~[1, 2, 3]);
3709+
assert_eq!([~[1], ~[2,3]].concat_vec(), ~[1, 2, 3]);
37083710

37093711
assert_eq!(concat_slices([&[1], &[2,3]]), ~[1, 2, 3]);
3710-
assert_eq!([&[1], &[2,3]].concat(), ~[1, 2, 3]);
3712+
assert_eq!([&[1], &[2,3]].concat_vec(), ~[1, 2, 3]);
37113713
}
37123714

37133715
#[test]
37143716
fn test_connect() {
37153717
assert_eq!(connect([], &0), ~[]);
37163718
assert_eq!(connect([~[1], ~[2, 3]], &0), ~[1, 0, 2, 3]);
37173719
assert_eq!(connect([~[1], ~[2], ~[3]], &0), ~[1, 0, 2, 0, 3]);
3718-
assert_eq!([~[1], ~[2, 3]].connect(&0), ~[1, 0, 2, 3]);
3719-
assert_eq!([~[1], ~[2], ~[3]].connect(&0), ~[1, 0, 2, 0, 3]);
3720+
assert_eq!([~[1], ~[2, 3]].connect_vec(&0), ~[1, 0, 2, 3]);
3721+
assert_eq!([~[1], ~[2], ~[3]].connect_vec(&0), ~[1, 0, 2, 0, 3]);
37203722

37213723
assert_eq!(connect_slices([], &0), ~[]);
37223724
assert_eq!(connect_slices([&[1], &[2, 3]], &0), ~[1, 0, 2, 3]);
37233725
assert_eq!(connect_slices([&[1], &[2], &[3]], &0), ~[1, 0, 2, 0, 3]);
3724-
assert_eq!([&[1], &[2, 3]].connect(&0), ~[1, 0, 2, 3]);
3725-
assert_eq!([&[1], &[2], &[3]].connect(&0), ~[1, 0, 2, 0, 3]);
3726+
assert_eq!([&[1], &[2, 3]].connect_vec(&0), ~[1, 0, 2, 3]);
3727+
assert_eq!([&[1], &[2], &[3]].connect_vec(&0), ~[1, 0, 2, 0, 3]);
37263728
}
37273729

37283730
#[test]

0 commit comments

Comments
 (0)