]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/coerce-reborrow-mut-ptr-arg.rs
4a680027b46e2adb91f70047567acd5fd1e992e3
[rust.git] / src / test / run-pass / coerce-reborrow-mut-ptr-arg.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 struct SpeechMaker {
12     speeches: uint
13 }
14
15 fn talk(x: &mut SpeechMaker) {
16     x.speeches += 1;
17 }
18
19 fn give_a_few_speeches(speaker: &mut SpeechMaker) {
20
21     // Here speaker is reborrowed for each call, so we don't get errors
22     // about speaker being moved.
23
24     talk(speaker);
25     talk(speaker);
26     talk(speaker);
27 }
28
29 pub fn main() {
30     let mut lincoln = SpeechMaker {speeches: 22};
31     give_a_few_speeches(&mut lincoln);
32 }