Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 27869c5

Browse files
committed
rls-span: Fix nightly breakage
1 parent 2f17cf7 commit 27869c5

File tree

1 file changed

+22
-114
lines changed

1 file changed

+22
-114
lines changed

rls-span/src/lib.rs

Lines changed: 22 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg_attr(feature = "nightly", feature(step_trait))]
1+
#![cfg_attr(feature = "nightly", feature(step_trait, step_trait_ext))]
22

33
#[cfg(feature = "derive")]
44
#[macro_use]
@@ -9,8 +9,6 @@ use serde::{Deserialize, Serialize};
99
use std::marker::PhantomData;
1010
use std::path::PathBuf;
1111

12-
#[cfg(feature = "nightly")]
13-
use std::convert::TryFrom;
1412
#[cfg(feature = "nightly")]
1513
use std::iter::Step;
1614

@@ -86,62 +84,30 @@ impl Column<ZeroIndexed> {
8684
}
8785

8886
#[cfg(feature = "nightly")]
89-
impl Step for Column<ZeroIndexed> {
90-
fn steps_between(start: &Self, end: &Self) -> Option<usize> {
91-
<u32 as Step>::steps_between(&start.0, &end.0)
92-
}
93-
94-
fn replace_one(&mut self) -> Self {
95-
self.0 = 1;
96-
self.clone()
97-
}
98-
99-
fn replace_zero(&mut self) -> Self {
100-
self.0 = 0;
101-
self.clone()
102-
}
103-
104-
fn add_one(&self) -> Self {
105-
Self::new(self.0 + 1)
106-
}
107-
108-
fn sub_one(&self) -> Self {
109-
Self::new(self.0 - 1)
110-
}
111-
112-
fn add_usize(&self, n: usize) -> Option<Self> {
113-
(self.0 as usize).checked_add(n).and_then(|n| u32::try_from(n).ok()).map(Self::new)
114-
}
87+
macro_rules! impl_step {
88+
($target: ty) => {
89+
unsafe impl Step for $target {
90+
fn steps_between(start: &Self, end: &Self) -> Option<usize> {
91+
Step::steps_between(&start.0, &end.0)
92+
}
93+
fn forward_checked(arg: Self, count: usize) -> Option<Self> {
94+
Step::forward_checked(arg.0, count).map(|x| Self(x, PhantomData))
95+
}
96+
fn backward_checked(arg: Self, count: usize) -> Option<Self> {
97+
Step::backward_checked(arg.0, count).map(|x| Self(x, PhantomData))
98+
}
99+
}
100+
};
115101
}
116102

117103
#[cfg(feature = "nightly")]
118-
impl Step for Column<OneIndexed> {
119-
fn steps_between(start: &Self, end: &Self) -> Option<usize> {
120-
<u32 as Step>::steps_between(&start.0, &end.0)
121-
}
122-
123-
fn replace_one(&mut self) -> Self {
124-
self.0 = 2;
125-
self.clone()
126-
}
127-
128-
fn replace_zero(&mut self) -> Self {
129-
self.0 = 1;
130-
self.clone()
131-
}
132-
133-
fn add_one(&self) -> Self {
134-
Self::new(self.0 + 1)
135-
}
136-
137-
fn sub_one(&self) -> Self {
138-
Self::new(self.0 - 1)
139-
}
140-
141-
fn add_usize(&self, n: usize) -> Option<Self> {
142-
(self.0 as usize).checked_add(n).and_then(|n| u32::try_from(n).ok()).map(Self::new)
143-
}
144-
}
104+
impl_step!(Column<ZeroIndexed>);
105+
#[cfg(feature = "nightly")]
106+
impl_step!(Column<OneIndexed>);
107+
#[cfg(feature = "nightly")]
108+
impl_step!(Row<ZeroIndexed>);
109+
#[cfg(feature = "nightly")]
110+
impl_step!(Row<OneIndexed>);
145111

146112
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
147113
pub struct Row<I: Indexed>(pub u32, PhantomData<I>);
@@ -206,64 +172,6 @@ impl Row<ZeroIndexed> {
206172
}
207173
}
208174

209-
#[cfg(feature = "nightly")]
210-
impl Step for Row<ZeroIndexed> {
211-
fn steps_between(start: &Self, end: &Self) -> Option<usize> {
212-
<u32 as Step>::steps_between(&start.0, &end.0)
213-
}
214-
215-
fn replace_one(&mut self) -> Self {
216-
self.0 = 1;
217-
self.clone()
218-
}
219-
220-
fn replace_zero(&mut self) -> Self {
221-
self.0 = 0;
222-
self.clone()
223-
}
224-
225-
fn add_one(&self) -> Self {
226-
Self::new(self.0 + 1)
227-
}
228-
229-
fn sub_one(&self) -> Self {
230-
Self::new(self.0 - 1)
231-
}
232-
233-
fn add_usize(&self, n: usize) -> Option<Self> {
234-
(self.0 as usize).checked_add(n).and_then(|n| u32::try_from(n).ok()).map(Self::new)
235-
}
236-
}
237-
238-
#[cfg(feature = "nightly")]
239-
impl Step for Row<OneIndexed> {
240-
fn steps_between(start: &Self, end: &Self) -> Option<usize> {
241-
<u32 as Step>::steps_between(&start.0, &end.0)
242-
}
243-
244-
fn replace_one(&mut self) -> Self {
245-
self.0 = 2;
246-
self.clone()
247-
}
248-
249-
fn replace_zero(&mut self) -> Self {
250-
self.0 = 1;
251-
self.clone()
252-
}
253-
254-
fn add_one(&self) -> Self {
255-
Self::new(self.0 + 1)
256-
}
257-
258-
fn sub_one(&self) -> Self {
259-
Self::new(self.0 - 1)
260-
}
261-
262-
fn add_usize(&self, n: usize) -> Option<Self> {
263-
(self.0 as usize).checked_add(n).and_then(|n| u32::try_from(n).ok()).map(Self::new)
264-
}
265-
}
266-
267175
#[cfg_attr(feature = "derive", derive(Serialize, Deserialize))]
268176
#[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
269177
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]

0 commit comments

Comments
 (0)