]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/new_without_default.rs
Ignore associated items in trait *implementations* when considering type complexity
[rust.git] / tests / ui / new_without_default.rs
index 781ea7bb152836eda343116409d8c84406266540..4b2e7444dcf63251932ba94ee3c4ace4e59be4dc 100644 (file)
@@ -1,4 +1,3 @@
-#![feature(const_fn)]
 #![allow(dead_code, clippy::missing_safety_doc)]
 #![warn(clippy::new_without_default)]
 
@@ -148,4 +147,42 @@ pub fn new() -> Self {
     }
 }
 
+pub struct NewNotEqualToDerive {
+    foo: i32,
+}
+
+impl NewNotEqualToDerive {
+    // This `new` implementation is not equal to a derived `Default`, so do not suggest deriving.
+    pub fn new() -> Self {
+        NewNotEqualToDerive { foo: 1 }
+    }
+}
+
+// see #6933
+pub struct FooGenerics<T>(std::marker::PhantomData<T>);
+impl<T> FooGenerics<T> {
+    pub fn new() -> Self {
+        Self(Default::default())
+    }
+}
+
+pub struct BarGenerics<T>(std::marker::PhantomData<T>);
+impl<T: Copy> BarGenerics<T> {
+    pub fn new() -> Self {
+        Self(Default::default())
+    }
+}
+
+pub mod issue7220 {
+    pub struct Foo<T> {
+        _bar: *mut T,
+    }
+
+    impl<T> Foo<T> {
+        pub fn new() -> Self {
+            todo!()
+        }
+    }
+}
+
 fn main() {}