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