From: Ian Jackson Date: Thu, 16 May 2019 00:39:28 +0000 (+0100) Subject: wip X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=91a20b550409165e84a8ecbc2b401b1f1c767d79;p=talk-2019-ghm-rust.git wip --- diff --git a/.gitignore b/.gitignore index c31bfc5..c48427e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ mm0.ps mm.ps borrow-mut.ps dangling.ps +borrow-nonmut.ps bck-lifetimes.ps macros.ps *.1 diff --git a/Makefile b/Makefile index f9a9c2e..b3a833c 100644 --- 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 index 0000000..bf9f471 --- /dev/null +++ b/borrow-nonmut-error.txt @@ -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 index 0000000..6c084d6 --- /dev/null +++ b/borrow-nonmut.fig @@ -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 index 0000000..aafb0ac --- /dev/null +++ b/borrow-nonmut.txt @@ -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"); +}