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

index 61f2093a48ee17154f40d3ae260f62919b0a23d3..c31bfc59f61a1d851b71bb1302c682b20455b795 100644 (file)
@@ -1,6 +1,8 @@
 intro.ps
 mm0.ps
 mm.ps
+borrow-mut.ps
+dangling.ps
 bck-lifetimes.ps
 macros.ps
 *.1
index 07b1dcf935b29ca21a3ac8ff2408c3bf6b6f24a6..eeb8936fec18a4947f86e661b759b840147567db 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,6 +2,8 @@
 SLIDES+= intro
 SLIDES+= mm0
 SLIDES+= mm
+SLIDES+= borrow-mut
+SLIDES+= dangling
 
 SLIDES+= bck-lifetimes
 SLIDES+= macros
@@ -23,6 +25,8 @@ mm0.ps: mm.fig
 
 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
 
 %.eps:   %.fig
        iconv <$< >$@.1 -f UTF-8 -t ISO-8859-1
diff --git a/borrow-mut-example.txt b/borrow-mut-example.txt
new file mode 100644 (file)
index 0000000..9789164
--- /dev/null
@@ -0,0 +1,9 @@
+fn main() {
+    let mut s = String::from("hello");
+    change(&mut s);
+    println!("{}", s);
+}
+
+fn change(some_string: &mut String) {
+    some_string.push_str(", world");
+}
diff --git a/borrow-mut.fig b/borrow-mut.fig
new file mode 100644 (file)
index 0000000..599b646
--- /dev/null
@@ -0,0 +1,12 @@
+#FIG 3.2  Produced by xfig version 3.2.6a
+Landscape
+Center
+Metric
+A4
+100.00
+Single
+-2
+1200 2
+2 5 0 1 0 -1 60 -1 -1 0.000 0 0 -1 0 0 5
+       0 borrow-mut-example.txt.eps
+        -1170 -2250 10593 -2250 10593 2370 -1170 2370 -1170 -2250
diff --git a/dangling.fig b/dangling.fig
new file mode 100644 (file)
index 0000000..30b4920
--- /dev/null
@@ -0,0 +1,12 @@
+#FIG 3.2  Produced by xfig version 3.2.6a
+Landscape
+Center
+Metric
+A4
+100.00
+Single
+-2
+1200 2
+2 5 0 1 0 -1 60 -1 -1 0.000 0 0 -1 0 0 5
+       0 dangling.txt.eps
+        -1170 -2250 10593 -2250 10593 3993 -1170 3993 -1170 -2250
diff --git a/dangling.txt b/dangling.txt
new file mode 100644 (file)
index 0000000..e4b884c
--- /dev/null
@@ -0,0 +1,19 @@
+fn main() {
+    let reference_to_nothing = dangle();
+}
+
+fn dangle() -> &String {
+    let s = String::from("hello");
+    &s
+}
+
+
+error[E0106]: missing lifetime specifier
+ --> main.rs:5:16
+  |
+5 | fn dangle() -> &String {
+  |                ^ expected lifetime parameter
+  |
+  = help: this function's return type contains a borrowed
+    value, but there is no value for it to be borrowed from
+  = help: consider giving it a 'static lifetime