Skip to content

Commit e6b04c2

Browse files
committed
transpile: refactor out fn SrcLocInclude::cmp_iter
1 parent b100420 commit e6b04c2

File tree

1 file changed

+9
-5
lines changed
  • c2rust-transpile/src/c_ast

1 file changed

+9
-5
lines changed

c2rust-transpile/src/c_ast/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,17 @@ struct SrcLocInclude<'a> {
155155
include_path: &'a [SrcLoc],
156156
}
157157

158+
impl SrcLocInclude<'_> {
159+
fn cmp_iter<'a>(&'a self) -> impl Iterator<Item = SrcLoc> + 'a {
160+
// See docs on `Self` for why this is the right comparison.
161+
let Self { loc, include_path } = *self;
162+
include_path.iter().copied().chain([loc])
163+
}
164+
}
165+
158166
impl PartialOrd for SrcLocInclude<'_> {
159167
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
160-
let a = self;
161-
let b = other;
162-
let a = a.include_path.iter().copied().chain([a.loc]);
163-
let b = b.include_path.iter().copied().chain([b.loc]);
164-
Some(a.cmp(b))
168+
Some(self.cmp_iter().cmp(other.cmp_iter()))
165169
}
166170
}
167171

0 commit comments

Comments
 (0)