3 use std::collections::HashMap;
6 struct FooDefault<'a> {
24 struct TupleDefault(bool, i32, u64);
32 impl std::default::Default for FooND1 {
33 fn default() -> Self {
42 impl std::default::Default for FooND2 {
43 fn default() -> Self {
58 impl Default for FooNDNew {
59 fn default() -> Self {
64 struct FooNDVec(Vec<i32>);
66 impl Default for FooNDVec {
67 fn default() -> Self {
73 struct StrDefault<'a>(&'a str);
78 struct AlreadyDerived(i32, bool);
87 fn default() -> Self {
100 struct RustIssue26925<T> {
104 // We should watch out for cases where a manual impl is needed because a
105 // derive adds different type bounds (https://github.com/rust-lang/rust/issues/26925).
106 // For example, a struct with Option<T> does not require T: Default, but a derive adds
107 // that type bound anyways. So until #26925 get fixed we should disable lint
108 // for the following case
109 impl<T> Default for RustIssue26925<T> {
110 fn default() -> Self {
115 struct SpecializedImpl<A, B> {
120 impl<T: Default> Default for SpecializedImpl<T, T> {
121 fn default() -> Self {
130 struct WithoutSelfCurly {
137 struct WithoutSelfParan(bool);
141 // https://github.com/rust-lang/rust-clippy/issues/7655
143 pub struct SpecializedImpl2<T> {
147 impl Default for SpecializedImpl2<String> {
148 fn default() -> Self {
149 Self { v: Vec::new() }
153 // https://github.com/rust-lang/rust-clippy/issues/7654
162 impl Default for Color {
163 fn default() -> Self {
164 Color { r: 0, g: 0, b: 0 }
174 impl Default for Color2 {
176 fn default() -> Self {
177 Self { r: 0, g: 0, b: 0 }
182 pub struct RepeatDefault1 {
188 pub struct RepeatDefault2 {
192 impl Default for RepeatDefault2 {
193 fn default() -> Self {
194 RepeatDefault2 { a: [0; 33] }
198 // https://github.com/rust-lang/rust-clippy/issues/7753
200 pub enum IntOrString {
205 impl Default for IntOrString {
206 fn default() -> Self {
212 pub enum SimpleEnum {
220 pub enum NonExhaustiveEnum {
226 impl Default for NonExhaustiveEnum {
227 fn default() -> Self {
228 NonExhaustiveEnum::Bar
232 // https://github.com/rust-lang/rust-clippy/issues/10396
237 struct GenericType<T = DefaultType> {
241 impl Default for GenericType {
242 fn default() -> Self {
243 Self { t: Default::default() }
247 struct InnerGenericType<T> {
251 impl Default for InnerGenericType<DefaultType> {
252 fn default() -> Self {
253 Self { t: Default::default() }
257 struct OtherGenericType<T = DefaultType> {
258 inner: InnerGenericType<T>,
261 impl Default for OtherGenericType {
262 fn default() -> Self {
264 inner: Default::default(),
277 pub inner: Box<dyn T>,
280 impl Default for Outer {
281 fn default() -> Self {
283 // Box::<S>::default() adjusts to Box<dyn T>
284 inner: Box::<S>::default(),
297 fn default() -> Self {