2021-01-03 18:46:20 +00:00
|
|
|
// check-pass
|
2019-11-21 19:35:19 +00:00
|
|
|
#![feature(const_mut_refs)]
|
|
|
|
|
2024-02-16 08:58:53 +00:00
|
|
|
use std::sync::Mutex;
|
|
|
|
|
2019-11-21 19:35:19 +00:00
|
|
|
struct Foo {
|
|
|
|
x: usize
|
|
|
|
}
|
|
|
|
|
2019-11-23 20:00:14 +00:00
|
|
|
const fn foo() -> Foo {
|
|
|
|
Foo { x: 0 }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Foo {
|
|
|
|
const fn bar(&mut self) -> usize {
|
|
|
|
self.x = 1;
|
|
|
|
self.x
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const fn baz(foo: &mut Foo) -> usize {
|
2019-11-23 00:59:34 +00:00
|
|
|
let x = &mut foo.x;
|
2019-11-23 20:00:14 +00:00
|
|
|
*x = 2;
|
2019-11-23 00:59:34 +00:00
|
|
|
*x
|
2019-11-21 19:35:19 +00:00
|
|
|
}
|
|
|
|
|
2019-11-23 20:00:14 +00:00
|
|
|
const fn bazz(foo: &mut Foo) -> usize {
|
|
|
|
foo.x = 3;
|
|
|
|
foo.x
|
|
|
|
}
|
|
|
|
|
2024-02-16 08:58:53 +00:00
|
|
|
// Empty slices get promoted so this passes the static checks.
|
|
|
|
// Make sure it also passes the dynamic checks.
|
|
|
|
static MUTABLE_REFERENCE_HOLDER: Mutex<&mut [u8]> = Mutex::new(&mut []);
|
|
|
|
|
2019-11-21 19:35:19 +00:00
|
|
|
fn main() {
|
2019-11-23 20:00:14 +00:00
|
|
|
let _: [(); foo().bar()] = [(); 1];
|
|
|
|
let _: [(); baz(&mut foo())] = [(); 2];
|
|
|
|
let _: [(); bazz(&mut foo())] = [(); 3];
|
2019-11-21 19:35:19 +00:00
|
|
|
}
|