]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/manual_str_repeat.rs
Fix type checks for `manual_str_repeat`
[rust.git] / tests / ui / manual_str_repeat.rs
index 1acd66da27591da3c1d69b157f9386e63d12ac88..0d69c989b2ed84a0b616f773aa963e9ca30c9d14 100644 (file)
@@ -1,8 +1,10 @@
 // run-rustfix
 
+#![feature(custom_inner_attributes)]
 #![warn(clippy::manual_str_repeat)]
 
-use std::iter::repeat;
+use std::borrow::Cow;
+use std::iter::{repeat, FromIterator};
 
 fn main() {
     let _: String = std::iter::repeat("test").take(10).collect();
@@ -17,7 +19,7 @@ fn main() {
     macro_rules! m {
         ($e:expr) => {{ $e }};
     }
-
+    // FIXME: macro args are fine
     let _: String = repeat(m!("test")).take(m!(count)).collect();
 
     let x = &x;
@@ -28,4 +30,37 @@ macro_rules! repeat_m {
     }
     // Don't lint, repeat is from a macro.
     let _: String = repeat_m!("test").take(count).collect();
+
+    let x: Box<str> = Box::from("test");
+    let _: String = repeat(x).take(count).collect();
+
+    #[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 = repeat(Cow::Borrowed("test")).take(count).collect();
+
+    let x = "x".to_owned();
+    let _: String = repeat(x).take(count).collect();
+
+    let x = 'x';
+    // Don't lint, not char literal
+    let _: String = repeat(x).take(count).collect();
+}
+
+fn _msrv_1_15() {
+    #![clippy::msrv = "1.15"]
+    // `str::repeat` was stabilized in 1.16. Do not lint this
+    let _: String = std::iter::repeat("test").take(10).collect();
+}
+
+fn _msrv_1_16() {
+    #![clippy::msrv = "1.16"]
+    let _: String = std::iter::repeat("test").take(10).collect();
 }