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();
20 // Extend with constant expression
22 let mut vec1 = Vec::with_capacity(len);
23 vec1.extend(repeat(0).take(len));
25 // Extend with len expression
26 let mut vec2 = Vec::with_capacity(len - 10);
27 vec2.extend(repeat(0).take(len - 10));
29 // Extend with mismatching expression should not be warned
30 let mut vec3 = Vec::with_capacity(24322);
31 vec3.extend(repeat(0).take(2));
34 fn mixed_extend_resize_vector() {
36 let mut mismatching_len = Vec::with_capacity(30);
37 mismatching_len.extend(repeat(0).take(40));
39 // Slow initialization
40 let mut resized_vec = Vec::with_capacity(30);
41 resized_vec.resize(30, 0);
43 let mut extend_vec = Vec::with_capacity(30);
44 extend_vec.extend(repeat(0).take(30));
48 // Resize with constant expression
50 let mut vec1 = Vec::with_capacity(len);
53 // Resize mismatch len
54 let mut vec2 = Vec::with_capacity(200);
57 // Resize with len expression
58 let mut vec3 = Vec::with_capacity(len - 10);
59 vec3.resize(len - 10, 0);
61 // Reinitialization should be warned
62 vec1 = Vec::with_capacity(10);
67 let mut unsafe_vec: Vec<u8> = Vec::with_capacity(200);
70 unsafe_vec.set_len(200);
74 fn do_stuff(vec: &mut Vec<u8>) {
78 fn extend_vector_with_manipulations_between() {
80 let mut vec1:Vec<u8> = Vec::with_capacity(len);
82 vec1.extend(repeat(0).take(len));