2018-05-11 11:20:39 +00:00
|
|
|
#![feature(const_fn)]
|
2019-10-02 15:19:30 +00:00
|
|
|
#![allow(dead_code, clippy::missing_safety_doc)]
|
2018-12-17 23:25:49 +00:00
|
|
|
#![warn(clippy::new_without_default)]
|
2016-03-01 15:25:15 +00:00
|
|
|
|
2016-06-01 21:35:14 +00:00
|
|
|
pub struct Foo;
|
2017-02-08 13:58:07 +00:00
|
|
|
|
2016-03-01 15:25:15 +00:00
|
|
|
impl Foo {
|
2018-12-09 22:26:16 +00:00
|
|
|
pub fn new() -> Foo {
|
|
|
|
Foo
|
|
|
|
}
|
2016-03-01 15:25:15 +00:00
|
|
|
}
|
|
|
|
|
2016-06-01 21:35:14 +00:00
|
|
|
pub struct Bar;
|
2017-02-08 13:58:07 +00:00
|
|
|
|
2016-03-01 15:25:15 +00:00
|
|
|
impl Bar {
|
2018-12-09 22:26:16 +00:00
|
|
|
pub fn new() -> Self {
|
|
|
|
Bar
|
|
|
|
}
|
2016-03-01 15:25:15 +00:00
|
|
|
}
|
|
|
|
|
2016-06-01 21:35:14 +00:00
|
|
|
pub struct Ok;
|
2016-03-01 15:25:15 +00:00
|
|
|
|
|
|
|
impl Ok {
|
2018-12-09 22:26:16 +00:00
|
|
|
pub fn new() -> Self {
|
|
|
|
Ok
|
|
|
|
}
|
2016-03-01 15:25:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Ok {
|
2018-12-09 22:26:16 +00:00
|
|
|
fn default() -> Self {
|
|
|
|
Ok
|
|
|
|
}
|
2016-03-01 15:25:15 +00:00
|
|
|
}
|
|
|
|
|
2016-06-01 21:35:14 +00:00
|
|
|
pub struct Params;
|
2016-03-01 15:25:15 +00:00
|
|
|
|
|
|
|
impl Params {
|
2018-12-09 22:26:16 +00:00
|
|
|
pub fn new(_: u32) -> Self {
|
|
|
|
Params
|
|
|
|
}
|
2016-03-01 15:25:15 +00:00
|
|
|
}
|
|
|
|
|
2016-06-01 21:35:14 +00:00
|
|
|
pub struct GenericsOk<T> {
|
2016-03-03 18:46:10 +00:00
|
|
|
bar: T,
|
|
|
|
}
|
|
|
|
|
2016-03-18 18:12:32 +00:00
|
|
|
impl<U> Default for GenericsOk<U> {
|
2018-12-09 22:26:16 +00:00
|
|
|
fn default() -> Self {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2016-03-18 18:12:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'c, V> GenericsOk<V> {
|
2018-12-09 22:26:16 +00:00
|
|
|
pub fn new() -> GenericsOk<V> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
2016-03-18 18:12:32 +00:00
|
|
|
}
|
|
|
|
|
2016-06-01 21:35:14 +00:00
|
|
|
pub struct LtOk<'a> {
|
2016-03-18 18:12:32 +00:00
|
|
|
foo: &'a bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'b> Default for LtOk<'b> {
|
2018-12-09 22:26:16 +00:00
|
|
|
fn default() -> Self {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2016-03-18 18:12:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'c> LtOk<'c> {
|
2018-12-09 22:26:16 +00:00
|
|
|
pub fn new() -> LtOk<'c> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
2016-03-18 18:12:32 +00:00
|
|
|
}
|
|
|
|
|
2016-06-01 21:35:14 +00:00
|
|
|
pub struct LtKo<'a> {
|
2016-03-18 18:12:32 +00:00
|
|
|
foo: &'a bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'c> LtKo<'c> {
|
2018-12-09 22:26:16 +00:00
|
|
|
pub fn new() -> LtKo<'c> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
2016-07-10 12:07:13 +00:00
|
|
|
// FIXME: that suggestion is missing lifetimes
|
2016-06-01 21:35:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Private;
|
|
|
|
|
|
|
|
impl Private {
|
2018-12-09 22:26:16 +00:00
|
|
|
fn new() -> Private {
|
|
|
|
unimplemented!()
|
|
|
|
} // We don't lint private items
|
2016-03-03 18:46:10 +00:00
|
|
|
}
|
|
|
|
|
2016-06-03 14:45:07 +00:00
|
|
|
struct Const;
|
|
|
|
|
|
|
|
impl Const {
|
2018-12-09 22:26:16 +00:00
|
|
|
pub const fn new() -> Const {
|
|
|
|
Const
|
|
|
|
} // const fns can't be implemented via Default
|
2016-06-03 14:45:07 +00:00
|
|
|
}
|
2017-06-14 16:50:19 +00:00
|
|
|
|
|
|
|
pub struct IgnoreGenericNew;
|
|
|
|
|
|
|
|
impl IgnoreGenericNew {
|
2018-12-09 22:26:16 +00:00
|
|
|
pub fn new<T>() -> Self {
|
|
|
|
IgnoreGenericNew
|
|
|
|
} // the derived Default does not make sense here as the result depends on T
|
2017-06-14 16:50:19 +00:00
|
|
|
}
|
|
|
|
|
2017-11-29 16:06:27 +00:00
|
|
|
pub trait TraitWithNew: Sized {
|
|
|
|
fn new() -> Self {
|
|
|
|
panic!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-07 10:39:54 +00:00
|
|
|
pub struct IgnoreUnsafeNew;
|
|
|
|
|
|
|
|
impl IgnoreUnsafeNew {
|
2018-12-09 22:26:16 +00:00
|
|
|
pub unsafe fn new() -> Self {
|
|
|
|
IgnoreUnsafeNew
|
|
|
|
}
|
2018-10-07 10:39:54 +00:00
|
|
|
}
|
|
|
|
|
2018-10-22 04:59:45 +00:00
|
|
|
#[derive(Default)]
|
2019-06-19 18:36:23 +00:00
|
|
|
pub struct OptionRefWrapper<'a, T>(Option<&'a T>);
|
2018-10-22 04:59:45 +00:00
|
|
|
|
2019-06-19 18:36:23 +00:00
|
|
|
impl<'a, T> OptionRefWrapper<'a, T> {
|
2018-10-22 04:59:45 +00:00
|
|
|
pub fn new() -> Self {
|
|
|
|
OptionRefWrapper(None)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-11 06:06:41 +00:00
|
|
|
pub struct Allow(Foo);
|
|
|
|
|
|
|
|
impl Allow {
|
|
|
|
#[allow(clippy::new_without_default)]
|
2018-12-27 15:17:45 +00:00
|
|
|
pub fn new() -> Self {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
2018-12-11 06:06:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct AllowDerive;
|
|
|
|
|
|
|
|
impl AllowDerive {
|
2018-12-17 23:25:49 +00:00
|
|
|
#[allow(clippy::new_without_default)]
|
2018-12-27 15:17:45 +00:00
|
|
|
pub fn new() -> Self {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
2018-12-11 06:06:41 +00:00
|
|
|
}
|
|
|
|
|
2020-05-28 13:45:24 +00:00
|
|
|
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 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-01 15:25:15 +00:00
|
|
|
fn main() {}
|