Skip to content

Commit 571a624

Browse files
committed
Auto merge of #53755 - llogiq:fix-unsound-16bit-range, r=nagisa
fix u32 steps_between for 16-bit systems This fixes #48006.
2 parents aaa170b + 9dab56c commit 571a624

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

Diff for: src/libcore/iter/range.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,16 @@ macro_rules! step_impl_no_between {
165165
)*)
166166
}
167167

168-
step_impl_unsigned!(usize u8 u16 u32);
169-
step_impl_signed!([isize: usize] [i8: u8] [i16: u16] [i32: u32]);
168+
step_impl_unsigned!(usize u8 u16);
169+
#[cfg(not(target_pointer_witdth = "16"))]
170+
step_impl_unsigned!(u32);
171+
#[cfg(target_pointer_witdth = "16")]
172+
step_impl_no_between!(u32);
173+
step_impl_signed!([isize: usize] [i8: u8] [i16: u16]);
174+
#[cfg(not(target_pointer_witdth = "16"))]
175+
step_impl_signed!([i32: u32]);
176+
#[cfg(target_pointer_witdth = "16")]
177+
step_impl_no_between!(i32);
170178
#[cfg(target_pointer_width = "64")]
171179
step_impl_unsigned!(u64);
172180
#[cfg(target_pointer_width = "64")]

Diff for: src/test/run-pass/issue-48006.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(step_trait)]
12+
13+
use std::iter::Step;
14+
15+
#[cfg(target_pointer_width = "16")]
16+
fn main() {
17+
assert!(Step::steps_between(&0u32, &::std::u32::MAX).is_none());
18+
}
19+
20+
#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))]
21+
fn main() {
22+
assert!(Step::steps_between(&0u32, &::std::u32::MAX).is_some());
23+
}

0 commit comments

Comments
 (0)