]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/swap-overlapping.rs
auto merge of #7016 : thestinger/rust/ptr, r=luqmana
[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 use std::ptr;
14 use std::util;
15
16 pub fn main() {
17     let mut test = TestDescAndFn {
18         desc: TestDesc {
19             name: DynTestName(~"test"),
20             should_fail: false
21         },
22         testfn: DynTestFn(|| ()),
23     };
24     do_swap(&mut test);
25 }
26
27 fn do_swap(test: &mut TestDescAndFn) {
28     unsafe {
29         ptr::swap_ptr(test, test);
30     }
31 }
32
33 pub enum TestName {
34     DynTestName(~str)
35 }
36
37 pub enum TestFn {
38     DynTestFn(~fn()),
39     DynBenchFn(~fn(&mut int))
40 }
41
42 pub struct TestDesc {
43     name: TestName,
44     should_fail: bool
45 }
46
47 pub struct TestDescAndFn {
48     desc: TestDesc,
49     testfn: TestFn,
50 }