]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/default_trait_access.fixed
New upstream version 1.61.0+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / default_trait_access.fixed
1 // run-rustfix
2
3 #![allow(unused_imports, dead_code)]
4 #![deny(clippy::default_trait_access)]
5
6 use std::default;
7 use std::default::Default as D2;
8 use std::string;
9
10 fn main() {
11 let s1: String = std::string::String::default();
12
13 let s2 = String::default();
14
15 let s3: String = std::string::String::default();
16
17 let s4: String = std::string::String::default();
18
19 let s5 = string::String::default();
20
21 let s6: String = std::string::String::default();
22
23 let s7 = std::string::String::default();
24
25 let s8: String = DefaultFactory::make_t_badly();
26
27 let s9: String = DefaultFactory::make_t_nicely();
28
29 let s10 = DerivedDefault::default();
30
31 let s11: GenericDerivedDefault<String> = GenericDerivedDefault::default();
32
33 let s12 = GenericDerivedDefault::<String>::default();
34
35 let s13 = TupleDerivedDefault::default();
36
37 let s14: TupleDerivedDefault = TupleDerivedDefault::default();
38
39 let s15: ArrayDerivedDefault = ArrayDerivedDefault::default();
40
41 let s16 = ArrayDerivedDefault::default();
42
43 let s17: TupleStructDerivedDefault = TupleStructDerivedDefault::default();
44
45 let s18 = TupleStructDerivedDefault::default();
46
47 let s19 = <DerivedDefault as Default>::default();
48
49 let s20 = UpdateSyntax {
50 s: "foo",
51 ..Default::default()
52 };
53
54 println!(
55 "[{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}]",
56 s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19, s20,
57 );
58 }
59
60 struct DefaultFactory;
61
62 impl DefaultFactory {
63 pub fn make_t_badly<T: Default>() -> T {
64 Default::default()
65 }
66
67 pub fn make_t_nicely<T: Default>() -> T {
68 T::default()
69 }
70 }
71
72 #[derive(Debug, Default)]
73 struct DerivedDefault {
74 pub s: String,
75 }
76
77 #[derive(Debug, Default)]
78 struct GenericDerivedDefault<T: Default + std::fmt::Debug> {
79 pub s: T,
80 }
81
82 #[derive(Debug, Default)]
83 struct TupleDerivedDefault {
84 pub s: (String, String),
85 }
86
87 #[derive(Debug, Default)]
88 struct ArrayDerivedDefault {
89 pub s: [String; 10],
90 }
91
92 #[derive(Debug, Default)]
93 struct TupleStructDerivedDefault(String);
94
95 #[derive(Debug, Default)]
96 struct UpdateSyntax {
97 pub s: &'static str,
98 pub u: u64,
99 }