|
| 1 | +#![feature(custom_inner_attributes)] |
| 2 | +#![rustfmt::skip] |
| 3 | +#![allow(clippy::trivially_copy_pass_by_ref, clippy::cognitive_complexity)] |
| 4 | + |
| 5 | +struct S; |
| 6 | + |
| 7 | +impl S { |
| 8 | + fn bool_self_ref(&self) -> bool { false } |
| 9 | + fn bool_self_mut(&mut self) -> bool { false } |
| 10 | + fn bool_self_ref_arg_ref(&self, _: &u32) -> bool { false } |
| 11 | + fn bool_self_ref_arg_mut(&self, _: &mut u32) -> bool { false } |
| 12 | + fn bool_self_mut_arg_ref(&mut self, _: &u32) -> bool { false } |
| 13 | + fn bool_self_mut_arg_mut(&mut self, _: &mut u32) -> bool { false } |
| 14 | + |
| 15 | + fn u32_self_ref(&self) -> u32 { 0 } |
| 16 | + fn u32_self_mut(&mut self) -> u32 { 0 } |
| 17 | + fn u32_self_ref_arg_ref(&self, _: &u32) -> u32 { 0 } |
| 18 | + fn u32_self_ref_arg_mut(&self, _: &mut u32) -> u32 { 0 } |
| 19 | + fn u32_self_mut_arg_ref(&mut self, _: &u32) -> u32 { 0 } |
| 20 | + fn u32_self_mut_arg_mut(&mut self, _: &mut u32) -> u32 { 0 } |
| 21 | +} |
| 22 | + |
| 23 | +fn bool_ref(_: &u32) -> bool { false } |
| 24 | +fn bool_mut(_: &mut u32) -> bool { false } |
| 25 | +fn u32_ref(_: &u32) -> u32 { 0 } |
| 26 | +fn u32_mut(_: &mut u32) -> u32 { 0 } |
| 27 | + |
| 28 | +fn func_non_mutable() { |
| 29 | + debug_assert!(bool_ref(&3)); |
| 30 | + debug_assert!(!bool_ref(&3)); |
| 31 | + |
| 32 | + debug_assert_eq!(0, u32_ref(&3)); |
| 33 | + debug_assert_eq!(u32_ref(&3), 0); |
| 34 | + |
| 35 | + debug_assert_ne!(1, u32_ref(&3)); |
| 36 | + debug_assert_ne!(u32_ref(&3), 1); |
| 37 | +} |
| 38 | + |
| 39 | +fn func_mutable() { |
| 40 | + debug_assert!(bool_mut(&mut 3)); |
| 41 | + debug_assert!(!bool_mut(&mut 3)); |
| 42 | + |
| 43 | + debug_assert_eq!(0, u32_mut(&mut 3)); |
| 44 | + debug_assert_eq!(u32_mut(&mut 3), 0); |
| 45 | + |
| 46 | + debug_assert_ne!(1, u32_mut(&mut 3)); |
| 47 | + debug_assert_ne!(u32_mut(&mut 3), 1); |
| 48 | +} |
| 49 | + |
| 50 | +fn method_non_mutable() { |
| 51 | + debug_assert!(S.bool_self_ref()); |
| 52 | + debug_assert!(S.bool_self_ref_arg_ref(&3)); |
| 53 | + |
| 54 | + debug_assert_eq!(S.u32_self_ref(), 0); |
| 55 | + debug_assert_eq!(S.u32_self_ref_arg_ref(&3), 0); |
| 56 | + |
| 57 | + debug_assert_ne!(S.u32_self_ref(), 1); |
| 58 | + debug_assert_ne!(S.u32_self_ref_arg_ref(&3), 1); |
| 59 | +} |
| 60 | + |
| 61 | +fn method_mutable() { |
| 62 | + debug_assert!(S.bool_self_mut()); |
| 63 | + debug_assert!(!S.bool_self_mut()); |
| 64 | + debug_assert!(S.bool_self_ref_arg_mut(&mut 3)); |
| 65 | + debug_assert!(S.bool_self_mut_arg_ref(&3)); |
| 66 | + debug_assert!(S.bool_self_mut_arg_mut(&mut 3)); |
| 67 | + |
| 68 | + debug_assert_eq!(S.u32_self_mut(), 0); |
| 69 | + debug_assert_eq!(S.u32_self_mut_arg_ref(&3), 0); |
| 70 | + debug_assert_eq!(S.u32_self_ref_arg_mut(&mut 3), 0); |
| 71 | + debug_assert_eq!(S.u32_self_mut_arg_mut(&mut 3), 0); |
| 72 | + |
| 73 | + debug_assert_ne!(S.u32_self_mut(), 1); |
| 74 | + debug_assert_ne!(S.u32_self_mut_arg_ref(&3), 1); |
| 75 | + debug_assert_ne!(S.u32_self_ref_arg_mut(&mut 3), 1); |
| 76 | + debug_assert_ne!(S.u32_self_mut_arg_mut(&mut 3), 1); |
| 77 | +} |
| 78 | + |
| 79 | +fn misc() { |
| 80 | + // with variable |
| 81 | + let mut v: Vec<u32> = vec![1, 2, 3, 4]; |
| 82 | + debug_assert_eq!(v.get(0), Some(&1)); |
| 83 | + debug_assert_ne!(v[0], 2); |
| 84 | + debug_assert_eq!(v.pop(), Some(1)); |
| 85 | + debug_assert_ne!(Some(3), v.pop()); |
| 86 | + |
| 87 | + let a = &mut 3; |
| 88 | + debug_assert!(bool_mut(a)); |
| 89 | + |
| 90 | + // nested |
| 91 | + debug_assert!(!(bool_ref(&u32_mut(&mut 3)))); |
| 92 | + |
| 93 | + // chained |
| 94 | + debug_assert_eq!(v.pop().unwrap(), 3); |
| 95 | + |
| 96 | + // format args |
| 97 | + debug_assert!(bool_ref(&3), "w/o format"); |
| 98 | + debug_assert!(bool_mut(&mut 3), "w/o format"); |
| 99 | + debug_assert!(bool_ref(&3), "{} format", "w/"); |
| 100 | + debug_assert!(bool_mut(&mut 3), "{} format", "w/"); |
| 101 | +} |
| 102 | + |
| 103 | +fn main() { |
| 104 | + func_non_mutable(); |
| 105 | + func_mutable(); |
| 106 | + method_non_mutable(); |
| 107 | + method_mutable(); |
| 108 | + |
| 109 | + misc(); |
| 110 | +} |
0 commit comments