diff options
| author | P1start <rewi-github@whanau.org> | 2014-08-10 15:54:33 +1200 |
|---|---|---|
| committer | P1start <rewi-github@whanau.org> | 2014-09-10 10:25:12 +1200 |
| commit | bf274bc18bcbfea1377c5c64ae0cc099b03d9beb (patch) | |
| tree | 78f4b0455b6c93991836bed81b7b57096737b462 /src/test/compile-fail/borrow-tuple-fields.rs | |
| parent | 651106462c357b71a4ca2c02ba2bfedfc38b0035 (diff) | |
| download | rust-bf274bc18bcbfea1377c5c64ae0cc099b03d9beb.tar.gz rust-bf274bc18bcbfea1377c5c64ae0cc099b03d9beb.zip | |
Implement tuple and tuple struct indexing
This allows code to access the fields of tuples and tuple structs:
let x = (1i, 2i);
assert_eq!(x.1, 2);
struct Point(int, int);
let origin = Point(0, 0);
assert_eq!(origin.0, 0);
assert_eq!(origin.1, 0);
Diffstat (limited to 'src/test/compile-fail/borrow-tuple-fields.rs')
| -rw-r--r-- | src/test/compile-fail/borrow-tuple-fields.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/test/compile-fail/borrow-tuple-fields.rs b/src/test/compile-fail/borrow-tuple-fields.rs new file mode 100644 index 00000000000..519bad4e627 --- /dev/null +++ b/src/test/compile-fail/borrow-tuple-fields.rs @@ -0,0 +1,42 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(tuple_indexing)] + +struct Foo(Box<int>, int); + +struct Bar(int, int); + +fn main() { + let x = (box 1i, 2i); + let r = &x.0; + let y = x; //~ ERROR cannot move out of `x` because it is borrowed + + let mut x = (1i, 2i); + let a = &x.0; + let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable because it is also borrowed as + + let mut x = (1i, 2i); + let a = &mut x.0; + let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable more than once at a time + + + let x = Foo(box 1i, 2i); + let r = &x.0; + let y = x; //~ ERROR cannot move out of `x` because it is borrowed + + let mut x = Bar(1i, 2i); + let a = &x.0; + let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable because it is also borrowed as + + let mut x = Bar(1i, 2i); + let a = &mut x.0; + let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable more than once at a time +} |
