Skip to content

Commit 021bcb9

Browse files
committed
fmt tests: remove static mut
1 parent 5bd918f commit 021bcb9

File tree

1 file changed

+26
-20
lines changed
  • library/alloctests/tests

1 file changed

+26
-20
lines changed

library/alloctests/tests/fmt.rs

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#![deny(warnings)]
2-
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
3-
#![allow(static_mut_refs)]
42
#![allow(unnecessary_transmutes)]
53

64
use std::cell::RefCell;
@@ -285,19 +283,32 @@ fn test_format_args() {
285283
t!(s, "args were: hello world");
286284
}
287285

286+
macro_rules! counter_fn {
287+
($name:ident) => {
288+
fn $name() -> u32 {
289+
thread_local! {static COUNTER: ::core::cell::Cell<u32> = ::core::cell::Cell::new(0);}
290+
291+
COUNTER.set(COUNTER.get() + 1);
292+
COUNTER.get()
293+
}
294+
};
295+
}
296+
288297
#[test]
289298
fn test_order() {
290-
// Make sure format!() arguments are always evaluated in a left-to-right
291-
// ordering
292-
fn foo() -> isize {
293-
static mut FOO: isize = 0;
294-
unsafe {
295-
FOO += 1;
296-
FOO
297-
}
298-
}
299+
// Make sure format!() arguments are always evaluated in a left-to-right ordering
300+
counter_fn!(count);
301+
299302
assert_eq!(
300-
format!("{} {} {a} {b} {} {c}", foo(), foo(), foo(), a = foo(), b = foo(), c = foo()),
303+
format!(
304+
"{} {} {a} {b} {} {c}",
305+
count(),
306+
count(),
307+
count(),
308+
a = count(),
309+
b = count(),
310+
c = count()
311+
),
301312
"1 2 4 5 3 6".to_string()
302313
);
303314
}
@@ -306,14 +317,9 @@ fn test_order() {
306317
fn test_once() {
307318
// Make sure each argument are evaluated only once even though it may be
308319
// formatted multiple times
309-
fn foo() -> isize {
310-
static mut FOO: isize = 0;
311-
unsafe {
312-
FOO += 1;
313-
FOO
314-
}
315-
}
316-
assert_eq!(format!("{0} {0} {0} {a} {a} {a}", foo(), a = foo()), "1 1 1 2 2 2".to_string());
320+
counter_fn!(count);
321+
322+
assert_eq!(format!("{0} {0} {0} {a} {a} {a}", count(), a = count()), "1 1 1 2 2 2".to_string());
317323
}
318324

319325
#[test]

0 commit comments

Comments
 (0)