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