diff --git a/src/test/compile-fail/borrowck-borrowed-uniq-rvalue-2.rs b/src/test/compile-fail/borrowck-borrowed-uniq-rvalue-2.rs new file mode 100644 index 0000000000000..6dfe23c1995a9 --- /dev/null +++ b/src/test/compile-fail/borrowck-borrowed-uniq-rvalue-2.rs @@ -0,0 +1,9 @@ +struct defer { + x: &[&str]; + new(x: &[&str]) { self.x = x; } + drop { #error["%?", self.x]; } +} + +fn main() { + let _x = defer(~["Goodbye", "world!"]); //~ ERROR illegal borrow +} diff --git a/src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs b/src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs new file mode 100644 index 0000000000000..59b8be67ae759 --- /dev/null +++ b/src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs @@ -0,0 +1,13 @@ +//buggy.rs +use std; +import std::map::hashmap; +import std::map; + +fn main() { + let buggy_map :hashmap = hashmap::(uint::hash, uint::eq); + buggy_map.insert(42, ~1); //~ ERROR illegal borrow + + // but it is ok if we use a temporary + let tmp = ~2; + buggy_map.insert(43, tmp); +} diff --git a/src/test/compile-fail/borrowck-ref-into-rvalue.rs b/src/test/compile-fail/borrowck-ref-into-rvalue.rs new file mode 100644 index 0000000000000..654801403de3e --- /dev/null +++ b/src/test/compile-fail/borrowck-ref-into-rvalue.rs @@ -0,0 +1,11 @@ +fn main() { + let msg; + match some(~"Hello") { //~ ERROR illegal borrow + some(ref m) => { + msg = m; + }, + none => { fail } + } + io::println(*msg); +} +