|
1 |
| -// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint |
2 |
| -#![allow(static_mut_refs)] |
3 |
| - |
4 | 1 | use core::iter::TrustedLen;
|
5 | 2 |
|
6 | 3 | use super::*;
|
| 4 | +use crate::testing::macros::struct_with_counted_drop; |
7 | 5 |
|
8 | 6 | #[bench]
|
9 | 7 | fn bench_push_back_100(b: &mut test::Bencher) {
|
@@ -1086,36 +1084,24 @@ fn test_clone_from() {
|
1086 | 1084 |
|
1087 | 1085 | #[test]
|
1088 | 1086 | fn test_vec_deque_truncate_drop() {
|
1089 |
| - static mut DROPS: u32 = 0; |
1090 |
| - #[derive(Clone)] |
1091 |
| - struct Elem(#[allow(dead_code)] i32); |
1092 |
| - impl Drop for Elem { |
1093 |
| - fn drop(&mut self) { |
1094 |
| - unsafe { |
1095 |
| - DROPS += 1; |
1096 |
| - } |
1097 |
| - } |
1098 |
| - } |
| 1087 | + struct_with_counted_drop!(Elem, DROPS); |
1099 | 1088 |
|
1100 |
| - let v = vec![Elem(1), Elem(2), Elem(3), Elem(4), Elem(5)]; |
1101 |
| - for push_front in 0..=v.len() { |
1102 |
| - let v = v.clone(); |
1103 |
| - let mut tester = VecDeque::with_capacity(5); |
1104 |
| - for (index, elem) in v.into_iter().enumerate() { |
| 1089 | + const LEN: usize = 5; |
| 1090 | + for push_front in 0..=LEN { |
| 1091 | + let mut tester = VecDeque::with_capacity(LEN); |
| 1092 | + for index in 0..LEN { |
1105 | 1093 | if index < push_front {
|
1106 |
| - tester.push_front(elem); |
| 1094 | + tester.push_front(Elem); |
1107 | 1095 | } else {
|
1108 |
| - tester.push_back(elem); |
| 1096 | + tester.push_back(Elem); |
1109 | 1097 | }
|
1110 | 1098 | }
|
1111 |
| - assert_eq!(unsafe { DROPS }, 0); |
| 1099 | + assert_eq!(DROPS.get(), 0); |
1112 | 1100 | tester.truncate(3);
|
1113 |
| - assert_eq!(unsafe { DROPS }, 2); |
| 1101 | + assert_eq!(DROPS.get(), 2); |
1114 | 1102 | tester.truncate(0);
|
1115 |
| - assert_eq!(unsafe { DROPS }, 5); |
1116 |
| - unsafe { |
1117 |
| - DROPS = 0; |
1118 |
| - } |
| 1103 | + assert_eq!(DROPS.get(), 5); |
| 1104 | + DROPS.set(0); |
1119 | 1105 | }
|
1120 | 1106 | }
|
1121 | 1107 |
|
|
0 commit comments