Skip to content

Commit f174547

Browse files
committed
Mark the StepBy specialization as unsafe
1 parent 8a72f35 commit f174547

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

library/core/src/iter/adapters/step_by.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,15 @@ impl<T> SpecRangeSetup<T> for T {
141141

142142
/// Specialization trait to optimize `StepBy<Range<{integer}>>` iteration.
143143
///
144-
/// # Correctness
144+
/// # Safety
145145
///
146146
/// Technically this is safe to implement (look ma, no unsafe!), but in reality
147147
/// a lot of unsafe code relies on ranges over integers being correct.
148148
///
149149
/// For correctness *all* public StepBy methods must be specialized
150150
/// because `setup` drastically alters the meaning of the struct fields so that mixing
151151
/// different implementations would lead to incorrect results.
152-
trait StepByImpl<I> {
152+
unsafe trait StepByImpl<I> {
153153
type Item;
154154

155155
fn spec_next(&mut self) -> Option<Self::Item>;
@@ -172,13 +172,13 @@ trait StepByImpl<I> {
172172
///
173173
/// See also: `StepByImpl`
174174
///
175-
/// # Correctness
175+
/// # Safety
176176
///
177177
/// The specializations must be implemented together with `StepByImpl`
178178
/// where applicable. I.e. if `StepBy` does support backwards iteration
179179
/// for a given iterator and that is specialized for forward iteration then
180180
/// it must also be specialized for backwards iteration.
181-
trait StepByBackImpl<I> {
181+
unsafe trait StepByBackImpl<I> {
182182
type Item;
183183

184184
fn spec_next_back(&mut self) -> Option<Self::Item>
@@ -201,7 +201,7 @@ trait StepByBackImpl<I> {
201201
F: FnMut(Acc, Self::Item) -> Acc;
202202
}
203203

204-
impl<I: Iterator> StepByImpl<I> for StepBy<I> {
204+
unsafe impl<I: Iterator> StepByImpl<I> for StepBy<I> {
205205
type Item = I::Item;
206206

207207
#[inline]
@@ -319,7 +319,7 @@ impl<I: Iterator> StepByImpl<I> for StepBy<I> {
319319
}
320320
}
321321

322-
impl<I: DoubleEndedIterator + ExactSizeIterator> StepByBackImpl<I> for StepBy<I> {
322+
unsafe impl<I: DoubleEndedIterator + ExactSizeIterator> StepByBackImpl<I> for StepBy<I> {
323323
type Item = I::Item;
324324

325325
#[inline]
@@ -416,7 +416,7 @@ macro_rules! spec_int_ranges {
416416
}
417417
}
418418

419-
impl StepByImpl<Range<$t>> for StepBy<Range<$t>> {
419+
unsafe impl StepByImpl<Range<$t>> for StepBy<Range<$t>> {
420420
#[inline]
421421
fn spec_next(&mut self) -> Option<$t> {
422422
// if a step size larger than the type has been specified fall back to
@@ -497,7 +497,7 @@ macro_rules! spec_int_ranges_r {
497497
($($t:ty)*) => ($(
498498
const _: () = assert!(usize::BITS >= <$t>::BITS);
499499

500-
impl StepByBackImpl<Range<$t>> for StepBy<Range<$t>> {
500+
unsafe impl StepByBackImpl<Range<$t>> for StepBy<Range<$t>> {
501501

502502
#[inline]
503503
fn spec_next_back(&mut self) -> Option<Self::Item>

0 commit comments

Comments
 (0)