]> git.lizzy.rs Git - rust.git/blob - tests/ui/new_without_default.rs
Merge branch 'master' into rustfmt_tests
[rust.git] / tests / ui / new_without_default.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
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.
9
10 #![feature(const_fn)]
11 #![allow(dead_code)]
12 #![warn(clippy::new_without_default, clippy::new_without_default_derive)]
13
14 pub struct Foo;
15
16 impl Foo {
17     pub fn new() -> Foo {
18         Foo
19     }
20 }
21
22 pub struct Bar;
23
24 impl Bar {
25     pub fn new() -> Self {
26         Bar
27     }
28 }
29
30 pub struct Ok;
31
32 impl Ok {
33     pub fn new() -> Self {
34         Ok
35     }
36 }
37
38 impl Default for Ok {
39     fn default() -> Self {
40         Ok
41     }
42 }
43
44 pub struct Params;
45
46 impl Params {
47     pub fn new(_: u32) -> Self {
48         Params
49     }
50 }
51
52 pub struct GenericsOk<T> {
53     bar: T,
54 }
55
56 impl<U> Default for GenericsOk<U> {
57     fn default() -> Self {
58         unimplemented!();
59     }
60 }
61
62 impl<'c, V> GenericsOk<V> {
63     pub fn new() -> GenericsOk<V> {
64         unimplemented!()
65     }
66 }
67
68 pub struct LtOk<'a> {
69     foo: &'a bool,
70 }
71
72 impl<'b> Default for LtOk<'b> {
73     fn default() -> Self {
74         unimplemented!();
75     }
76 }
77
78 impl<'c> LtOk<'c> {
79     pub fn new() -> LtOk<'c> {
80         unimplemented!()
81     }
82 }
83
84 pub struct LtKo<'a> {
85     foo: &'a bool,
86 }
87
88 impl<'c> LtKo<'c> {
89     pub fn new() -> LtKo<'c> {
90         unimplemented!()
91     }
92     // FIXME: that suggestion is missing lifetimes
93 }
94
95 struct Private;
96
97 impl Private {
98     fn new() -> Private {
99         unimplemented!()
100     } // We don't lint private items
101 }
102
103 struct Const;
104
105 impl Const {
106     pub const fn new() -> Const {
107         Const
108     } // const fns can't be implemented via Default
109 }
110
111 pub struct IgnoreGenericNew;
112
113 impl IgnoreGenericNew {
114     pub fn new<T>() -> Self {
115         IgnoreGenericNew
116     } // the derived Default does not make sense here as the result depends on T
117 }
118
119 pub trait TraitWithNew: Sized {
120     fn new() -> Self {
121         panic!()
122     }
123 }
124
125 pub struct IgnoreUnsafeNew;
126
127 impl IgnoreUnsafeNew {
128     pub unsafe fn new() -> Self {
129         IgnoreUnsafeNew
130     }
131 }
132
133 #[derive(Default)]
134 pub struct OptionRefWrapper<'a, T: 'a>(Option<&'a T>);
135
136 impl<'a, T: 'a> OptionRefWrapper<'a, T> {
137     pub fn new() -> Self {
138         OptionRefWrapper(None)
139     }
140 }
141
142 fn main() {}