From 6ebdb06b7ab8fbf0f094d26a9c4c5788503137b0 Mon Sep 17 00:00:00 2001 From: Sancpp <67474179+sancppp@users.noreply.github.com> Date: Mon, 30 Oct 2023 08:12:19 -0500 Subject: [PATCH] Update ownership.md update error info --- src/basic/ownership/ownership.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/basic/ownership/ownership.md b/src/basic/ownership/ownership.md index f8355cdc..633af334 100644 --- a/src/basic/ownership/ownership.md +++ b/src/basic/ownership/ownership.md @@ -181,17 +181,24 @@ println!("{}, world!", s1); 由于 Rust 禁止你使用无效的引用,你会看到以下的错误: ```console -error[E0382]: use of moved value: `s1` +error[E0382]: borrow of moved value: `s1` --> 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; - | -- value moved here + | -- value moved here 4 | 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 - not implement the `Copy` trait + = 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) +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`. ``` 现在再回头看看之前的规则,相信大家已经有了更深刻的理解: