Skip to content

Commit aa760a8

Browse files
committed
deprecate Vec::get
1 parent b35d1a8 commit aa760a8

File tree

25 files changed

+91
-88
lines changed

25 files changed

+91
-88
lines changed

src/compiletest/compiletest.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ pub fn parse_config(args: Vec<String> ) -> Config {
8989
optflag("h", "help", "show this message"));
9090

9191
assert!(!args.is_empty());
92-
let argv0 = (*args.get(0)).clone();
92+
let argv0 = args[0].clone();
9393
let args_ = args.tail();
94-
if args.get(1).as_slice() == "-h" || args.get(1).as_slice() == "--help" {
94+
if args[1].as_slice() == "-h" || args[1].as_slice() == "--help" {
9595
let message = format!("Usage: {} [OPTIONS] [TESTNAME...]", argv0);
9696
println!("{}", getopts::usage(message.as_slice(), groups.as_slice()));
9797
println!("");
@@ -116,7 +116,7 @@ pub fn parse_config(args: Vec<String> ) -> Config {
116116
}
117117

118118
let filter = if !matches.free.is_empty() {
119-
let s = matches.free.get(0).as_slice();
119+
let s = matches.free[0].as_slice();
120120
match regex::Regex::new(s) {
121121
Ok(re) => Some(re),
122122
Err(e) => {

src/compiletest/runtest.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn run_pretty_test(config: &Config, props: &TestProps, testfile: &Path) {
167167
let proc_res = print_source(config,
168168
props,
169169
testfile,
170-
(*srcs.get(round)).to_string(),
170+
srcs[round].to_string(),
171171
"normal");
172172

173173
if !proc_res.status.success() {
@@ -187,9 +187,9 @@ fn run_pretty_test(config: &Config, props: &TestProps, testfile: &Path) {
187187
let s = File::open(&filepath).read_to_end().unwrap();
188188
String::from_utf8(s).unwrap()
189189
}
190-
None => { (*srcs.get(srcs.len() - 2u)).clone() }
190+
None => { srcs[srcs.len() - 2u].clone() }
191191
};
192-
let mut actual = (*srcs.get(srcs.len() - 1u)).clone();
192+
let mut actual = srcs[srcs.len() - 1u].clone();
193193

194194
if props.pp_exact.is_some() {
195195
// Now we have to care about line endings
@@ -209,7 +209,7 @@ fn run_pretty_test(config: &Config, props: &TestProps, testfile: &Path) {
209209
if props.no_pretty_expanded { return }
210210

211211
// additionally, run `--pretty expanded` and try to build it.
212-
let proc_res = print_source(config, props, testfile, (*srcs.get(round)).clone(), "expanded");
212+
let proc_res = print_source(config, props, testfile, srcs[round].clone(), "expanded");
213213
if !proc_res.status.success() {
214214
fatal_proc_rec("pretty-printing (expanded) failed", &proc_res);
215215
}
@@ -702,7 +702,7 @@ fn check_debugger_output(debugger_run_result: &ProcRes, check_lines: &[String])
702702
let mut rest = line.trim();
703703
let mut first = true;
704704
let mut failed = false;
705-
for frag in check_fragments.get(i).iter() {
705+
for frag in check_fragments[i].iter() {
706706
let found = if first {
707707
if rest.starts_with(frag.as_slice()) {
708708
Some(0)
@@ -752,7 +752,7 @@ fn check_error_patterns(props: &TestProps,
752752
}
753753

754754
let mut next_err_idx = 0u;
755-
let mut next_err_pat = props.error_patterns.get(next_err_idx);
755+
let mut next_err_pat = &props.error_patterns[next_err_idx];
756756
let mut done = false;
757757
let output_to_check = if props.check_stdout {
758758
format!("{}{}", proc_res.stdout, proc_res.stderr)
@@ -761,14 +761,14 @@ fn check_error_patterns(props: &TestProps,
761761
};
762762
for line in output_to_check.as_slice().lines() {
763763
if line.contains(next_err_pat.as_slice()) {
764-
debug!("found error pattern {}", *next_err_pat);
764+
debug!("found error pattern {}", next_err_pat);
765765
next_err_idx += 1u;
766766
if next_err_idx == props.error_patterns.len() {
767767
debug!("found all error patterns");
768768
done = true;
769769
break;
770770
}
771-
next_err_pat = props.error_patterns.get(next_err_idx);
771+
next_err_pat = &props.error_patterns[next_err_idx];
772772
}
773773
}
774774
if done { return; }
@@ -847,13 +847,13 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError> ,
847847
for line in proc_res.stderr.as_slice().lines() {
848848
let mut was_expected = false;
849849
for (i, ee) in expected_errors.iter().enumerate() {
850-
if !*found_flags.get(i) {
850+
if !found_flags[i] {
851851
debug!("prefix={} ee.kind={} ee.msg={} line={}",
852-
prefixes.get(i).as_slice(),
852+
prefixes[i].as_slice(),
853853
ee.kind,
854854
ee.msg,
855855
line);
856-
if prefix_matches(line, prefixes.get(i).as_slice()) &&
856+
if prefix_matches(line, prefixes[i].as_slice()) &&
857857
line.contains(ee.kind.as_slice()) &&
858858
line.contains(ee.msg.as_slice()) {
859859
*found_flags.get_mut(i) = true;
@@ -877,7 +877,7 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError> ,
877877

878878
for (i, &flag) in found_flags.iter().enumerate() {
879879
if !flag {
880-
let ee = expected_errors.get(i);
880+
let ee = &expected_errors[i];
881881
fatal_proc_rec(format!("expected {} on line {} not found: {}",
882882
ee.kind, ee.line, ee.msg).as_slice(),
883883
proc_res);

src/doc/intro.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ fn main() {
205205
206206
spawn(proc() {
207207
let numbers = rx.recv();
208-
println!("{}", *numbers.get(0));
208+
println!("{}", numbers[0]);
209209
})
210210
}
211211
```
@@ -244,19 +244,19 @@ fn main() {
244244
245245
spawn(proc() {
246246
let numbers = rx.recv();
247-
println!("{}", numbers.get(0));
247+
println!("{}", numbers[0]);
248248
});
249249
250250
// Try to print a number from the original task
251-
println!("{}", *numbers.get(0));
251+
println!("{}", numbers[0]);
252252
}
253253
```
254254

255255
The compiler will produce an error indicating that the value is no longer in scope:
256256

257257
```text
258258
concurrency.rs:12:20: 12:27 error: use of moved value: 'numbers'
259-
concurrency.rs:12 println!("{}", numbers.get(0));
259+
concurrency.rs:12 println!("{}", numbers[0]);
260260
^~~~~~~
261261
```
262262

@@ -276,7 +276,7 @@ fn main() {
276276
277277
spawn(proc() {
278278
let numbers = rx.recv();
279-
println!("{:d}", *numbers.get(num as uint));
279+
println!("{:d}", numbers[num as uint]);
280280
})
281281
}
282282
}
@@ -309,7 +309,7 @@ fn main() {
309309
310310
spawn(proc() {
311311
let numbers = rx.recv();
312-
println!("{:d}", *numbers.get(num as uint));
312+
println!("{:d}", (*numbers)[num as uint]);
313313
})
314314
}
315315
}
@@ -364,7 +364,7 @@ fn main() {
364364
// See: https://github.com/rust-lang/rust/issues/6515
365365
*numbers.get_mut(num as uint) = *numbers.get_mut(num as uint) + 1;
366366
367-
println!("{}", *numbers.get(num as uint));
367+
println!("{}", (*numbers)[num as uint]);
368368
369369
// When `numbers` goes out of scope the lock is dropped
370370
})

src/doc/tutorial.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2427,7 +2427,7 @@ as in this version of `print_all` that copies elements.
24272427
fn print_all<T: Printable + Clone>(printable_things: Vec<T>) {
24282428
let mut i = 0;
24292429
while i < printable_things.len() {
2430-
let copy_of_thing = printable_things.get(i).clone();
2430+
let copy_of_thing = printable_things[i].clone();
24312431
copy_of_thing.print();
24322432
i += 1;
24332433
}

src/libcollections/vec.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub static PTR_MARKER: u8 = 0;
4242
/// vec.push(2i);
4343
///
4444
/// assert_eq!(vec.len(), 2);
45-
/// assert_eq!(vec.get(0), &1);
45+
/// assert_eq!(vec[0], 1);
4646
///
4747
/// assert_eq!(vec.pop(), Some(2));
4848
/// assert_eq!(vec.len(), 1);
@@ -746,9 +746,12 @@ impl<T> Vec<T> {
746746
/// # Example
747747
///
748748
/// ```rust
749+
/// #![allow(deprecated)]
750+
///
749751
/// let vec = vec!(1i, 2, 3);
750752
/// assert!(vec.get(1) == &2);
751753
/// ```
754+
#[deprecated="prefer using indexing, e.g., vec[0]"]
752755
#[inline]
753756
pub fn get<'a>(&'a self, index: uint) -> &'a T {
754757
&self.as_slice()[index]

src/libdebug/repr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
466466
_offset: uint,
467467
inner: *const TyDesc)
468468
-> bool {
469-
match *self.var_stk.get(self.var_stk.len() - 1) {
469+
match self.var_stk[self.var_stk.len() - 1] {
470470
Matched => {
471471
if i != 0 {
472472
try!(self, self.writer.write(", ".as_bytes()));
@@ -484,7 +484,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
484484
_disr_val: Disr,
485485
n_fields: uint,
486486
_name: &str) -> bool {
487-
match *self.var_stk.get(self.var_stk.len() - 1) {
487+
match self.var_stk[self.var_stk.len() - 1] {
488488
Matched => {
489489
if n_fields > 0 {
490490
try!(self, self.writer.write([')' as u8]));

src/libgetopts/lib.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
//! fn main() {
5252
//! let args: Vec<String> = os::args();
5353
//!
54-
//! let program = args.get(0).clone();
54+
//! let program = args[0].clone();
5555
//!
5656
//! let opts = [
5757
//! optopt("o", "", "set output file name", "NAME"),
@@ -67,7 +67,7 @@
6767
//! }
6868
//! let output = matches.opt_str("o");
6969
//! let input = if !matches.free.is_empty() {
70-
//! (*matches.free.get(0)).clone()
70+
//! matches.free[0].clone()
7171
//! } else {
7272
//! print_usage(program.as_slice(), opts);
7373
//! return;
@@ -275,7 +275,7 @@ impl OptGroup {
275275
impl Matches {
276276
fn opt_vals(&self, nm: &str) -> Vec<Optval> {
277277
match find_opt(self.opts.as_slice(), Name::from_str(nm)) {
278-
Some(id) => (*self.vals.get(id)).clone(),
278+
Some(id) => self.vals[id].clone(),
279279
None => fail!("No option '{}' defined", nm)
280280
}
281281
}
@@ -285,7 +285,7 @@ impl Matches {
285285
if vals.is_empty() {
286286
None
287287
} else {
288-
Some((*vals.get(0)).clone())
288+
Some(vals[0].clone())
289289
}
290290
}
291291

@@ -304,7 +304,7 @@ impl Matches {
304304
for nm in names.iter() {
305305
match find_opt(self.opts.as_slice(),
306306
Name::from_str(nm.as_slice())) {
307-
Some(id) if !self.vals.get(id).is_empty() => return true,
307+
Some(id) if !self.vals[id].is_empty() => return true,
308308
_ => (),
309309
};
310310
}
@@ -344,8 +344,8 @@ impl Matches {
344344
if vals.is_empty() {
345345
return None::<String>;
346346
}
347-
match vals.get(0) {
348-
&Val(ref s) => Some((*s).clone()),
347+
match vals[0] {
348+
Val(ref s) => Some((*s).clone()),
349349
_ => None
350350
}
351351
}
@@ -361,8 +361,8 @@ impl Matches {
361361
if vals.is_empty() {
362362
return None;
363363
}
364-
match vals.get(0) {
365-
&Val(ref s) => Some((*s).clone()),
364+
match vals[0] {
365+
Val(ref s) => Some((*s).clone()),
366366
_ => Some(def.to_string())
367367
}
368368
}
@@ -560,8 +560,8 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
560560
names = vec!(Long(tail.to_string()));
561561
} else {
562562
names =
563-
vec!(Long((*tail_eq.get(0)).to_string()));
564-
i_arg = Some((*tail_eq.get(1)).to_string());
563+
vec!(Long(tail_eq[0].to_string()));
564+
i_arg = Some(tail_eq[1].to_string());
565565
}
566566
} else {
567567
let mut j = 1;
@@ -583,7 +583,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
583583
None => {
584584
let arg_follows =
585585
last_valid_opt_id.is_some() &&
586-
match opts.get(last_valid_opt_id.unwrap())
586+
match opts[last_valid_opt_id.unwrap()]
587587
.hasarg {
588588

589589
Yes | Maybe => true,
@@ -609,7 +609,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
609609
Some(id) => id,
610610
None => return Err(UnrecognizedOption(nm.to_string()))
611611
};
612-
match opts.get(optid).hasarg {
612+
match opts[optid].hasarg {
613613
No => {
614614
if !i_arg.is_none() {
615615
return Err(UnexpectedArgument(nm.to_string()));
@@ -646,16 +646,16 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
646646
}
647647
i = 0u;
648648
while i < n_opts {
649-
let n = vals.get(i).len();
650-
let occ = opts.get(i).occur;
649+
let n = vals[i].len();
650+
let occ = opts[i].occur;
651651
if occ == Req {
652652
if n == 0 {
653-
return Err(OptionMissing(opts.get(i).name.to_string()));
653+
return Err(OptionMissing(opts[i].name.to_string()));
654654
}
655655
}
656656
if occ != Multi {
657657
if n > 1 {
658-
return Err(OptionDuplicated(opts.get(i).name.to_string()));
658+
return Err(OptionDuplicated(opts[i].name.to_string()));
659659
}
660660
}
661661
i += 1;

src/libglob/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl Iterator<Path> for Paths {
154154
if self.require_dir && !path.is_dir() { continue; }
155155
return Some(path);
156156
}
157-
let ref pattern = *self.dir_patterns.get(idx);
157+
let ref pattern = self.dir_patterns[idx];
158158

159159
if pattern.matches_with(match path.filename_str() {
160160
// this ugly match needs to go here to avoid a borrowck error
@@ -250,21 +250,21 @@ impl Pattern {
250250
let mut i = 0;
251251

252252
while i < chars.len() {
253-
match *chars.get(i) {
253+
match chars[i] {
254254
'?' => {
255255
tokens.push(AnyChar);
256256
i += 1;
257257
}
258258
'*' => {
259259
// *, **, ***, ****, ... are all equivalent
260-
while i < chars.len() && *chars.get(i) == '*' {
260+
while i < chars.len() && chars[i] == '*' {
261261
i += 1;
262262
}
263263
tokens.push(AnySequence);
264264
}
265265
'[' => {
266266

267-
if i <= chars.len() - 4 && *chars.get(i + 1) == '!' {
267+
if i <= chars.len() - 4 && chars[i + 1] == '!' {
268268
match chars.slice_from(i + 3).position_elem(&']') {
269269
None => (),
270270
Some(j) => {
@@ -276,7 +276,7 @@ impl Pattern {
276276
}
277277
}
278278
}
279-
else if i <= chars.len() - 3 && *chars.get(i + 1) != '!' {
279+
else if i <= chars.len() - 3 && chars[i + 1] != '!' {
280280
match chars.slice_from(i + 2).position_elem(&']') {
281281
None => (),
282282
Some(j) => {
@@ -507,7 +507,7 @@ fn fill_todo(todo: &mut Vec<(Path, uint)>, patterns: &[Pattern], idx: uint, path
507507
// the current and parent directory respectively requires that
508508
// the pattern has a leading dot, even if the `MatchOptions` field
509509
// `require_literal_leading_dot` is not set.
510-
if pattern.tokens.len() > 0 && pattern.tokens.get(0) == &Char('.') {
510+
if pattern.tokens.len() > 0 && pattern.tokens[0] == Char('.') {
511511
for &special in [".", ".."].iter() {
512512
if pattern.matches_with(special, options) {
513513
add(todo, path.join(special));

0 commit comments

Comments
 (0)