summaryrefslogtreecommitdiffstats
path: root/src/doc/book/listings/ch04-understanding-ownership/listing-04-06
diff options
context:
space:
mode:
Diffstat (limited to 'src/doc/book/listings/ch04-understanding-ownership/listing-04-06')
-rw-r--r--src/doc/book/listings/ch04-understanding-ownership/listing-04-06/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch04-understanding-ownership/listing-04-06/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch04-understanding-ownership/listing-04-06/output.txt12
-rw-r--r--src/doc/book/listings/ch04-understanding-ownership/listing-04-06/src/main.rs9
4 files changed, 33 insertions, 0 deletions
diff --git a/src/doc/book/listings/ch04-understanding-ownership/listing-04-06/Cargo.lock b/src/doc/book/listings/ch04-understanding-ownership/listing-04-06/Cargo.lock
new file mode 100644
index 000000000..2aa4918e5
--- /dev/null
+++ b/src/doc/book/listings/ch04-understanding-ownership/listing-04-06/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "ownership"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch04-understanding-ownership/listing-04-06/Cargo.toml b/src/doc/book/listings/ch04-understanding-ownership/listing-04-06/Cargo.toml
new file mode 100644
index 000000000..e8847526d
--- /dev/null
+++ b/src/doc/book/listings/ch04-understanding-ownership/listing-04-06/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "ownership"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch04-understanding-ownership/listing-04-06/output.txt b/src/doc/book/listings/ch04-understanding-ownership/listing-04-06/output.txt
new file mode 100644
index 000000000..1176f4e3a
--- /dev/null
+++ b/src/doc/book/listings/ch04-understanding-ownership/listing-04-06/output.txt
@@ -0,0 +1,12 @@
+$ cargo run
+ Compiling ownership v0.1.0 (file:///projects/ownership)
+error[E0596]: cannot borrow `*some_string` as mutable, as it is behind a `&` reference
+ --> src/main.rs:8:5
+ |
+7 | fn change(some_string: &String) {
+ | ------- help: consider changing this to be a mutable reference: `&mut String`
+8 | some_string.push_str(", world");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `some_string` is a `&` reference, so the data it refers to cannot be borrowed as mutable
+
+For more information about this error, try `rustc --explain E0596`.
+error: could not compile `ownership` due to previous error
diff --git a/src/doc/book/listings/ch04-understanding-ownership/listing-04-06/src/main.rs b/src/doc/book/listings/ch04-understanding-ownership/listing-04-06/src/main.rs
new file mode 100644
index 000000000..330ffa68a
--- /dev/null
+++ b/src/doc/book/listings/ch04-understanding-ownership/listing-04-06/src/main.rs
@@ -0,0 +1,9 @@
+fn main() {
+ let s = String::from("hello");
+
+ change(&s);
+}
+
+fn change(some_string: &String) {
+ some_string.push_str(", world");
+}