Skip to content

Commit 8a72f35

Browse files
committed
StepBy<Range<{int <= usize}>> can be TrustedLen
1 parent f70a4b9 commit 8a72f35

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::convert::TryFrom;
22
use crate::{
33
intrinsics,
4-
iter::from_fn,
4+
iter::{from_fn, TrustedLen},
55
ops::{Range, Try},
66
};
77

@@ -484,6 +484,12 @@ macro_rules! spec_int_ranges {
484484
acc
485485
}
486486
}
487+
488+
/// Safety: This macro is only applied to ranges over types <= usize
489+
/// which means the inner length is guaranteed to fit into a usize and so
490+
/// the outer length calculation won't encounter clamped values
491+
#[unstable(feature = "trusted_len", issue = "37572")]
492+
unsafe impl TrustedLen for StepBy<Range<$t>> {}
487493
)*)
488494
}
489495

0 commit comments

Comments
 (0)