about summary refs log tree commit diff
path: root/src/doc
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2015-05-11 19:58:57 +0530
committerManish Goregaokar <manishsmail@gmail.com>2015-05-11 19:58:57 +0530
commit1b8f52bb696e93f20d1bb5f719dc7c587f96733a (patch)
tree91f69da70ff999535f26b93ababe9ad9288f448a /src/doc
parentb0b6db6cb3970152cbb4a7a66b4e19cf8af3f33d (diff)
parent295b62dfb9ae53cb14518664ddaaf71348b20f18 (diff)
downloadrust-1b8f52bb696e93f20d1bb5f719dc7c587f96733a.tar.gz
rust-1b8f52bb696e93f20d1bb5f719dc7c587f96733a.zip
Rollup merge of #25286 - johannhof:patch-1, r=steveklabnik
The reference was claiming all vectors all bounds-checked at run-time, when constant vectors are usually checked at compile-time.

For the changed example see http://is.gd/28ak9E

Also fixed a minor grammar issue.
Diffstat (limited to 'src/doc')
-rw-r--r--src/doc/reference.md15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/doc/reference.md b/src/doc/reference.md
index 16fdcfa3013..fe5a6d9be49 100644
--- a/src/doc/reference.md
+++ b/src/doc/reference.md
@@ -842,7 +842,7 @@ module declarations should be at the crate root if direct usage of the declared
 modules within `use` items is desired. It is also possible to use `self` and
 `super` at the beginning of a `use` item to refer to the current and direct
 parent modules respectively. All rules regarding accessing declared modules in
-`use` declarations applies to both module declarations and `extern crate`
+`use` declarations apply to both module declarations and `extern crate`
 declarations.
 
 An example of what will and will not work for `use` items:
@@ -2564,12 +2564,19 @@ array is mutable, the resulting [lvalue](#lvalues,-rvalues-and-temporaries) can
 be assigned to.
 
 Indices are zero-based, and may be of any integral type. Vector access is
-bounds-checked at run-time. When the check fails, it will put the thread in a
-_panicked state_.
+bounds-checked at compile-time for constant arrays being accessed with a constant index value.
+Otherwise a check will be performed at run-time that will put the thread in a _panicked state_ if it fails.
 
 ```{should-fail}
 ([1, 2, 3, 4])[0];
-(["a", "b"])[10]; // panics
+
+let x = (["a", "b"])[10]; // compiler error: const index-expr is out of bounds
+
+let n = 10;
+let y = (["a", "b"])[n]; // panics
+
+let arr = ["a", "b"];
+arr[10]; // panics
 ```
 
 ### Range expressions