4 ms·
Checked array access is implemented with unsafe code. Actual code implementing the `[]` operator for arrays ("slices"): fn index(&self, &index: &uint) ->
by veddan 12y ago
Checked array access is implemented with unsafe code.
Actual code implementing the `[]` operator for arrays ("slices"):
fn index(&self, &index: &uint) -> &T {
assert!(index < self.len());
unsafe { mem::transmute(self.repr().data.offset(index as int)) }
}
By having `unsafe {}` it's possible to build low-level functionality as libraries rather than in the compiler. There no reason to think that code such as this would be less prone to bugs if it were hard-coded into the compiler. I'd be more inclined to believe the opposite.