Skip to content

Commit ccac41b

Browse files
authored
Prevent rustfmt from messing with verusfmt (#38)
Rustfmt messes with verusfmt's formatting, and this has been the cause of idempotency issues such as #33 and #36. With this PR, we close that out (hopefully) entirely. In short, we add a new (minimal) parser that collapses any `verus!{ ... }` into `verus!{}` before passing it to rustfmt; upon getting a result from rustfmt, we expand out those `verus!{}` to `verus!{ ... }` again, thereby preventing rustfmt from messing with anything inside the body that we have carefully set up already. This also allows us to enable the NR snapshot test, which is now stable. Fwiw, we could have fixed NR's non-idempotency if we could pass multiple macros to `rustfmt`'s `skip_macro_invocations` config; however, that is blocked on an issue in rustfmt: rust-lang/rustfmt#6097; even once that is fixed, we would need to assume/check that the user is on recent-enough rustfmt (also it turns out that `skip_macro_invocations` is not stable on rustfmt), so the fix that this PR does is a much more manageable fix for us overall. Additionally, this PR also adds in vstd as a snapshot test (which could not be added before, due to same idempotency issue). Fixes #36
2 parents af5db34 + 5833f1c commit ccac41b

File tree

10 files changed

+26269
-5510
lines changed

10 files changed

+26269
-5510
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Unreleased
22

33
* When running verusfmt on multiple files, continue attempting files even if one in the middle fails
4+
* Fix idempotency issue of `verus!` macro inside a `macro_rules!` definition
45

56
# v0.2.5
67

examples/ironfleet.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub enum AppReply {
9191
}
9292

9393
} // verus!
94-
// verus
94+
// verus
9595
}
9696

9797
mod app_interface_t {
@@ -2682,7 +2682,7 @@ impl DelegationMap<CKey> {
26822682
}
26832683

26842684
} // verus!
2685-
// end verus!
2685+
// end verus!
26862686
}
26872687

26882688
mod endpoint_hashmap_t {
@@ -2901,7 +2901,7 @@ pub open spec fn is_valid_lio_op<IdType, MessageType>(
29012901
// LIoOpSeqCompatibleWithReduction
29022902

29032903
} // verus!
2904-
// verus
2904+
// verus
29052905
}
29062906

29072907
mod hashmap_t {
@@ -7113,7 +7113,7 @@ pub fn sht_main(netc: NetClient, args: Args) -> Result<(), IronError>
71137113
}
71147114

71157115
} // verus!
7116-
// verus
7116+
// verus
71177117
}
71187118

71197119
mod marshal_ironsht_specific_v {
@@ -11651,7 +11651,7 @@ pub proof fn choose_smallest(low: int, high: int, p: FnSpec(int) -> bool) -> (re
1165111651
}
1165211652

1165311653
} // verus!
11654-
}
11654+
}
1165511655

1165611656
pub mod clone_v {
1165711657
use vstd::prelude::*;
@@ -11667,7 +11667,7 @@ pub trait VerusClone: Sized {
1166711667
}
1166811668

1166911669
} // verus!
11670-
}
11670+
}
1167111671

1167211672
pub mod seq_lib_v {
1167311673
use builtin::*;
@@ -12002,7 +12002,7 @@ pub proof fn some_differing_index_for_unequal_seqs<A>(s1: Seq<A>, s2: Seq<A>) ->
1200212002
}
1200312003

1200412004
} // verus!
12005-
}
12005+
}
1200612006

1200712007
pub mod set_lib_ext_v {
1200812008
use builtin::*;
@@ -12343,7 +12343,7 @@ pub proof fn flatten_sets_singleton_auto<A>()
1234312343
// lemmas somewhere, but it's not easy to see from the profiler yet.
1234412344

1234512345
} // verus!
12346-
}
12346+
}
1234712347
}
1234812348
// TODO: maybe move into Verus?
1234912349

0 commit comments

Comments
 (0)