Skip to content

Commit 023da2b

Browse files
committed
alloc: less static mut
1 parent 015c777 commit 023da2b

File tree

1 file changed

+4
-5
lines changed
  • library/alloc/src/collections/linked_list

1 file changed

+4
-5
lines changed

library/alloc/src/collections/linked_list/tests.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
22
#![allow(static_mut_refs)]
33

4+
use std::cell::Cell;
45
use std::panic::{AssertUnwindSafe, catch_unwind};
56
use std::thread;
67

@@ -1030,16 +1031,14 @@ fn extract_if_drop_panic_leak() {
10301031
#[test]
10311032
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
10321033
fn extract_if_pred_panic_leak() {
1033-
static mut DROPS: i32 = 0;
1034+
thread_local! {static DROPS: Cell<i32> = Cell::new(0);}
10341035

10351036
#[derive(Debug)]
10361037
struct D(u32);
10371038

10381039
impl Drop for D {
10391040
fn drop(&mut self) {
1040-
unsafe {
1041-
DROPS += 1;
1042-
}
1041+
DROPS.with(|drops| drops.update(|v| v + 1));
10431042
}
10441043
}
10451044

@@ -1058,7 +1057,7 @@ fn extract_if_pred_panic_leak() {
10581057
}))
10591058
.ok();
10601059

1061-
assert_eq!(unsafe { DROPS }, 2); // 0 and 1
1060+
DROPS.with(|drops| assert_eq!(drops.get(), 2)); // 0 and 1
10621061
assert_eq!(q.len(), 6);
10631062
}
10641063

0 commit comments

Comments
 (0)