]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/swap-overlapping.rs
auto merge of #5043 : brson/rust/swap, r=brson
[rust.git] / src / test / run-pass / swap-overlapping.rs
1 // Copyright 2013 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 // Issue #5041 - avoid overlapping memcpy when src and dest of a swap are the same
12
13 pub fn main() {
14     let mut test = TestDescAndFn {
15         desc: TestDesc {
16             name: DynTestName(~"test"),
17             should_fail: false
18         },
19         testfn: DynTestFn(|| ()),
20     };
21     do_swap(&mut test);
22 }
23
24 fn do_swap(test: &mut TestDescAndFn) {
25     *test <-> *test;
26 }
27
28 pub enum TestName {
29     DynTestName(~str)
30 }
31
32 pub enum TestFn {
33     DynTestFn(~fn()),
34     DynBenchFn(~fn(&mut int))
35 }
36
37 pub struct TestDesc {
38     name: TestName,
39     should_fail: bool
40 }
41
42 pub struct TestDescAndFn {
43     desc: TestDesc,
44     testfn: TestFn,
45 }