3 #![warn(clippy::unwrap_or_else_default)]
5 #![allow(clippy::unnecessary_wraps)]
7 /// Checks implementation of the `UNWRAP_OR_ELSE_DEFAULT` lint.
8 fn unwrap_or_else_default() {
16 // fake default, we should not trigger on this
22 struct HasDefaultAndDuplicate;
24 impl HasDefaultAndDuplicate {
25 fn default() -> Self {
26 HasDefaultAndDuplicate
30 impl Default for HasDefaultAndDuplicate {
31 fn default() -> Self {
32 HasDefaultAndDuplicate
40 fn make<T, V>(_: V) -> T {
44 let with_enum = Some(Enum::A());
45 with_enum.unwrap_or_else(Enum::A);
47 let with_new = Some(vec![1]);
48 with_new.unwrap_or_default();
50 let with_err: Result<_, ()> = Ok(vec![1]);
51 with_err.unwrap_or_else(make);
53 // should not be changed
54 let with_fake_default = None::<Foo>;
55 with_fake_default.unwrap_or_else(Foo::default);
57 // should not be changed
58 let with_fake_default2 = None::<HasDefaultAndDuplicate>;
59 with_fake_default2.unwrap_or_else(<HasDefaultAndDuplicate>::default);
61 let with_real_default = None::<HasDefaultAndDuplicate>;
62 with_real_default.unwrap_or_default();
64 let with_default_trait = Some(1);
65 with_default_trait.unwrap_or_default();
67 let with_default_type = Some(1);
68 with_default_type.unwrap_or_default();
70 let with_default_type: Option<Vec<u64>> = None;
71 with_default_type.unwrap_or_default();