]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/new_without_default.rs
Update upstream source from tag 'upstream/1.52.1+dfsg1'
[rustc.git] / src / tools / clippy / tests / ui / new_without_default.rs
CommitLineData
f20569fa
XL
1#![feature(const_fn)]
2#![allow(dead_code, clippy::missing_safety_doc)]
3#![warn(clippy::new_without_default)]
4
5pub struct Foo;
6
7impl Foo {
8 pub fn new() -> Foo {
9 Foo
10 }
11}
12
13pub struct Bar;
14
15impl Bar {
16 pub fn new() -> Self {
17 Bar
18 }
19}
20
21pub struct Ok;
22
23impl Ok {
24 pub fn new() -> Self {
25 Ok
26 }
27}
28
29impl Default for Ok {
30 fn default() -> Self {
31 Ok
32 }
33}
34
35pub struct Params;
36
37impl Params {
38 pub fn new(_: u32) -> Self {
39 Params
40 }
41}
42
43pub struct GenericsOk<T> {
44 bar: T,
45}
46
47impl<U> Default for GenericsOk<U> {
48 fn default() -> Self {
49 unimplemented!();
50 }
51}
52
53impl<'c, V> GenericsOk<V> {
54 pub fn new() -> GenericsOk<V> {
55 unimplemented!()
56 }
57}
58
59pub struct LtOk<'a> {
60 foo: &'a bool,
61}
62
63impl<'b> Default for LtOk<'b> {
64 fn default() -> Self {
65 unimplemented!();
66 }
67}
68
69impl<'c> LtOk<'c> {
70 pub fn new() -> LtOk<'c> {
71 unimplemented!()
72 }
73}
74
75pub struct LtKo<'a> {
76 foo: &'a bool,
77}
78
79impl<'c> LtKo<'c> {
80 pub fn new() -> LtKo<'c> {
81 unimplemented!()
82 }
83 // FIXME: that suggestion is missing lifetimes
84}
85
86struct Private;
87
88impl Private {
89 fn new() -> Private {
90 unimplemented!()
91 } // We don't lint private items
92}
93
94struct Const;
95
96impl Const {
97 pub const fn new() -> Const {
98 Const
99 } // const fns can't be implemented via Default
100}
101
102pub struct IgnoreGenericNew;
103
104impl IgnoreGenericNew {
105 pub fn new<T>() -> Self {
106 IgnoreGenericNew
107 } // the derived Default does not make sense here as the result depends on T
108}
109
110pub trait TraitWithNew: Sized {
111 fn new() -> Self {
112 panic!()
113 }
114}
115
116pub struct IgnoreUnsafeNew;
117
118impl IgnoreUnsafeNew {
119 pub unsafe fn new() -> Self {
120 IgnoreUnsafeNew
121 }
122}
123
124#[derive(Default)]
125pub struct OptionRefWrapper<'a, T>(Option<&'a T>);
126
127impl<'a, T> OptionRefWrapper<'a, T> {
128 pub fn new() -> Self {
129 OptionRefWrapper(None)
130 }
131}
132
133pub struct Allow(Foo);
134
135impl Allow {
136 #[allow(clippy::new_without_default)]
137 pub fn new() -> Self {
138 unimplemented!()
139 }
140}
141
142pub struct AllowDerive;
143
144impl AllowDerive {
145 #[allow(clippy::new_without_default)]
146 pub fn new() -> Self {
147 unimplemented!()
148 }
149}
150
151pub struct NewNotEqualToDerive {
152 foo: i32,
153}
154
155impl NewNotEqualToDerive {
156 // This `new` implementation is not equal to a derived `Default`, so do not suggest deriving.
157 pub fn new() -> Self {
158 NewNotEqualToDerive { foo: 1 }
159 }
160}
161
162fn main() {}