1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
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.
13 #![warn(clippy::default_trait_access)]
15 use std::default::Default as D2;
20 let s1: String = Default::default();
22 let s2 = String::default();
24 let s3: String = D2::default();
26 let s4: String = std::default::Default::default();
28 let s5 = string::String::default();
30 let s6: String = default::Default::default();
32 let s7 = std::string::String::default();
34 let s8: String = DefaultFactory::make_t_badly();
36 let s9: String = DefaultFactory::make_t_nicely();
38 let s10 = DerivedDefault::default();
40 let s11: GenericDerivedDefault<String> = Default::default();
42 let s12 = GenericDerivedDefault::<String>::default();
44 let s13 = TupleDerivedDefault::default();
46 let s14: TupleDerivedDefault = Default::default();
48 let s15: ArrayDerivedDefault = Default::default();
50 let s16 = ArrayDerivedDefault::default();
52 let s17: TupleStructDerivedDefault = Default::default();
54 let s18 = TupleStructDerivedDefault::default();
56 let s19 = <DerivedDefault as Default>::default();
59 "[{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}], [{:?}]",
82 struct DefaultFactory;
85 pub fn make_t_badly<T: Default>() -> T {
89 pub fn make_t_nicely<T: Default>() -> T {
94 #[derive(Debug, Default)]
95 struct DerivedDefault {
99 #[derive(Debug, Default)]
100 struct GenericDerivedDefault<T: Default + std::fmt::Debug> {
104 #[derive(Debug, Default)]
105 struct TupleDerivedDefault {
106 pub s: (String, String),
109 #[derive(Debug, Default)]
110 struct ArrayDerivedDefault {
114 #[derive(Debug, Default)]
115 struct TupleStructDerivedDefault(String);