- /* println!("The first element is: {}", *first); */
-}
-// `&mut` is the operator to create a mutable borrow. We have to mark `v` as mutable in order
-// to create such a borrow. Because the borrow passed to `vec_inc` only lasts as
-// long as the function call, we can still call `vec_inc` on the same vector twice:
-// The durations of the two borrows do not overlap, so we never have more than one mutable borrow.
-// However, we can *not* create a shared borrow that spans a call to `vec_inc`. Just try
-// enabling the commented-out lines. This is because `vec_inc` could mutate the vector structurally
-// (i.e., it could add or remove elements), and hence the pointer `first` could become invalid.
-//
-// Above, I said that having a mutable borrow excludes aliasing. But if you look at the code above carefully,
-// you may say: "Wait! Don't the `v` in `foo3` and the `v` in `vec_inc` alias?" And you are right,
-// they do. However, the `v` in `foo3` is not actually usable, it is not *active*: As long as there is an
-// outstanding borrow, Rust will not allow you to do anything with `v`. This is, in fact, what
-// prevents the creation of a mutable borrow when there already is a shared one.
-
-// This also works the other way around: In `foo4`, there is already a mutable borrow active in the `vec_min`
-// line, so the attempt to create another shared borrow is rejected by the compiler.
-fn foo4() {
- let mut v = vec![5,4,3,2,1];
- let first = &mut v[0];
- /* vec_min(&v); */
- println!("The first element is: {}", *first);