]> git.lizzy.rs Git - rust.git/blob - tests/ui/default_trait_access.rs
Stabilize tool lints
[rust.git] / tests / ui / default_trait_access.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
11
12
13 #![warn(clippy::default_trait_access)]
14
15 use std::default::Default as D2;
16 use std::string;
17 use std::default;
18
19 fn main() {
20     let s1: String = Default::default();
21
22     let s2 = String::default();
23
24     let s3: String = D2::default();
25
26     let s4: String = std::default::Default::default();
27
28     let s5 = string::String::default();
29
30     let s6: String = default::Default::default();
31
32     let s7 = std::string::String::default();
33
34     let s8: String = DefaultFactory::make_t_badly();
35
36     let s9: String = DefaultFactory::make_t_nicely();
37
38     let s10 = DerivedDefault::default();
39
40     let s11: GenericDerivedDefault<String> = Default::default();
41
42     let s12 = GenericDerivedDefault::<String>::default();
43
44     let s13 = TupleDerivedDefault::default();
45
46     let s14: TupleDerivedDefault = Default::default();
47
48     let s15: ArrayDerivedDefault = Default::default();
49
50     let s16 = ArrayDerivedDefault::default();
51
52     let s17: TupleStructDerivedDefault = Default::default();
53
54     let s18 = TupleStructDerivedDefault::default();
55
56     let s19 = <DerivedDefault as Default>::default();
57
58     println!(
59         "[{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}], [{:?}]",
60         s1,
61         s2,
62         s3,
63         s4,
64         s5,
65         s6,
66         s7,
67         s8,
68         s9,
69         s10,
70         s11,
71         s12,
72         s13,
73         s14,
74         s15,
75         s16,
76         s17,
77         s18,
78         s19,
79     );
80 }
81
82 struct DefaultFactory;
83
84 impl DefaultFactory {
85     pub fn make_t_badly<T: Default>() -> T {
86         Default::default()
87     }
88
89     pub fn make_t_nicely<T: Default>() -> T {
90         T::default()
91     }
92 }
93
94 #[derive(Debug, Default)]
95 struct DerivedDefault {
96     pub s: String,
97 }
98
99 #[derive(Debug, Default)]
100 struct GenericDerivedDefault<T: Default + std::fmt::Debug> {
101     pub s: T,
102 }
103
104 #[derive(Debug, Default)]
105 struct TupleDerivedDefault {
106     pub s: (String, String),
107 }
108
109 #[derive(Debug, Default)]
110 struct ArrayDerivedDefault {
111     pub s: [String; 10],
112 }
113
114 #[derive(Debug, Default)]
115 struct TupleStructDerivedDefault(String);