2023-04-20 14:37:15 +00:00
|
|
|
//@run-rustfix
|
2023-04-20 15:19:36 +00:00
|
|
|
//@aux-build: proc_macros.rs:proc-macro
|
2020-09-10 15:47:07 +00:00
|
|
|
#![deny(clippy::default_trait_access)]
|
2022-10-02 19:13:22 +00:00
|
|
|
#![allow(dead_code, unused_imports)]
|
|
|
|
#![allow(clippy::uninlined_format_args)]
|
2020-09-10 15:47:07 +00:00
|
|
|
|
2023-03-07 14:40:55 +00:00
|
|
|
extern crate proc_macros;
|
2022-04-13 14:13:39 +00:00
|
|
|
|
2023-03-07 14:40:55 +00:00
|
|
|
use proc_macros::with_span;
|
2020-09-10 15:47:07 +00:00
|
|
|
use std::default::Default as D2;
|
2023-07-03 17:42:48 +00:00
|
|
|
use std::{default, string};
|
2020-09-10 15:47:07 +00:00
|
|
|
|
|
|
|
fn main() {
|
2023-01-04 10:23:35 +00:00
|
|
|
let s1: String = String::default();
|
2020-09-10 15:47:07 +00:00
|
|
|
|
|
|
|
let s2 = String::default();
|
|
|
|
|
2023-01-04 10:23:35 +00:00
|
|
|
let s3: String = String::default();
|
2020-09-10 15:47:07 +00:00
|
|
|
|
2023-01-04 10:23:35 +00:00
|
|
|
let s4: String = String::default();
|
2020-09-10 15:47:07 +00:00
|
|
|
|
|
|
|
let s5 = string::String::default();
|
|
|
|
|
2023-01-04 10:23:35 +00:00
|
|
|
let s6: String = String::default();
|
2020-09-10 15:47:07 +00:00
|
|
|
|
|
|
|
let s7 = std::string::String::default();
|
|
|
|
|
|
|
|
let s8: String = DefaultFactory::make_t_badly();
|
|
|
|
|
|
|
|
let s9: String = DefaultFactory::make_t_nicely();
|
|
|
|
|
|
|
|
let s10 = DerivedDefault::default();
|
|
|
|
|
|
|
|
let s11: GenericDerivedDefault<String> = GenericDerivedDefault::default();
|
|
|
|
|
|
|
|
let s12 = GenericDerivedDefault::<String>::default();
|
|
|
|
|
|
|
|
let s13 = TupleDerivedDefault::default();
|
|
|
|
|
|
|
|
let s14: TupleDerivedDefault = TupleDerivedDefault::default();
|
|
|
|
|
|
|
|
let s15: ArrayDerivedDefault = ArrayDerivedDefault::default();
|
|
|
|
|
|
|
|
let s16 = ArrayDerivedDefault::default();
|
|
|
|
|
|
|
|
let s17: TupleStructDerivedDefault = TupleStructDerivedDefault::default();
|
|
|
|
|
|
|
|
let s18 = TupleStructDerivedDefault::default();
|
|
|
|
|
|
|
|
let s19 = <DerivedDefault as Default>::default();
|
|
|
|
|
2022-02-14 12:22:36 +00:00
|
|
|
let s20 = UpdateSyntax {
|
|
|
|
s: "foo",
|
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
|
2022-04-13 14:13:39 +00:00
|
|
|
let _s21: String = with_span!(s Default::default());
|
|
|
|
|
2020-09-10 15:47:07 +00:00
|
|
|
println!(
|
2022-02-14 12:22:36 +00:00
|
|
|
"[{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}]",
|
|
|
|
s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19, s20,
|
2020-09-10 15:47:07 +00: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()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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);
|
2022-02-14 12:22:36 +00:00
|
|
|
|
|
|
|
#[derive(Debug, Default)]
|
|
|
|
struct UpdateSyntax {
|
|
|
|
pub s: &'static str,
|
|
|
|
pub u: u64,
|
|
|
|
}
|