Skip to content

Commit 19eb27d

Browse files
committed
swap-overlapping
1 parent bf6b0a8 commit 19eb27d

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

tests/ui/ptr_ops/ptr-swap-overlapping-regions.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1+
//! Check that `std::ptr::swap` behaves correctly when the source and destination
2+
//! pointers refer to the same memory location, avoiding issues like overlapping `memcpy`.
3+
//! This is a regression test for issues where `ptr::swap` might behave incorrectly
4+
//! when `src` and `dest` are the same.
5+
//!
6+
//! Regression test: <https://github.com/rust-lang/rust/issues/5041>
7+
18
//@ run-pass
29

310
#![allow(dead_code)]
4-
// Issue #5041 - avoid overlapping memcpy when src and dest of a swap are the same
5-
611

712
use std::ptr;
813

914
pub fn main() {
1015
let mut test = TestDescAndFn {
11-
desc: TestDesc {
12-
name: TestName::DynTestName("test".to_string()),
13-
should_fail: false
14-
},
16+
desc: TestDesc { name: TestName::DynTestName("test".to_string()), should_fail: false },
1517
testfn: TestFn::DynTestFn(22),
1618
};
1719
do_swap(&mut test);
@@ -24,7 +26,7 @@ fn do_swap(test: &mut TestDescAndFn) {
2426
}
2527

2628
pub enum TestName {
27-
DynTestName(String)
29+
DynTestName(String),
2830
}
2931

3032
pub enum TestFn {
@@ -34,7 +36,7 @@ pub enum TestFn {
3436

3537
pub struct TestDesc {
3638
name: TestName,
37-
should_fail: bool
39+
should_fail: bool,
3840
}
3941

4042
pub struct TestDescAndFn {

0 commit comments

Comments
 (0)