Skip to content

Commit 12128e6

Browse files
committed
out-pointer-aliasing
1 parent 073c03b commit 12128e6

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

tests/ui/codegen/sret-aliasing-rules.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
//! Check that functions with sret results don't violate aliasing rules.
2+
//!
3+
//! When `foo = func(&mut foo)` is called, the compiler must avoid creating
4+
//! two mutable references to the same variable simultaneously (one for the
5+
//! parameter and one for the hidden sret out-pointer).
6+
//!
7+
//! Regression test for <https://github.com/rust-lang/rust/pull/18250>.
8+
19
//@ run-pass
210

311
#[derive(Copy, Clone)]
@@ -14,10 +22,7 @@ pub fn foo(f: &mut Foo) -> Foo {
1422
}
1523

1624
pub fn main() {
17-
let mut f = Foo {
18-
f1: 8,
19-
_f2: 9,
20-
};
25+
let mut f = Foo { f1: 8, _f2: 9 };
2126
f = foo(&mut f);
2227
assert_eq!(f.f1, 8);
2328
}

0 commit comments

Comments
 (0)