Skip to content

Commit 8a308b1

Browse files
committed
auto merge of #15725 : aochagavia/rust/vec, r=alexcrichton
* Deprecated `to_owned` in favor of `to_vec` * Deprecated `into_owned` in favor of `into_vec` [breaking-change]
2 parents cebed8a + 8107ef7 commit 8a308b1

File tree

16 files changed

+59
-46
lines changed

16 files changed

+59
-46
lines changed

src/libcollections/slice.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -277,21 +277,33 @@ impl<T: Clone> Iterator<Vec<T>> for Permutations<T> {
277277

278278
/// Extension methods for vector slices with cloneable elements
279279
pub trait CloneableVector<T> {
280-
/// Copy `self` into a new owned vector
281-
fn to_owned(&self) -> Vec<T>;
280+
/// Copy `self` into a new vector
281+
fn to_vec(&self) -> Vec<T>;
282+
283+
/// Deprecated. Use `to_vec`
284+
#[deprecated = "Replaced by `to_vec`"]
285+
fn to_owned(&self) -> Vec<T> {
286+
self.to_vec()
287+
}
282288

283289
/// Convert `self` into an owned vector, not making a copy if possible.
284-
fn into_owned(self) -> Vec<T>;
290+
fn into_vec(self) -> Vec<T>;
291+
292+
/// Deprecated. Use `into_vec`
293+
#[deprecated = "Replaced by `into_vec`"]
294+
fn into_owned(self) -> Vec<T> {
295+
self.into_vec()
296+
}
285297
}
286298

287299
/// Extension methods for vector slices
288300
impl<'a, T: Clone> CloneableVector<T> for &'a [T] {
289301
/// Returns a copy of `v`.
290302
#[inline]
291-
fn to_owned(&self) -> Vec<T> { Vec::from_slice(*self) }
303+
fn to_vec(&self) -> Vec<T> { Vec::from_slice(*self) }
292304

293305
#[inline(always)]
294-
fn into_owned(self) -> Vec<T> { self.to_owned() }
306+
fn into_vec(self) -> Vec<T> { self.to_vec() }
295307
}
296308

297309
/// Extension methods for vectors containing `Clone` elements.
@@ -325,7 +337,7 @@ impl<'a,T:Clone> ImmutableCloneableVector<T> for &'a [T] {
325337
fn permutations(self) -> Permutations<T> {
326338
Permutations{
327339
swaps: ElementSwaps::new(self.len()),
328-
v: self.to_owned(),
340+
v: self.to_vec(),
329341
}
330342
}
331343

@@ -888,7 +900,7 @@ mod tests {
888900
fn test_slice() {
889901
// Test fixed length vector.
890902
let vec_fixed = [1i, 2, 3, 4];
891-
let v_a = vec_fixed.slice(1u, vec_fixed.len()).to_owned();
903+
let v_a = vec_fixed.slice(1u, vec_fixed.len()).to_vec();
892904
assert_eq!(v_a.len(), 3u);
893905
let v_a = v_a.as_slice();
894906
assert_eq!(v_a[0], 2);
@@ -897,15 +909,15 @@ mod tests {
897909

898910
// Test on stack.
899911
let vec_stack = &[1i, 2, 3];
900-
let v_b = vec_stack.slice(1u, 3u).to_owned();
912+
let v_b = vec_stack.slice(1u, 3u).to_vec();
901913
assert_eq!(v_b.len(), 2u);
902914
let v_b = v_b.as_slice();
903915
assert_eq!(v_b[0], 2);
904916
assert_eq!(v_b[1], 3);
905917

906918
// Test `Box<[T]>`
907919
let vec_unique = vec![1i, 2, 3, 4, 5, 6];
908-
let v_d = vec_unique.slice(1u, 6u).to_owned();
920+
let v_d = vec_unique.slice(1u, 6u).to_vec();
909921
assert_eq!(v_d.len(), 5u);
910922
let v_d = v_d.as_slice();
911923
assert_eq!(v_d[0], 2);
@@ -1132,7 +1144,7 @@ mod tests {
11321144
let (min_size, max_opt) = it.size_hint();
11331145
assert_eq!(min_size, 1);
11341146
assert_eq!(max_opt.unwrap(), 1);
1135-
assert_eq!(it.next(), Some(v.as_slice().to_owned()));
1147+
assert_eq!(it.next(), Some(v.as_slice().to_vec()));
11361148
assert_eq!(it.next(), None);
11371149
}
11381150
{
@@ -1141,7 +1153,7 @@ mod tests {
11411153
let (min_size, max_opt) = it.size_hint();
11421154
assert_eq!(min_size, 1);
11431155
assert_eq!(max_opt.unwrap(), 1);
1144-
assert_eq!(it.next(), Some(v.as_slice().to_owned()));
1156+
assert_eq!(it.next(), Some(v.as_slice().to_vec()));
11451157
assert_eq!(it.next(), None);
11461158
}
11471159
{

src/libcollections/vec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,8 @@ impl<T> Collection for Vec<T> {
437437
}
438438

439439
impl<T: Clone> CloneableVector<T> for Vec<T> {
440-
fn to_owned(&self) -> Vec<T> { self.clone() }
441-
fn into_owned(self) -> Vec<T> { self }
440+
fn to_vec(&self) -> Vec<T> { self.clone() }
441+
fn into_vec(self) -> Vec<T> { self }
442442
}
443443

444444
// FIXME: #13996: need a way to mark the return value as `noalias`

src/libgraphviz/maybe_owned_vec.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,23 @@ impl<'a,T:fmt::Show> fmt::Show for MaybeOwnedVector<'a,T> {
124124

125125
impl<'a,T:Clone> CloneableVector<T> for MaybeOwnedVector<'a,T> {
126126
/// Returns a copy of `self`.
127-
fn to_owned(&self) -> Vec<T> {
128-
self.as_slice().to_owned()
127+
fn to_vec(&self) -> Vec<T> {
128+
self.as_slice().to_vec()
129129
}
130130

131131
/// Convert `self` into an owned slice, not making a copy if possible.
132-
fn into_owned(self) -> Vec<T> {
132+
fn into_vec(self) -> Vec<T> {
133133
match self {
134-
Growable(v) => v.as_slice().to_owned(),
135-
Borrowed(v) => v.to_owned(),
134+
Growable(v) => v.as_slice().to_vec(),
135+
Borrowed(v) => v.to_vec(),
136136
}
137137
}
138138
}
139139

140140
impl<'a, T: Clone> Clone for MaybeOwnedVector<'a, T> {
141141
fn clone(&self) -> MaybeOwnedVector<'a, T> {
142142
match *self {
143-
Growable(ref v) => Growable(v.to_owned()),
143+
Growable(ref v) => Growable(v.to_vec()),
144144
Borrowed(v) => Borrowed(v)
145145
}
146146
}

src/librustc/back/link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ fn link_args(cmd: &mut Command,
12541254
abi::OsMacos | abi::OsiOS => {
12551255
let morestack = lib_path.join("libmorestack.a");
12561256

1257-
let mut v = "-Wl,-force_load,".as_bytes().to_owned();
1257+
let mut v = b"-Wl,-force_load,".to_vec();
12581258
v.push_all(morestack.as_vec());
12591259
cmd.arg(v.as_slice());
12601260
}

src/librustc/driver/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub mod config;
3636

3737

3838
pub fn main_args(args: &[String]) -> int {
39-
let owned_args = args.to_owned();
39+
let owned_args = args.to_vec();
4040
monitor(proc() run_compiler(owned_args.as_slice()));
4141
0
4242
}

src/librustc/metadata/filesearch.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<'a> FileSearch<'a> {
4646
FileMatches => found = true,
4747
FileDoesntMatch => ()
4848
}
49-
visited_dirs.insert(path.as_vec().to_owned());
49+
visited_dirs.insert(path.as_vec().to_vec());
5050
}
5151

5252
debug!("filesearch: searching lib path");
@@ -59,18 +59,18 @@ impl<'a> FileSearch<'a> {
5959
}
6060
}
6161

62-
visited_dirs.insert(tlib_path.as_vec().to_owned());
62+
visited_dirs.insert(tlib_path.as_vec().to_vec());
6363
// Try RUST_PATH
6464
if !found {
6565
let rustpath = rust_path();
6666
for path in rustpath.iter() {
6767
let tlib_path = make_rustpkg_lib_path(
6868
self.sysroot, path, self.triple);
6969
debug!("is {} in visited_dirs? {:?}", tlib_path.display(),
70-
visited_dirs.contains_equiv(&tlib_path.as_vec().to_owned()));
70+
visited_dirs.contains_equiv(&tlib_path.as_vec().to_vec()));
7171

7272
if !visited_dirs.contains_equiv(&tlib_path.as_vec()) {
73-
visited_dirs.insert(tlib_path.as_vec().to_owned());
73+
visited_dirs.insert(tlib_path.as_vec().to_vec());
7474
// Don't keep searching the RUST_PATH if one match turns up --
7575
// if we did, we'd get a "multiple matching crates" error
7676
match f(&tlib_path) {

src/librustc/middle/dataflow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ impl<'a, O:DataFlowOperator> DataFlowContext<'a, O> {
369369
let slice = match e {
370370
Entry => on_entry,
371371
Exit => {
372-
let mut t = on_entry.to_owned();
372+
let mut t = on_entry.to_vec();
373373
self.apply_gen_kill_frozen(cfgidx, t.as_mut_slice());
374374
temp_bits = t;
375375
temp_bits.as_slice()
@@ -445,7 +445,7 @@ impl<'a, O:DataFlowOperator> DataFlowContext<'a, O> {
445445
cfg.graph.each_edge(|_edge_index, edge| {
446446
let flow_exit = edge.source();
447447
let (start, end) = self.compute_id_range(flow_exit);
448-
let mut orig_kills = self.kills.slice(start, end).to_owned();
448+
let mut orig_kills = self.kills.slice(start, end).to_vec();
449449

450450
let mut changed = false;
451451
for &node_id in edge.data.exiting_scopes.iter() {

src/librustc/middle/save/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,10 +1137,11 @@ impl<'l> Visitor<DxrVisitorEnv> for DxrVisitor<'l> {
11371137
}
11381138
},
11391139
ast::ViewItemExternCrate(ident, ref s, id) => {
1140-
let name = get_ident(ident).get().to_owned();
1140+
let name = get_ident(ident);
1141+
let name = name.get();
11411142
let s = match *s {
1142-
Some((ref s, _)) => s.get().to_owned(),
1143-
None => name.to_owned(),
1143+
Some((ref s, _)) => s.get().to_string(),
1144+
None => name.to_string(),
11441145
};
11451146
let sub_span = self.span.sub_span_after_keyword(i.span, keywords::Crate);
11461147
let cnum = match self.sess.cstore.find_extern_mod_stmt_cnum(id) {
@@ -1151,7 +1152,7 @@ impl<'l> Visitor<DxrVisitorEnv> for DxrVisitor<'l> {
11511152
sub_span,
11521153
id,
11531154
cnum,
1154-
name.as_slice(),
1155+
name,
11551156
s.as_slice(),
11561157
e.cur_scope);
11571158
},
@@ -1274,9 +1275,9 @@ impl<'l> Visitor<DxrVisitorEnv> for DxrVisitor<'l> {
12741275
// process collected paths
12751276
for &(id, ref p, ref immut, ref_kind) in self.collected_paths.iter() {
12761277
let value = if *immut {
1277-
self.span.snippet(p.span).into_owned()
1278+
self.span.snippet(p.span).into_string()
12781279
} else {
1279-
"<mutable>".to_owned()
1280+
"<mutable>".to_string()
12801281
};
12811282
let sub_span = self.span.span_for_first_ident(p.span);
12821283
let def_map = self.analysis.ty_cx.def_map.borrow();
@@ -1331,7 +1332,7 @@ impl<'l> Visitor<DxrVisitorEnv> for DxrVisitor<'l> {
13311332
let value = self.span.snippet(l.span);
13321333

13331334
for &(id, ref p, ref immut, _) in self.collected_paths.iter() {
1334-
let value = if *immut { value.to_owned() } else { "<mutable>".to_owned() };
1335+
let value = if *immut { value.to_string() } else { "<mutable>".to_string() };
13351336
let types = self.analysis.ty_cx.node_types.borrow();
13361337
let typ = ppaux::ty_to_string(&self.analysis.ty_cx, *types.get(&(id as uint)));
13371338
// Get the span only for the name of the variable (I hope the path

src/librustc/middle/save/recorder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl<'a> FmtStrs<'a> {
170170
String::from_str(v)
171171
}
172172
)));
173-
Some(strs.fold(String::new(), |s, ss| s.append(ss.as_slice()))).map(|s| s.into_owned())
173+
Some(strs.fold(String::new(), |s, ss| s.append(ss.as_slice())))
174174
}
175175

176176
pub fn record_without_span(&mut self,
@@ -503,7 +503,7 @@ impl<'a> FmtStrs<'a> {
503503
};
504504
let (dcn, dck) = match declid {
505505
Some(declid) => (s!(declid.node), s!(declid.krate)),
506-
None => ("".to_owned(), "".to_owned())
506+
None => ("".to_string(), "".to_string())
507507
};
508508
self.check_and_record(MethodCall,
509509
span,

src/librustc/middle/typeck/infer/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl Emitter for ExpectErrorEmitter {
9595
}
9696

9797
fn errors(msgs: &[&str]) -> (Box<Emitter+Send>, uint) {
98-
let v = Vec::from_fn(msgs.len(), |i| msgs[i].to_owned());
98+
let v = msgs.iter().map(|m| m.to_string()).collect();
9999
(box ExpectErrorEmitter { messages: v } as Box<Emitter+Send>, msgs.len())
100100
}
101101

@@ -114,7 +114,7 @@ fn test_env(_test_name: &str,
114114

115115
let sess = session::build_session_(options, None, span_diagnostic_handler);
116116
let krate_config = Vec::new();
117-
let input = driver::StrInput(source_string.to_owned());
117+
let input = driver::StrInput(source_string.to_string());
118118
let krate = driver::phase_1_parse_input(&sess, krate_config, &input);
119119
let (krate, ast_map) =
120120
driver::phase_2_configure_and_expand(&sess, krate, "test")

src/librustrt/c_str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,11 +778,11 @@ mod tests {
778778
c_ = Some(c.clone());
779779
c.clone();
780780
// force a copy, reading the memory
781-
c.as_bytes().to_owned();
781+
c.as_bytes().to_vec();
782782
});
783783
let c_ = c_.unwrap();
784784
// force a copy, reading the memory
785-
c_.as_bytes().to_owned();
785+
c_.as_bytes().to_vec();
786786
}
787787

788788
#[test]

src/libsyntax/ext/expand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ mod test {
15461546
fn run_renaming_test(t: &RenamingTest, test_idx: uint) {
15471547
let invalid_name = token::special_idents::invalid.name;
15481548
let (teststr, bound_connections, bound_ident_check) = match *t {
1549-
(ref str,ref conns, bic) => (str.to_owned(), conns.clone(), bic)
1549+
(ref str,ref conns, bic) => (str.to_string(), conns.clone(), bic)
15501550
};
15511551
let cr = expand_crate_str(teststr.to_string());
15521552
let bindings = crate_bindings(&cr);

src/test/bench/shootout-k-nucleotide-pipes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn sort_and_fmt(mm: &HashMap<Vec<u8> , uint>, total: uint) -> String {
7272

7373
// given a map, search for the frequency of a pattern
7474
fn find(mm: &HashMap<Vec<u8> , uint>, key: String) -> uint {
75-
let key = key.to_owned().into_ascii().as_slice().to_lower().into_string();
75+
let key = key.into_ascii().as_slice().to_lower().into_string();
7676
match mm.find_equiv(&key.as_bytes()) {
7777
option::None => { return 0u; }
7878
option::Some(&num) => { return num; }
@@ -179,7 +179,7 @@ fn main() {
179179
let mut proc_mode = false;
180180

181181
for line in rdr.lines() {
182-
let line = line.unwrap().as_slice().trim().to_owned();
182+
let line = line.unwrap().as_slice().trim().to_string();
183183

184184
if line.len() == 0u { continue; }
185185

src/test/bench/shootout-regex-dna.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fn main() {
109109
let (mut variant_strs, mut counts) = (vec!(), vec!());
110110
for variant in variants.move_iter() {
111111
let seq_arc_copy = seq_arc.clone();
112-
variant_strs.push(variant.to_string().to_owned());
112+
variant_strs.push(variant.to_string());
113113
counts.push(Future::spawn(proc() {
114114
count_matches(seq_arc_copy.as_slice(), &variant)
115115
}));

src/test/run-pass/issue-1696.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ use std::collections::HashMap;
1515

1616
pub fn main() {
1717
let mut m = HashMap::new();
18-
m.insert("foo".as_bytes().to_owned(), "bar".as_bytes().to_owned());
18+
m.insert(b"foo".to_vec(), b"bar".to_vec());
1919
println!("{:?}", m);
2020
}

src/test/run-pass/issue-4241.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ priv fn parse_list(len: uint, io: @io::Reader) -> Result {
5656
}
5757

5858
priv fn chop(s: String) -> String {
59-
s.slice(0, s.len() - 1).to_owned()
59+
s.slice(0, s.len() - 1).to_string()
6060
}
6161

6262
priv fn parse_bulk(io: @io::Reader) -> Result {

0 commit comments

Comments
 (0)