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.
10 #![warn(clippy::default_trait_access)]
13 use std::default::Default as D2;
17 let s1: String = Default::default();
19 let s2 = String::default();
21 let s3: String = D2::default();
23 let s4: String = std::default::Default::default();
25 let s5 = string::String::default();
27 let s6: String = default::Default::default();
29 let s7 = std::string::String::default();
31 let s8: String = DefaultFactory::make_t_badly();
33 let s9: String = DefaultFactory::make_t_nicely();
35 let s10 = DerivedDefault::default();
37 let s11: GenericDerivedDefault<String> = Default::default();
39 let s12 = GenericDerivedDefault::<String>::default();
41 let s13 = TupleDerivedDefault::default();
43 let s14: TupleDerivedDefault = Default::default();
45 let s15: ArrayDerivedDefault = Default::default();
47 let s16 = ArrayDerivedDefault::default();
49 let s17: TupleStructDerivedDefault = Default::default();
51 let s18 = TupleStructDerivedDefault::default();
53 let s19 = <DerivedDefault as Default>::default();
56 "[{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}], [{:?}]",
79 struct DefaultFactory;
82 pub fn make_t_badly<T: Default>() -> T {
86 pub fn make_t_nicely<T: Default>() -> T {
91 #[derive(Debug, Default)]
92 struct DerivedDefault {
96 #[derive(Debug, Default)]
97 struct GenericDerivedDefault<T: Default + std::fmt::Debug> {
101 #[derive(Debug, Default)]
102 struct TupleDerivedDefault {
103 pub s: (String, String),
106 #[derive(Debug, Default)]
107 struct ArrayDerivedDefault {
111 #[derive(Debug, Default)]
112 struct TupleStructDerivedDefault(String);