Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a patcher panic #341

Merged
merged 1 commit into from Feb 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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