SSJX.CO.UK
Browser Games | Cybiko | Amiga | Applications | Windows Games | Java Area | Test Area | Guides | Site Map

Out Of Bounds - Rust

Introduction

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
	array[3]=97;
	
	// #2. This is an immutable variable so should also be an easy catch - CT: FAILED
	array[pa]=98;

	// #3. Same as above, left in for completeness - CT: FAILED
	array[pb]=99;

	// #4. Looping through array - CT: FAILED
	for i in 0..5
	{
		println!("{}",array[i]);
	}
}

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.

Summary

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

11/01/20