Update ownership.md

update error info
pull/1320/head
Sancpp 1 year ago committed by GitHub
parent 13f9efacd3
commit 6ebdb06b7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -181,17 +181,24 @@ println!("{}, world!", s1);
由于 Rust 禁止你使用无效的引用,你会看到以下的错误: 由于 Rust 禁止你使用无效的引用,你会看到以下的错误:
```console ```console
error[E0382]: use of moved value: `s1` error[E0382]: borrow of moved value: `s1`
--> src/main.rs:5:28 --> src/main.rs:5:28
| |
2 | let s1 = String::from("hello");
| -- move occurs because `s1` has type `String`, which does not implement the `Copy` trait
3 | let s2 = s1; 3 | let s2 = s1;
| -- value moved here | -- value moved here
4 | 4 |
5 | println!("{}, world!", s1); 5 | println!("{}, world!", s1);
| ^^ value used here after move | ^^ value borrowed here after move
| |
= note: move occurs because `s1` has type `std::string::String`, which does = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
not implement the `Copy` trait help: consider cloning the value if the performance cost is acceptable
|
3 | let s2 = s1.clone();
| ++++++++
For more information about this error, try `rustc --explain E0382`.
``` ```
现在再回头看看之前的规则,相信大家已经有了更深刻的理解: 现在再回头看看之前的规则,相信大家已经有了更深刻的理解:

Loading…
Cancel
Save