Skip to content

Commit

Permalink
Fix a patcher panic (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Feb 1, 2023
1 parent 08a9ec3 commit 7b5a7f8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cargo-insta/src/inline.rs
Expand Up @@ -57,10 +57,18 @@ impl FilePatcher {
pub fn add_snapshot_macro(&mut self, line: usize) -> bool {
match self.find_snapshot_macro(line) {
Some(snapshot) => {
assert!(self
// this can happen if multiple snapshots were added in one
// iteration of a loop. In that case we want to ignore the
// duplicate
//
// See https://github.com/mitsuhiko/insta/issues/340
if self
.inline_snapshots
.last()
.map_or(true, |x| x.end.0 <= line));
.map_or(false, |x| x.end.0 > line)
{
return false;
}
self.inline_snapshots.push(snapshot);
true
}
Expand Down

0 comments on commit 7b5a7f8

Please sign in to comment.