about summary refs log tree commit diff
path: root/src/test/compile-fail/mutable-arguments.rs
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2012-05-29 15:37:50 -0700
committerNiko Matsakis <niko@alum.mit.edu>2012-05-29 16:22:17 -0700
commitf90228b8a82deb8da178d32322057d7e17245a77 (patch)
treec3121277e2296d1e65d4ca405e376914d51acb7a /src/test/compile-fail/mutable-arguments.rs
parent47375439ed3563f0ba8e37f5d7737011383ecbd0 (diff)
downloadrust-f90228b8a82deb8da178d32322057d7e17245a77.tar.gz
rust-f90228b8a82deb8da178d32322057d7e17245a77.zip
make all arguments modes immutable
note: you can still move from copy/move mode args
Diffstat (limited to 'src/test/compile-fail/mutable-arguments.rs')
-rw-r--r--src/test/compile-fail/mutable-arguments.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/test/compile-fail/mutable-arguments.rs b/src/test/compile-fail/mutable-arguments.rs
new file mode 100644
index 00000000000..79e7f412163
--- /dev/null
+++ b/src/test/compile-fail/mutable-arguments.rs
@@ -0,0 +1,30 @@
+// Note: it would be nice to give fewer warnings in these cases.
+
+fn mutate_by_mut_ref(&x: uint) {
+    x = 0u;
+}
+
+fn mutate_by_ref(&&x: uint) {
+    //!^ WARNING unused variable: `x`
+    x = 0u; //! ERROR assigning to argument
+}
+
+fn mutate_by_val(++x: uint) {
+    //!^ WARNING unused variable: `x`
+    x = 0u; //! ERROR assigning to argument
+}
+
+fn mutate_by_copy(+x: uint) {
+    //!^ WARNING unused variable: `x`
+    x = 0u; //! ERROR assigning to argument
+    //!^ WARNING value assigned to `x` is never read
+}
+
+fn mutate_by_move(-x: uint) {
+    //!^ WARNING unused variable: `x`
+    x = 0u; //! ERROR assigning to argument
+    //!^ WARNING value assigned to `x` is never read
+}
+
+fn main() {
+}