]> git.lizzy.rs Git - rust.git/blob - tests/ui/manual_str_repeat.rs
Addition `manual_map` test for `unsafe` blocks
[rust.git] / tests / ui / manual_str_repeat.rs
1 // run-rustfix
2
3 #![feature(custom_inner_attributes)]
4 #![warn(clippy::manual_str_repeat)]
5
6 use std::borrow::Cow;
7 use std::iter::{repeat, FromIterator};
8
9 fn main() {
10     let _: String = std::iter::repeat("test").take(10).collect();
11     let _: String = std::iter::repeat('x').take(10).collect();
12     let _: String = std::iter::repeat('\'').take(10).collect();
13     let _: String = std::iter::repeat('"').take(10).collect();
14
15     let x = "test";
16     let count = 10;
17     let _ = repeat(x).take(count + 2).collect::<String>();
18
19     macro_rules! m {
20         ($e:expr) => {{ $e }};
21     }
22     // FIXME: macro args are fine
23     let _: String = repeat(m!("test")).take(m!(count)).collect();
24
25     let x = &x;
26     let _: String = repeat(*x).take(count).collect();
27
28     macro_rules! repeat_m {
29         ($e:expr) => {{ repeat($e) }};
30     }
31     // Don't lint, repeat is from a macro.
32     let _: String = repeat_m!("test").take(count).collect();
33
34     let x: Box<str> = Box::from("test");
35     let _: String = repeat(x).take(count).collect();
36
37     #[derive(Clone)]
38     struct S;
39     impl FromIterator<Box<S>> for String {
40         fn from_iter<T: IntoIterator<Item = Box<S>>>(_: T) -> Self {
41             Self::new()
42         }
43     }
44     // Don't lint, wrong box type
45     let _: String = repeat(Box::new(S)).take(count).collect();
46
47     let _: String = repeat(Cow::Borrowed("test")).take(count).collect();
48
49     let x = "x".to_owned();
50     let _: String = repeat(x).take(count).collect();
51
52     let x = 'x';
53     // Don't lint, not char literal
54     let _: String = repeat(x).take(count).collect();
55 }
56
57 fn _msrv_1_15() {
58     #![clippy::msrv = "1.15"]
59     // `str::repeat` was stabilized in 1.16. Do not lint this
60     let _: String = std::iter::repeat("test").take(10).collect();
61 }
62
63 fn _msrv_1_16() {
64     #![clippy::msrv = "1.16"]
65     let _: String = std::iter::repeat("test").take(10).collect();
66 }