2025-07-01 02:46:47 +05:00
|
|
|
//! Check that functions with sret results don't violate aliasing rules.
|
|
|
|
|
//!
|
|
|
|
|
//! When `foo = func(&mut foo)` is called, the compiler must avoid creating
|
|
|
|
|
//! two mutable references to the same variable simultaneously (one for the
|
|
|
|
|
//! parameter and one for the hidden sret out-pointer).
|
|
|
|
|
//!
|
|
|
|
|
//! Regression test for <https://github.com/rust-lang/rust/pull/18250>.
|
|
|
|
|
|
2019-07-27 00:54:25 +03:00
|
|
|
//@ run-pass
|
|
|
|
|
|
2015-03-30 09:38:27 -04:00
|
|
|
#[derive(Copy, Clone)]
|
2014-10-22 21:23:26 +02:00
|
|
|
pub struct Foo {
|
2015-03-25 17:06:52 -07:00
|
|
|
f1: isize,
|
|
|
|
|
_f2: isize,
|
2014-10-22 21:23:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline(never)]
|
|
|
|
|
pub fn foo(f: &mut Foo) -> Foo {
|
|
|
|
|
let ret = *f;
|
|
|
|
|
f.f1 = 0;
|
|
|
|
|
ret
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn main() {
|
2025-07-01 02:46:47 +05:00
|
|
|
let mut f = Foo { f1: 8, _f2: 9 };
|
2014-10-22 21:23:26 +02:00
|
|
|
f = foo(&mut f);
|
|
|
|
|
assert_eq!(f.f1, 8);
|
|
|
|
|
}
|