2018-10-06 11:18:06 -05:00
|
|
|
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
|
2018-07-28 10:34:52 -05:00
|
|
|
#![feature(tool_lints)]
|
|
|
|
|
|
|
|
#![warn(clippy::default_trait_access)]
|
2018-06-14 02:57:27 -05:00
|
|
|
|
|
|
|
use std::default::Default as D2;
|
|
|
|
use std::string;
|
|
|
|
use std::default;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let s1: String = Default::default();
|
|
|
|
|
|
|
|
let s2 = String::default();
|
|
|
|
|
|
|
|
let s3: String = D2::default();
|
|
|
|
|
|
|
|
let s4: String = std::default::Default::default();
|
|
|
|
|
|
|
|
let s5 = string::String::default();
|
|
|
|
|
|
|
|
let s6: String = default::Default::default();
|
|
|
|
|
|
|
|
let s7 = std::string::String::default();
|
|
|
|
|
|
|
|
let s8: String = DefaultFactory::make_t_badly();
|
|
|
|
|
|
|
|
let s9: String = DefaultFactory::make_t_nicely();
|
|
|
|
|
2018-06-17 16:58:08 -05:00
|
|
|
let s10 = DerivedDefault::default();
|
|
|
|
|
|
|
|
let s11: GenericDerivedDefault<String> = Default::default();
|
|
|
|
|
|
|
|
let s12 = GenericDerivedDefault::<String>::default();
|
|
|
|
|
|
|
|
let s13 = TupleDerivedDefault::default();
|
|
|
|
|
|
|
|
let s14: TupleDerivedDefault = Default::default();
|
|
|
|
|
|
|
|
let s15: ArrayDerivedDefault = Default::default();
|
|
|
|
|
|
|
|
let s16 = ArrayDerivedDefault::default();
|
|
|
|
|
|
|
|
let s17: TupleStructDerivedDefault = Default::default();
|
|
|
|
|
|
|
|
let s18 = TupleStructDerivedDefault::default();
|
|
|
|
|
2018-08-27 17:22:07 -05:00
|
|
|
let s19 = <DerivedDefault as Default>::default();
|
|
|
|
|
2018-06-17 16:58:08 -05:00
|
|
|
println!(
|
2018-08-27 17:22:07 -05:00
|
|
|
"[{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}], [{:?}]",
|
2018-06-17 16:58:08 -05:00
|
|
|
s1,
|
|
|
|
s2,
|
|
|
|
s3,
|
|
|
|
s4,
|
|
|
|
s5,
|
|
|
|
s6,
|
|
|
|
s7,
|
|
|
|
s8,
|
|
|
|
s9,
|
|
|
|
s10,
|
|
|
|
s11,
|
|
|
|
s12,
|
|
|
|
s13,
|
|
|
|
s14,
|
|
|
|
s15,
|
|
|
|
s16,
|
|
|
|
s17,
|
|
|
|
s18,
|
2018-08-27 17:22:07 -05:00
|
|
|
s19,
|
2018-06-17 16:58:08 -05:00
|
|
|
);
|
2018-06-14 02:57:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
struct DefaultFactory;
|
|
|
|
|
|
|
|
impl DefaultFactory {
|
|
|
|
pub fn make_t_badly<T: Default>() -> T {
|
|
|
|
Default::default()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn make_t_nicely<T: Default>() -> T {
|
|
|
|
T::default()
|
|
|
|
}
|
|
|
|
}
|
2018-06-17 16:58:08 -05:00
|
|
|
|
|
|
|
#[derive(Debug, Default)]
|
|
|
|
struct DerivedDefault {
|
|
|
|
pub s: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Default)]
|
|
|
|
struct GenericDerivedDefault<T: Default + std::fmt::Debug> {
|
|
|
|
pub s: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Default)]
|
|
|
|
struct TupleDerivedDefault {
|
|
|
|
pub s: (String, String),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Default)]
|
|
|
|
struct ArrayDerivedDefault {
|
|
|
|
pub s: [String; 10],
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Default)]
|
|
|
|
struct TupleStructDerivedDefault(String);
|