2022-02-06 16:43:51 +08:00
|
|
|
$ cargo run
|
|
|
|
Compiling ownership v0.1.0 (file:///projects/ownership)
|
|
|
|
error[E0502]: cannot borrow `s` as mutable because it is also borrowed as immutable
|
|
|
|
--> src/main.rs:18:5
|
|
|
|
|
|
|
|
|
16 | let word = first_word(&s);
|
|
|
|
| -- immutable borrow occurs here
|
2023-01-16 17:34:52 +08:00
|
|
|
17 |
|
2022-02-06 16:43:51 +08:00
|
|
|
18 | s.clear(); // error!
|
|
|
|
| ^^^^^^^^^ mutable borrow occurs here
|
2023-01-16 17:34:52 +08:00
|
|
|
19 |
|
2022-02-06 16:43:51 +08:00
|
|
|
20 | println!("the first word is: {}", word);
|
|
|
|
| ---- immutable borrow later used here
|
|
|
|
|
|
|
|
For more information about this error, try `rustc --explain E0502`.
|
|
|
|
error: could not compile `ownership` due to previous error
|