Skip to content

Commit

Permalink
Auto merge of #53755 - llogiq:fix-unsound-16bit-range, r=nagisa
Browse files Browse the repository at this point in the history
fix u32 steps_between for 16-bit systems

This fixes #48006.
  • Loading branch information
bors committed Aug 31, 2018
2 parents aaa170b + 9dab56c commit 571a624
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/libcore/iter/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,16 @@ macro_rules! step_impl_no_between {
)*)
}

step_impl_unsigned!(usize u8 u16 u32);
step_impl_signed!([isize: usize] [i8: u8] [i16: u16] [i32: u32]);
step_impl_unsigned!(usize u8 u16);
#[cfg(not(target_pointer_witdth = "16"))]
step_impl_unsigned!(u32);
#[cfg(target_pointer_witdth = "16")]
step_impl_no_between!(u32);
step_impl_signed!([isize: usize] [i8: u8] [i16: u16]);
#[cfg(not(target_pointer_witdth = "16"))]
step_impl_signed!([i32: u32]);
#[cfg(target_pointer_witdth = "16")]
step_impl_no_between!(i32);
#[cfg(target_pointer_width = "64")]
step_impl_unsigned!(u64);
#[cfg(target_pointer_width = "64")]
Expand Down
23 changes: 23 additions & 0 deletions src/test/run-pass/issue-48006.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(step_trait)]

use std::iter::Step;

#[cfg(target_pointer_width = "16")]
fn main() {
assert!(Step::steps_between(&0u32, &::std::u32::MAX).is_none());
}

#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))]
fn main() {
assert!(Step::steps_between(&0u32, &::std::u32::MAX).is_some());
}

0 comments on commit 571a624

Please sign in to comment.