]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/new_without_default.rs
Merge commit '7ea7cd165ad6705603852771bf82cc2fd6560db5' into clippyup2
[rust.git] / tests / ui / new_without_default.rs
index 46d2bc45f68102f2a4a8db8fd2d8521d3a6dff10..3b6041823d8786672ec6bb3d7bdae19acaeaa428 100644 (file)
@@ -1,47 +1,43 @@
-// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-
-#![feature(tool_lints)]
-
 #![feature(const_fn)]
-
-
-#![allow(dead_code)]
-#![warn(clippy::new_without_default, clippy::new_without_default_derive)]
+#![allow(dead_code, clippy::missing_safety_doc)]
+#![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> {
@@ -49,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> {
@@ -61,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> {
@@ -73,26 +77,34 @@ 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
+    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 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 fn new<T>() -> Self {
+        IgnoreGenericNew
+    } // the derived Default does not make sense here as the result depends on T
 }
 
 pub trait TraitWithNew: Sized {
@@ -101,4 +113,50 @@ fn new() -> Self {
     }
 }
 
+pub struct IgnoreUnsafeNew;
+
+impl IgnoreUnsafeNew {
+    pub unsafe fn new() -> Self {
+        IgnoreUnsafeNew
+    }
+}
+
+#[derive(Default)]
+pub struct OptionRefWrapper<'a, T>(Option<&'a T>);
+
+impl<'a, T> OptionRefWrapper<'a, T> {
+    pub fn new() -> Self {
+        OptionRefWrapper(None)
+    }
+}
+
+pub struct Allow(Foo);
+
+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!()
+    }
+}
+
+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 }
+    }
+}
+
 fn main() {}