1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
17 #![warn(clippy::new_without_default, clippy::new_without_default_derive)]
22 pub fn new() -> Foo { Foo }
28 pub fn new() -> Self { Bar }
34 pub fn new() -> Self { Ok }
38 fn default() -> Self { Ok }
44 pub fn new(_: u32) -> Self { Params }
47 pub struct GenericsOk<T> {
51 impl<U> Default for GenericsOk<U> {
52 fn default() -> Self { unimplemented!(); }
55 impl<'c, V> GenericsOk<V> {
56 pub fn new() -> GenericsOk<V> { unimplemented!() }
63 impl<'b> Default for LtOk<'b> {
64 fn default() -> Self { unimplemented!(); }
68 pub fn new() -> LtOk<'c> { unimplemented!() }
76 pub fn new() -> LtKo<'c> { unimplemented!() }
77 // FIXME: that suggestion is missing lifetimes
83 fn new() -> Private { unimplemented!() } // We don't lint private items
89 pub const fn new() -> Const { Const } // const fns can't be implemented via Default
92 pub struct IgnoreGenericNew;
94 impl IgnoreGenericNew {
95 pub fn new<T>() -> Self { IgnoreGenericNew } // the derived Default does not make sense here as the result depends on T
98 pub trait TraitWithNew: Sized {
104 pub struct IgnoreUnsafeNew;
106 impl IgnoreUnsafeNew {
107 pub unsafe fn new() -> Self { IgnoreUnsafeNew }
111 pub struct OptionRefWrapper<'a, T: 'a>(Option<&'a T>);
113 impl<'a, T: 'a> OptionRefWrapper<'a, T> {
114 pub fn new() -> Self {
115 OptionRefWrapper(None)