Only eval args once

This commit is contained in:
nora 2022-10-02 12:02:59 +02:00
parent 58e90857d2
commit b5f6318fce
No known key found for this signature in database
3 changed files with 65 additions and 15 deletions

View file

@ -1,3 +1,5 @@
use std::cell::Cell;
#[macro_use]
extern crate mono_fmt;
@ -17,3 +19,13 @@ fn test_pointer_formats_data_pointer() {
assert_eq!(format!("{s:p}"), format!("{:p}", s.as_ptr()));
assert_eq!(format!("{b:p}"), format!("{:p}", b.as_ptr()));
}
#[test]
fn only_eval_once() {
let evil = Cell::new(0);
let _ = format!("{0} {0}", {
evil.set(evil.get() + 1);
0
});
assert_eq!(evil.get(), 1);
}