Skip to content

Commit 96a77ac

Browse files
committed
fix signature of Step::steps_between implementations
A recent nightly changed the signature of Step::steps_between to match the signature of Iterator::size_hint. This patch changes our implementations to match the new signature.
1 parent e016a4c commit 96a77ac

File tree

4 files changed

+33
-20
lines changed

4 files changed

+33
-20
lines changed

src/addr.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,18 @@ impl VirtAddr {
241241

242242
// FIXME: Move this into the `Step` impl, once `Step` is stabilized.
243243
#[cfg(any(feature = "instructions", feature = "step_trait"))]
244-
pub(crate) fn steps_between_impl(start: &Self, end: &Self) -> Option<usize> {
245-
let mut steps = end.0.checked_sub(start.0)?;
244+
pub(crate) fn steps_between_impl(start: &Self, end: &Self) -> (usize, Option<usize>) {
245+
let mut steps = if let Some(steps) = end.0.checked_sub(start.0) {
246+
steps
247+
} else {
248+
return (0, None);
249+
};
246250

247251
// Mask away extra bits that appear while jumping the gap.
248252
steps &= 0xffff_ffff_ffff;
249253

250-
usize::try_from(steps).ok()
254+
let steps = usize::try_from(steps).ok();
255+
(steps.unwrap_or(!0), steps)
251256
}
252257

253258
// FIXME: Move this into the `Step` impl, once `Step` is stabilized.
@@ -360,7 +365,7 @@ impl Sub<VirtAddr> for VirtAddr {
360365
#[cfg(feature = "step_trait")]
361366
impl Step for VirtAddr {
362367
#[inline]
363-
fn steps_between(start: &Self, end: &Self) -> Option<usize> {
368+
fn steps_between(start: &Self, end: &Self) -> (usize, Option<usize>) {
364369
Self::steps_between_impl(start, end)
365370
}
366371

@@ -721,43 +726,49 @@ mod tests {
721726
#[test]
722727
#[cfg(feature = "step_trait")]
723728
fn virtaddr_steps_between() {
724-
assert_eq!(Step::steps_between(&VirtAddr(0), &VirtAddr(0)), Some(0));
725-
assert_eq!(Step::steps_between(&VirtAddr(0), &VirtAddr(1)), Some(1));
726-
assert_eq!(Step::steps_between(&VirtAddr(1), &VirtAddr(0)), None);
729+
assert_eq!(
730+
Step::steps_between(&VirtAddr(0), &VirtAddr(0)),
731+
(0, Some(0))
732+
);
733+
assert_eq!(
734+
Step::steps_between(&VirtAddr(0), &VirtAddr(1)),
735+
(1, Some(1))
736+
);
737+
assert_eq!(Step::steps_between(&VirtAddr(1), &VirtAddr(0)), (0, None));
727738
assert_eq!(
728739
Step::steps_between(
729740
&VirtAddr(0x7fff_ffff_ffff),
730741
&VirtAddr(0xffff_8000_0000_0000)
731742
),
732-
Some(1)
743+
(1, Some(1))
733744
);
734745
assert_eq!(
735746
Step::steps_between(
736747
&VirtAddr(0xffff_8000_0000_0000),
737748
&VirtAddr(0x7fff_ffff_ffff)
738749
),
739-
None
750+
(0, None)
740751
);
741752
assert_eq!(
742753
Step::steps_between(
743754
&VirtAddr(0xffff_8000_0000_0000),
744755
&VirtAddr(0xffff_8000_0000_0000)
745756
),
746-
Some(0)
757+
(0, Some(0))
747758
);
748759
assert_eq!(
749760
Step::steps_between(
750761
&VirtAddr(0xffff_8000_0000_0000),
751762
&VirtAddr(0xffff_8000_0000_0001)
752763
),
753-
Some(1)
764+
(1, Some(1))
754765
);
755766
assert_eq!(
756767
Step::steps_between(
757768
&VirtAddr(0xffff_8000_0000_0001),
758769
&VirtAddr(0xffff_8000_0000_0000)
759770
),
760-
None
771+
(0, None)
761772
);
762773
}
763774

src/instructions/tlb.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,14 @@ where
315315
if let Some(mut pages) = self.page_range {
316316
while !pages.is_empty() {
317317
// Calculate out how many pages we still need to flush.
318-
let count = Page::<S>::steps_between_impl(&pages.start, &pages.end).unwrap();
318+
let count = Page::<S>::steps_between_impl(&pages.start, &pages.end).0;
319319

320320
// Make sure that we never jump the gap in the address space when flushing.
321321
let second_half_start =
322322
Page::<S>::containing_address(VirtAddr::new(0xffff_8000_0000_0000));
323323
let count = if pages.start < second_half_start {
324324
let count_to_second_half =
325-
Page::steps_between_impl(&pages.start, &second_half_start).unwrap();
325+
Page::steps_between_impl(&pages.start, &second_half_start).0;
326326
cmp::min(count, count_to_second_half)
327327
} else {
328328
count

src/structures/paging/page.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,11 @@ impl<S: PageSize> Page<S> {
160160

161161
// FIXME: Move this into the `Step` impl, once `Step` is stabilized.
162162
#[cfg(any(feature = "instructions", feature = "step_trait"))]
163-
pub(crate) fn steps_between_impl(start: &Self, end: &Self) -> Option<usize> {
164-
VirtAddr::steps_between_impl(&start.start_address, &end.start_address)
165-
.map(|steps| steps / S::SIZE as usize)
163+
pub(crate) fn steps_between_impl(start: &Self, end: &Self) -> (usize, Option<usize>) {
164+
let (lower, upper) = VirtAddr::steps_between_impl(&start.start_address, &end.start_address);
165+
let lower = lower / S::SIZE as usize;
166+
let upper = upper.map(|steps| steps / S::SIZE as usize);
167+
(lower, upper)
166168
}
167169

168170
// FIXME: Move this into the `Step` impl, once `Step` is stabilized.
@@ -293,7 +295,7 @@ impl<S: PageSize> Sub<Self> for Page<S> {
293295

294296
#[cfg(feature = "step_trait")]
295297
impl<S: PageSize> Step for Page<S> {
296-
fn steps_between(start: &Self, end: &Self) -> Option<usize> {
298+
fn steps_between(start: &Self, end: &Self) -> (usize, Option<usize>) {
297299
Self::steps_between_impl(start, end)
298300
}
299301

src/structures/paging/page_table.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ impl From<PageTableIndex> for usize {
353353
#[cfg(feature = "step_trait")]
354354
impl Step for PageTableIndex {
355355
#[inline]
356-
fn steps_between(start: &Self, end: &Self) -> Option<usize> {
357-
end.0.checked_sub(start.0).map(usize::from)
356+
fn steps_between(start: &Self, end: &Self) -> (usize, Option<usize>) {
357+
Step::steps_between(&start.0, &end.0)
358358
}
359359

360360
#[inline]

0 commit comments

Comments
 (0)