Browser Games | Cybiko | Amiga | Applications | Windows Games | Java Area | Test Area | Guides | Site Map

Out Of Bounds - Rust


This is part of a series testing each of the languages I use to see how good they are at catching simple array out of bounds errors.

These tests check for the following:

The Code

The following was compiled using Rustc 1.32 :

fn main() {
	let pa=3;
	let pb=4;
	let mut array=[1,2,3];
	// #1. Simple so should be an easy catch - CT: CAUGHT
	// #2. This is an immutable variable so should also be an easy catch - CT: FAILED

	// #3. Same as above, left in for completeness - CT: FAILED

	// #4. Looping through array - CT: FAILED
	for i in 0..5

Test 1 - Default Settings

By default checks are on so this is the only test. Despite being heavily focused on safety, the compiler only picked up error #1.

With #1 commented out, running the above does give a 'index out of bounds' errors.


Really expected Rust to do much better in this given the Rust's focus on safety.