chiark / gitweb /
wip
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 16 May 2019 00:39:28 +0000 (01:39 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 16 May 2019 00:39:28 +0000 (01:39 +0100)
.gitignore
Makefile
borrow-nonmut-error.txt [new file with mode: 0644]
borrow-nonmut.fig [new file with mode: 0644]
borrow-nonmut.txt [new file with mode: 0644]

index c31bfc59f61a1d851b71bb1302c682b20455b795..c48427e48ce50e715e173d59f0ee9a91f993e013 100644 (file)
@@ -3,6 +3,7 @@ mm0.ps
 mm.ps
 borrow-mut.ps
 dangling.ps
+borrow-nonmut.ps
 bck-lifetimes.ps
 macros.ps
 *.1
index f9a9c2ed0b17ae3b68be70a67012ee3e604627c7..b3a833c367fea6fe91588c3f86ab256e5db85303 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,7 @@ SLIDES+= mm0
 SLIDES+= mm
 SLIDES+= borrow-mut
 SLIDES+= dangling
+SLIDES+= borrow-nonmut
 
 SLIDES+= bck-lifetimes
 SLIDES+= macros
@@ -27,6 +28,7 @@ bck-lifetimes.ps: bck-err.txt.eps
 macros.ps: serde-example.txt.eps macro-rules-example.txt.eps
 borrow-mut.ps: borrow-mut-example.txt.eps
 dangling.ps: dangling.txt.eps dangling-err.txt.eps
+borrow-nonmut.ps: borrow-nonmut.txt.eps borrow-nonmut-error.txt.eps
 
 %.eps:   %.fig
        iconv <$< >$@.1 -f UTF-8 -t ISO-8859-1
diff --git a/borrow-nonmut-error.txt b/borrow-nonmut-error.txt
new file mode 100644 (file)
index 0000000..bf9f471
--- /dev/null
@@ -0,0 +1,9 @@
+error[E0596]: cannot borrow immutable borrowed content
+              `*some_string` as mutable
+ --> error.rs:8:5
+  |
+7 | fn change(some_string: &String) {
+  |                        ------- use `&mut String` here
+  |                                to make mutable
+8 |     some_string.push_str(", world");
+  |     ^^^^^^^^^^^ cannot borrow as mutable
diff --git a/borrow-nonmut.fig b/borrow-nonmut.fig
new file mode 100644 (file)
index 0000000..6c084d6
--- /dev/null
@@ -0,0 +1,17 @@
+#FIG 3.2  Produced by xfig version 3.2.6a
+Landscape
+Center
+Metric
+A4
+100.00
+Single
+-2
+1200 2
+2 1 0 2 0 7 50 -1 -1 0.000 0 0 7 0 0 2
+        -1260 1890 10800 1890
+2 5 0 1 0 -1 60 -1 -1 0.000 0 0 -1 0 0 5
+       0 borrow-nonmut.txt.eps
+        -1170 -2250 8177 -2250 8177 1625 -1170 1625 -1170 -2250
+2 5 0 1 0 -1 60 -1 -1 0.000 0 0 -1 0 0 5
+       0 borrow-nonmut-error.txt.eps
+        -1170 2155 10052 2155 10052 5080 -1170 5080 -1170 2155
diff --git a/borrow-nonmut.txt b/borrow-nonmut.txt
new file mode 100644 (file)
index 0000000..aafb0ac
--- /dev/null
@@ -0,0 +1,9 @@
+fn main() {
+    let s = String::from("hello");
+    change(&s);
+    println!("{}", s);
+}
+
+fn change(some_string: &String) {
+    some_string.push_str(", world");
+}