1 #![feature(custom_inner_attributes)]
2 #![rustfmt::skip]
3 #![warn(clippy::debug_assert_with_mut_call)]
4 #![allow(clippy::redundant_closure_call)]
5
6
7 struct S;
8
9 impl S {
bool_self_ref(&self) -> bool10 fn bool_self_ref(&self) -> bool { false }
bool_self_mut(&mut self) -> bool11 fn bool_self_mut(&mut self) -> bool { false }
bool_self_ref_arg_ref(&self, _: &u32) -> bool12 fn bool_self_ref_arg_ref(&self, _: &u32) -> bool { false }
bool_self_ref_arg_mut(&self, _: &mut u32) -> bool13 fn bool_self_ref_arg_mut(&self, _: &mut u32) -> bool { false }
bool_self_mut_arg_ref(&mut self, _: &u32) -> bool14 fn bool_self_mut_arg_ref(&mut self, _: &u32) -> bool { false }
bool_self_mut_arg_mut(&mut self, _: &mut u32) -> bool15 fn bool_self_mut_arg_mut(&mut self, _: &mut u32) -> bool { false }
16
u32_self_ref(&self) -> u3217 fn u32_self_ref(&self) -> u32 { 0 }
u32_self_mut(&mut self) -> u3218 fn u32_self_mut(&mut self) -> u32 { 0 }
u32_self_ref_arg_ref(&self, _: &u32) -> u3219 fn u32_self_ref_arg_ref(&self, _: &u32) -> u32 { 0 }
u32_self_ref_arg_mut(&self, _: &mut u32) -> u3220 fn u32_self_ref_arg_mut(&self, _: &mut u32) -> u32 { 0 }
u32_self_mut_arg_ref(&mut self, _: &u32) -> u3221 fn u32_self_mut_arg_ref(&mut self, _: &u32) -> u32 { 0 }
u32_self_mut_arg_mut(&mut self, _: &mut u32) -> u3222 fn u32_self_mut_arg_mut(&mut self, _: &mut u32) -> u32 { 0 }
23 }
24
bool_ref(_: &u32) -> bool25 fn bool_ref(_: &u32) -> bool { false }
bool_mut(_: &mut u32) -> bool26 fn bool_mut(_: &mut u32) -> bool { false }
u32_ref(_: &u32) -> u3227 fn u32_ref(_: &u32) -> u32 { 0 }
u32_mut(_: &mut u32) -> u3228 fn u32_mut(_: &mut u32) -> u32 { 0 }
29
func_non_mutable()30 fn func_non_mutable() {
31 debug_assert!(bool_ref(&3));
32 debug_assert!(!bool_ref(&3));
33
34 debug_assert_eq!(0, u32_ref(&3));
35 debug_assert_eq!(u32_ref(&3), 0);
36
37 debug_assert_ne!(1, u32_ref(&3));
38 debug_assert_ne!(u32_ref(&3), 1);
39 }
40
func_mutable()41 fn func_mutable() {
42 debug_assert!(bool_mut(&mut 3));
43 debug_assert!(!bool_mut(&mut 3));
44
45 debug_assert_eq!(0, u32_mut(&mut 3));
46 debug_assert_eq!(u32_mut(&mut 3), 0);
47
48 debug_assert_ne!(1, u32_mut(&mut 3));
49 debug_assert_ne!(u32_mut(&mut 3), 1);
50 }
51
method_non_mutable()52 fn method_non_mutable() {
53 debug_assert!(S.bool_self_ref());
54 debug_assert!(S.bool_self_ref_arg_ref(&3));
55
56 debug_assert_eq!(S.u32_self_ref(), 0);
57 debug_assert_eq!(S.u32_self_ref_arg_ref(&3), 0);
58
59 debug_assert_ne!(S.u32_self_ref(), 1);
60 debug_assert_ne!(S.u32_self_ref_arg_ref(&3), 1);
61 }
62
method_mutable()63 fn method_mutable() {
64 debug_assert!(S.bool_self_mut());
65 debug_assert!(!S.bool_self_mut());
66 debug_assert!(S.bool_self_ref_arg_mut(&mut 3));
67 debug_assert!(S.bool_self_mut_arg_ref(&3));
68 debug_assert!(S.bool_self_mut_arg_mut(&mut 3));
69
70 debug_assert_eq!(S.u32_self_mut(), 0);
71 debug_assert_eq!(S.u32_self_mut_arg_ref(&3), 0);
72 debug_assert_eq!(S.u32_self_ref_arg_mut(&mut 3), 0);
73 debug_assert_eq!(S.u32_self_mut_arg_mut(&mut 3), 0);
74
75 debug_assert_ne!(S.u32_self_mut(), 1);
76 debug_assert_ne!(S.u32_self_mut_arg_ref(&3), 1);
77 debug_assert_ne!(S.u32_self_ref_arg_mut(&mut 3), 1);
78 debug_assert_ne!(S.u32_self_mut_arg_mut(&mut 3), 1);
79 }
80
misc()81 fn misc() {
82 // with variable
83 let mut v: Vec<u32> = vec![1, 2, 3, 4];
84 debug_assert_eq!(v.get(0), Some(&1));
85 debug_assert_ne!(v[0], 2);
86 debug_assert_eq!(v.pop(), Some(1));
87 debug_assert_ne!(Some(3), v.pop());
88
89 let a = &mut 3;
90 debug_assert!(bool_mut(a));
91
92 // nested
93 debug_assert!(!(bool_ref(&u32_mut(&mut 3))));
94
95 // chained
96 debug_assert_eq!(v.pop().unwrap(), 3);
97
98 // format args
99 debug_assert!(bool_ref(&3), "w/o format");
100 debug_assert!(bool_mut(&mut 3), "w/o format");
101 debug_assert!(bool_ref(&3), "{} format", "w/");
102 debug_assert!(bool_mut(&mut 3), "{} format", "w/");
103
104 // sub block
105 let mut x = 42_u32;
106 debug_assert!({
107 bool_mut(&mut x);
108 x > 10
109 });
110
111 // closures
112 debug_assert!((|| {
113 let mut x = 42;
114 bool_mut(&mut x);
115 x > 10
116 })());
117 }
118
debug_await()119 async fn debug_await() {
120 debug_assert!(async {
121 true
122 }.await);
123 }
124
main()125 fn main() {
126 func_non_mutable();
127 func_mutable();
128 method_non_mutable();
129 method_mutable();
130
131 misc();
132 debug_await();
133 }
134