Skip to content

Commit 2809c75

Browse files
committed
try to rewrite explicit trait impl as closure, same lifeimte issues.
This seems like a systematic issue with `lines()` that needs fixing.
1 parent 3f47ec3 commit 2809c75

File tree

1 file changed

+30
-48
lines changed

1 file changed

+30
-48
lines changed

src/index/diff/delegate.rs

Lines changed: 30 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -61,56 +61,38 @@ impl Delegate {
6161
Delete,
6262
Add,
6363
}
64-
type SinkOutput = Vec<Result<(CrateVersion, Op), Error>>;
65-
struct Sink<'a, 'b, 'c> {
66-
out: &'a mut SinkOutput,
67-
input: &'b git::diff::text::imara::intern::InternedInput<&'b [u8]>,
68-
location: &'c BStr,
69-
}
70-
71-
impl<'a, 'b, 'c> git::diff::text::imara::Sink for Sink<'a, 'b, 'c> {
72-
type Out = &'a mut SinkOutput;
73-
74-
fn process_change(&mut self, before: Range<u32>, after: Range<u32>) {
75-
let mut line_before = self.input.before
76-
[before.start as usize..before.end as usize]
77-
.iter()
78-
.map(|&line| self.input.interner[line]);
79-
let mut line_after = self.input.after
80-
[after.start as usize..after.end as usize]
81-
.iter()
82-
.map(|&line| self.input.interner[line]);
83-
match (line_before.next(), line_after.next()) {
84-
(Some(removed), None) => {
85-
self.out.push(
86-
version_from_json_line(removed.as_bstr(), self.location)
87-
.map(|v| (v, Op::Delete)),
88-
);
89-
}
90-
(None, Some(inserted)) => {
91-
self.out.push(
92-
version_from_json_line(inserted.as_bstr(), self.location)
93-
.map(|v| (v, Op::Add)),
94-
);
95-
}
96-
(Some(_), Some(_)) | (None, None) => {
97-
/* ignore modifications, shouldn't exist */
64+
diff.lines(
65+
|input: &git::diff::text::imara::intern::InternedInput<&[u8]>| {
66+
|before: Range<u32>, after: Range<u32>| {
67+
let mut line_before = input.before
68+
[before.start as usize..before.end as usize]
69+
.iter()
70+
.map(|&line| input.interner[line]);
71+
let mut line_after = input.after
72+
[after.start as usize..after.end as usize]
73+
.iter()
74+
.map(|&line| input.interner[line]);
75+
match (line_before.next(), line_after.next()) {
76+
(Some(removed), None) => {
77+
line_changes.push(
78+
version_from_json_line(removed.as_bstr(), location)
79+
.map(|v| (v, Op::Delete)),
80+
);
81+
}
82+
(None, Some(inserted)) => {
83+
line_changes.push(
84+
version_from_json_line(inserted.as_bstr(), location)
85+
.map(|v| (v, Op::Add)),
86+
);
87+
}
88+
(Some(_), Some(_)) | (None, None) => {
89+
/* ignore modifications, shouldn't exist */
90+
}
9891
}
9992
}
100-
}
101-
102-
fn finish(self) -> Self::Out {
103-
self.out
104-
}
105-
}
106-
107-
let sink =
108-
|input: &git::diff::text::imara::intern::InternedInput<&[u8]>| Sink {
109-
out: &mut line_changes,
110-
input,
111-
location,
112-
};
113-
for op in diff.lines(sink).drain(..) {
93+
},
94+
);
95+
for op in line_changes.drain(..) {
11496
let (version, op) = op?;
11597
match op {
11698
Op::Add => {

0 commit comments

Comments
 (0)