From ad0fcf33a5b22c303b5fb4b3da67919008f1e17a Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 25 Aug 2016 16:37:43 -0400 Subject: [PATCH] It's not always possible to handle this at compile time --- src/ch07-02-unrecoverable-errors-with-panic.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ch07-02-unrecoverable-errors-with-panic.md b/src/ch07-02-unrecoverable-errors-with-panic.md index c966eea..c690808 100644 --- a/src/ch07-02-unrecoverable-errors-with-panic.md +++ b/src/ch07-02-unrecoverable-errors-with-panic.md @@ -41,8 +41,11 @@ fn main() { We attempt to access the hundredth element of our vector, but it only has three elements. In this situation, Rust will panic. Using `[]` is supposed to return a number. But if you pass it an invalid index, there's no number Rust could -return here, it would be wrong. So the only thing that we can do is terminate -the program. +return here, it would be wrong. In this case, we've typed in a literal, so in +theory, Rust could figure it out. But if our program was different, say, maybe +reading the index from user input, it would not be possible to determine at +compile time if the index was in bounds. So the only thing that we can do is +terminate the program. Let's try to run it: