]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/manual_str_repeat.fixed
Rollup merge of #103178 - ferrocene:pa-coverage-reports-tests, r=Mark-Simulacrum
[rust.git] / src / tools / clippy / tests / ui / manual_str_repeat.fixed
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;
8
9 fn main() {
10     let _: String = "test".repeat(10);
11     let _: String = "x".repeat(10);
12     let _: String = "'".repeat(10);
13     let _: String = "\"".repeat(10);
14
15     let x = "test";
16     let count = 10;
17     let _ = x.repeat(count + 2);
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 = (*x).repeat(count);
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 = x.repeat(count);
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 = Cow::Borrowed("test").repeat(count);
48
49     let x = "x".to_owned();
50     let _: String = x.repeat(count);
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 = "test".repeat(10);
66 }