]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/new_without_default.rs
Auto merge of #4478 - tsurai:master, r=flip1995
[rust.git] / tests / ui / new_without_default.rs
index a5673b622ba19894edaf36122adf3972a1aeae95..dbc7d597b2c1fc8cdf0c557db5b0836b5f1a813d 100644 (file)
@@ -1,43 +1,43 @@
-#![feature(plugin, const_fn)]
-#![plugin(clippy)]
-
+#![feature(const_fn)]
 #![allow(dead_code)]
-#![deny(new_without_default, new_without_default_derive)]
+#![warn(clippy::new_without_default)]
 
 pub struct Foo;
 
-
-
-
 impl Foo {
-    pub fn new() -> Foo { Foo }
-
+    pub fn new() -> Foo {
+        Foo
+    }
 }
 
 pub struct Bar;
 
-
-
-
 impl Bar {
-    pub fn new() -> Self { Bar }
-
+    pub fn new() -> Self {
+        Bar
+    }
 }
 
 pub struct Ok;
 
 impl Ok {
-    pub fn new() -> Self { Ok }
+    pub fn new() -> Self {
+        Ok
+    }
 }
 
 impl Default for Ok {
-    fn default() -> Self { Ok }
+    fn default() -> Self {
+        Ok
+    }
 }
 
 pub struct Params;
 
 impl Params {
-    pub fn new(_: u32) -> Self { Params }
+    pub fn new(_: u32) -> Self {
+        Params
+    }
 }
 
 pub struct GenericsOk<T> {
@@ -45,11 +45,15 @@ pub struct GenericsOk<T> {
 }
 
 impl<U> Default for GenericsOk<U> {
-    fn default() -> Self { unimplemented!(); }
+    fn default() -> Self {
+        unimplemented!();
+    }
 }
 
 impl<'c, V> GenericsOk<V> {
-    pub fn new() -> GenericsOk<V> { unimplemented!() }
+    pub fn new() -> GenericsOk<V> {
+        unimplemented!()
+    }
 }
 
 pub struct LtOk<'a> {
@@ -57,11 +61,15 @@ pub struct LtOk<'a> {
 }
 
 impl<'b> Default for LtOk<'b> {
-    fn default() -> Self { unimplemented!(); }
+    fn default() -> Self {
+        unimplemented!();
+    }
 }
 
 impl<'c> LtOk<'c> {
-    pub fn new() -> LtOk<'c> { unimplemented!() }
+    pub fn new() -> LtOk<'c> {
+        unimplemented!()
+    }
 }
 
 pub struct LtKo<'a> {
@@ -69,26 +77,75 @@ pub struct LtKo<'a> {
 }
 
 impl<'c> LtKo<'c> {
-    pub fn new() -> LtKo<'c> { unimplemented!() }
+    pub fn new() -> LtKo<'c> {
+        unimplemented!()
+    }
+    // FIXME: that suggestion is missing lifetimes
+}
+
+struct Private;
+
+impl Private {
+    fn new() -> Private {
+        unimplemented!()
+    } // We don't lint private items
+}
 
+struct Const;
 
+impl Const {
+    pub const fn new() -> Const {
+        Const
+    } // const fns can't be implemented via Default
+}
 
+pub struct IgnoreGenericNew;
 
+impl IgnoreGenericNew {
+    pub fn new<T>() -> Self {
+        IgnoreGenericNew
+    } // the derived Default does not make sense here as the result depends on T
+}
 
+pub trait TraitWithNew: Sized {
+    fn new() -> Self {
+        panic!()
+    }
+}
 
+pub struct IgnoreUnsafeNew;
 
-    // FIXME: that suggestion is missing lifetimes
+impl IgnoreUnsafeNew {
+    pub unsafe fn new() -> Self {
+        IgnoreUnsafeNew
+    }
 }
 
-struct Private;
+#[derive(Default)]
+pub struct OptionRefWrapper<'a, T>(Option<&'a T>);
 
-impl Private {
-    fn new() -> Private { unimplemented!() } // We don't lint private items
+impl<'a, T> OptionRefWrapper<'a, T> {
+    pub fn new() -> Self {
+        OptionRefWrapper(None)
+    }
 }
 
-struct Const;
+pub struct Allow(Foo);
 
-impl Const {
-    pub const fn new() -> Const { Const } // const fns can't be implemented via Default
+impl Allow {
+    #[allow(clippy::new_without_default)]
+    pub fn new() -> Self {
+        unimplemented!()
+    }
 }
+
+pub struct AllowDerive;
+
+impl AllowDerive {
+    #[allow(clippy::new_without_default)]
+    pub fn new() -> Self {
+        unimplemented!()
+    }
+}
+
 fn main() {}