diff --git a/src/test/compile-fail/implicit-copy-1.rs b/src/test/compile-fail/implicit-copy-1.rs new file mode 100644 index 00000000000..ed514a8fe1a --- /dev/null +++ b/src/test/compile-fail/implicit-copy-1.rs @@ -0,0 +1,21 @@ +// error-pattern: cannot copy pinned type r + +resource r(i: @mutable int) { + *i = *i + 1; +} + +fn movearg(i: r) { + // Implicit copy to mutate reference i + let j <- i; +} + +fn main() { + let i = @mutable 0; + { + let j <- r(i); + movearg(j); + } + log_err *i; + // nooooooo. destructor ran twice + assert *i == 2; +} \ No newline at end of file diff --git a/src/test/compile-fail/implicit-copy-2.rs b/src/test/compile-fail/implicit-copy-2.rs new file mode 100644 index 00000000000..fbdfa45ec8e --- /dev/null +++ b/src/test/compile-fail/implicit-copy-2.rs @@ -0,0 +1,21 @@ +// error-pattern: cannot copy pinned type 'a + +resource r(i: @mutable int) { + *i = *i + 1; +} + +fn movearg(i: T) { + // Implicit copy to mutate reference i + let j <- i; +} + +fn main() { + let i = @mutable 0; + { + let j <- r(i); + movearg(j); + } + log_err *i; + // nooooooo. destructor ran twice + assert *i == 2; +} \ No newline at end of file