]> git.lizzy.rs Git - rust.git/blob - tests/ui/new_without_default.rs
Adapt the *.stderr files of the ui-tests to the tool_lints
[rust.git] / tests / ui / new_without_default.rs
1 #![feature(tool_lints)]
2
3 #![feature(const_fn)]
4
5
6 #![allow(dead_code)]
7 #![warn(clippy::new_without_default, clippy::new_without_default_derive)]
8
9 pub struct Foo;
10
11 impl Foo {
12     pub fn new() -> Foo { Foo }
13 }
14
15 pub struct Bar;
16
17 impl Bar {
18     pub fn new() -> Self { Bar }
19 }
20
21 pub struct Ok;
22
23 impl Ok {
24     pub fn new() -> Self { Ok }
25 }
26
27 impl Default for Ok {
28     fn default() -> Self { Ok }
29 }
30
31 pub struct Params;
32
33 impl Params {
34     pub fn new(_: u32) -> Self { Params }
35 }
36
37 pub struct GenericsOk<T> {
38     bar: T,
39 }
40
41 impl<U> Default for GenericsOk<U> {
42     fn default() -> Self { unimplemented!(); }
43 }
44
45 impl<'c, V> GenericsOk<V> {
46     pub fn new() -> GenericsOk<V> { unimplemented!() }
47 }
48
49 pub struct LtOk<'a> {
50     foo: &'a bool,
51 }
52
53 impl<'b> Default for LtOk<'b> {
54     fn default() -> Self { unimplemented!(); }
55 }
56
57 impl<'c> LtOk<'c> {
58     pub fn new() -> LtOk<'c> { unimplemented!() }
59 }
60
61 pub struct LtKo<'a> {
62     foo: &'a bool,
63 }
64
65 impl<'c> LtKo<'c> {
66     pub fn new() -> LtKo<'c> { unimplemented!() }
67     // FIXME: that suggestion is missing lifetimes
68 }
69
70 struct Private;
71
72 impl Private {
73     fn new() -> Private { unimplemented!() } // We don't lint private items
74 }
75
76 struct Const;
77
78 impl Const {
79     pub const fn new() -> Const { Const } // const fns can't be implemented via Default
80 }
81
82 pub struct IgnoreGenericNew;
83
84 impl IgnoreGenericNew {
85     pub fn new<T>() -> Self { IgnoreGenericNew } // the derived Default does not make sense here as the result depends on T
86 }
87
88 pub trait TraitWithNew: Sized {
89     fn new() -> Self {
90         panic!()
91     }
92 }
93
94 fn main() {}