From 9980252cf1b3af504d5fc6664cf3963a90fe5782 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 16 May 2019 01:30:19 +0100 Subject: [PATCH] wip --- .gitignore | 2 ++ Makefile | 4 ++++ borrow-mut-example.txt | 9 +++++++++ borrow-mut.fig | 12 ++++++++++++ dangling.fig | 12 ++++++++++++ dangling.txt | 19 +++++++++++++++++++ 6 files changed, 58 insertions(+) create mode 100644 borrow-mut-example.txt create mode 100644 borrow-mut.fig create mode 100644 dangling.fig create mode 100644 dangling.txt diff --git a/.gitignore b/.gitignore index 61f2093..c31bfc5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ intro.ps mm0.ps mm.ps +borrow-mut.ps +dangling.ps bck-lifetimes.ps macros.ps *.1 diff --git a/Makefile b/Makefile index 07b1dcf..eeb8936 100644 --- 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 index 0000000..9789164 --- /dev/null +++ b/borrow-mut-example.txt @@ -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 index 0000000..599b646 --- /dev/null +++ b/borrow-mut.fig @@ -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 index 0000000..30b4920 --- /dev/null +++ b/dangling.fig @@ -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 index 0000000..e4b884c --- /dev/null +++ b/dangling.txt @@ -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 -- 2.30.2