2021-05-22 21:08:17 +00:00
|
|
|
// run-rustfix
|
|
|
|
|
|
|
|
#![warn(clippy::manual_str_repeat)]
|
|
|
|
|
2021-05-23 17:16:09 +00:00
|
|
|
use std::borrow::Cow;
|
2022-05-10 16:03:52 +00:00
|
|
|
use std::iter::repeat;
|
2021-05-22 21:08:17 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let _: String = "test".repeat(10);
|
|
|
|
let _: String = "x".repeat(10);
|
|
|
|
let _: String = "'".repeat(10);
|
|
|
|
let _: String = "\"".repeat(10);
|
|
|
|
|
|
|
|
let x = "test";
|
|
|
|
let count = 10;
|
|
|
|
let _ = x.repeat(count + 2);
|
|
|
|
|
|
|
|
macro_rules! m {
|
|
|
|
($e:expr) => {{ $e }};
|
|
|
|
}
|
2021-05-23 17:16:09 +00:00
|
|
|
// FIXME: macro args are fine
|
|
|
|
let _: String = repeat(m!("test")).take(m!(count)).collect();
|
2021-05-22 21:08:17 +00:00
|
|
|
|
|
|
|
let x = &x;
|
|
|
|
let _: String = (*x).repeat(count);
|
|
|
|
|
|
|
|
macro_rules! repeat_m {
|
|
|
|
($e:expr) => {{ repeat($e) }};
|
|
|
|
}
|
|
|
|
// Don't lint, repeat is from a macro.
|
|
|
|
let _: String = repeat_m!("test").take(count).collect();
|
2021-05-23 17:16:09 +00:00
|
|
|
|
|
|
|
let x: Box<str> = Box::from("test");
|
|
|
|
let _: String = x.repeat(count);
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
struct S;
|
|
|
|
impl FromIterator<Box<S>> for String {
|
|
|
|
fn from_iter<T: IntoIterator<Item = Box<S>>>(_: T) -> Self {
|
|
|
|
Self::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Don't lint, wrong box type
|
|
|
|
let _: String = repeat(Box::new(S)).take(count).collect();
|
|
|
|
|
|
|
|
let _: String = Cow::Borrowed("test").repeat(count);
|
|
|
|
|
|
|
|
let x = "x".to_owned();
|
|
|
|
let _: String = x.repeat(count);
|
|
|
|
|
|
|
|
let x = 'x';
|
|
|
|
// Don't lint, not char literal
|
|
|
|
let _: String = repeat(x).take(count).collect();
|
|
|
|
}
|
|
|
|
|
2022-11-19 12:50:02 +00:00
|
|
|
#[clippy::msrv = "1.15"]
|
2021-05-23 17:16:09 +00:00
|
|
|
fn _msrv_1_15() {
|
|
|
|
// `str::repeat` was stabilized in 1.16. Do not lint this
|
|
|
|
let _: String = std::iter::repeat("test").take(10).collect();
|
|
|
|
}
|
|
|
|
|
2022-11-19 12:50:02 +00:00
|
|
|
#[clippy::msrv = "1.16"]
|
2021-05-23 17:16:09 +00:00
|
|
|
fn _msrv_1_16() {
|
|
|
|
let _: String = "test".repeat(10);
|
2021-05-22 21:08:17 +00:00
|
|
|
}
|