-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Closed
Copy link
Labels
A-parserparser issuesparser issuesC-bugCategory: bugCategory: bugS-actionableSomeone could pick this issue up and work on it right nowSomeone could pick this issue up and work on it right now
Description
Here is the sample code:
fn collatz(n: u64) -> Option<u64> {
const OVERFLOW_BARRIER: u64 = u64::MAX / 3;
let mut n = n;
for i in 0.. {
n = match (n, n % 2) {
(0, _) => break,
(1, _) => return Some(i),
(OVERFLOW_BARRIER.., 1) => 0, // <- Errors out here.
(_, 0) => n / 2,
_ => n * 3 + 1,
}
}
None
}Changing OVERFLOW_BARRIER.. to OVERFLOW_BARRIER..=u64::MAX seems to work.
But changing placement of match tuple works just fine:
pub fn collatz(n: u64) -> Option<u64> {
const OVERFLOW_BARRIER: u64 = u64::MAX / 3;
let mut n = n;
for i in 0.. {
n = match (n % 2, n) {
(_, 0) => break,
(_, 1) => return Some(i),
(1, OVERFLOW_BARRIER..) => 0, // Detects no error.
(0, _) => n / 2,
_ => n * 3 + 1,
}
}
None
}But Rust compiler doesn't detect any error. It compiles just fine.
Metadata
Metadata
Assignees
Labels
A-parserparser issuesparser issuesC-bugCategory: bugCategory: bugS-actionableSomeone could pick this issue up and work on it right nowSomeone could pick this issue up and work on it right now