I'm creating a Sieve of Eratosthenes so I can see all the prime numbers up to the starting number. Just the following code causes a core dump on Rust 1.26. There are no compiler warnings or errors, and the core dump isn't very helpful either with no error message.
fn main() {
let starting_number: i64 = 600851475143;
let mut primes = vec![true; 600851475143];
primes[0] = false;
primes[1] = false;
for i in 2..((starting_number as f64).ln() as usize) {
if primes[i] {
let mut j = i + i;
while j < primes.len() {
primes[j] = false;
j += i;
}
}
}
}
I thought Rust was all about safety and avoiding core dumps? Is this a legit error with my code which isn't caught by the compiler or something different?