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