mirror of
https://github.com/rust-lang-cn/book-cn.git
synced 2025-02-02 23:38:41 +08:00
21 lines
700 B
Plaintext
21 lines
700 B
Plaintext
$ 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
|
|
17 |
|
|
18 | s.clear(); // error!
|
|
| ^^^^^^^^^ mutable borrow occurs here
|
|
19 |
|
|
20 | println!("the first word is: {}", word);
|
|
| ---- immutable borrow later used here
|
|
|
|
error: aborting due to previous error
|
|
|
|
For more information about this error, try `rustc --explain E0502`.
|
|
error: could not compile `ownership`
|
|
|
|
To learn more, run the command again with --verbose.
|