]> git.lizzy.rs Git - rust.git/blob - tests/ui/string_extend.rs
Merge branch 'master' into rustfmt_tests
[rust.git] / tests / ui / string_extend.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
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.
9
10 #[derive(Copy, Clone)]
11 struct HasChars;
12
13 impl HasChars {
14     fn chars(self) -> std::str::Chars<'static> {
15         "HasChars".chars()
16     }
17 }
18
19 fn main() {
20     let abc = "abc";
21     let def = String::from("def");
22     let mut s = String::new();
23
24     s.push_str(abc);
25     s.extend(abc.chars());
26
27     s.push_str("abc");
28     s.extend("abc".chars());
29
30     s.push_str(&def);
31     s.extend(def.chars());
32
33     s.extend(abc.chars().skip(1));
34     s.extend("abc".chars().skip(1));
35     s.extend(['a', 'b', 'c'].iter());
36
37     let f = HasChars;
38     s.extend(f.chars());
39 }