summaryrefslogtreecommitdiffstats
path: root/tests/ui/borrowck/borrowck-rvalues-mutable.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/borrowck/borrowck-rvalues-mutable.rs')
-rw-r--r--tests/ui/borrowck/borrowck-rvalues-mutable.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/ui/borrowck/borrowck-rvalues-mutable.rs b/tests/ui/borrowck/borrowck-rvalues-mutable.rs
new file mode 100644
index 000000000..c4695c942
--- /dev/null
+++ b/tests/ui/borrowck/borrowck-rvalues-mutable.rs
@@ -0,0 +1,34 @@
+// run-pass
+
+struct Counter {
+ value: usize
+}
+
+impl Counter {
+ fn new(v: usize) -> Counter {
+ Counter {value: v}
+ }
+
+ fn inc<'a>(&'a mut self) -> &'a mut Counter {
+ self.value += 1;
+ self
+ }
+
+ fn get(&self) -> usize {
+ self.value
+ }
+
+ fn get_and_inc(&mut self) -> usize {
+ let v = self.value;
+ self.value += 1;
+ v
+ }
+}
+
+pub fn main() {
+ let v = Counter::new(22).get_and_inc();
+ assert_eq!(v, 22);
+
+ let v = Counter::new(22).inc().inc().get();
+ assert_eq!(v, 24);
+}