1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
10 use std::iter::repeat;
15 mixed_extend_resize_vector();
19 // Extend with constant expression
21 let mut vec1 = Vec::with_capacity(len);
22 vec1.extend(repeat(0).take(len));
24 // Extend with len expression
25 let mut vec2 = Vec::with_capacity(len - 10);
26 vec2.extend(repeat(0).take(len - 10));
28 // Extend with mismatching expression should not be warned
29 let mut vec3 = Vec::with_capacity(24322);
30 vec3.extend(repeat(0).take(2));
33 fn mixed_extend_resize_vector() {
35 let mut mismatching_len = Vec::with_capacity(30);
36 mismatching_len.extend(repeat(0).take(40));
38 // Slow initialization
39 let mut resized_vec = Vec::with_capacity(30);
40 resized_vec.resize(30, 0);
42 let mut extend_vec = Vec::with_capacity(30);
43 extend_vec.extend(repeat(0).take(30));
47 // Resize with constant expression
49 let mut vec1 = Vec::with_capacity(len);
52 // Resize mismatch len
53 let mut vec2 = Vec::with_capacity(200);
56 // Resize with len expression
57 let mut vec3 = Vec::with_capacity(len - 10);
58 vec3.resize(len - 10, 0);
60 // Reinitialization should be warned
61 vec1 = Vec::with_capacity(10);
65 fn do_stuff(vec: &mut Vec<u8>) {}
67 fn extend_vector_with_manipulations_between() {
69 let mut vec1: Vec<u8> = Vec::with_capacity(len);
71 vec1.extend(repeat(0).take(len));