about summary refs log tree commit diff
path: root/tests/ui/deref/pin-deref-const.rs
blob: 6ed00177b232305da3a2e4c47cea86717c6e4ec0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// The purpose of this file is to track the error messages from Pin and DerefMut interacting.
//
// Identical to `pin-deref.rs` except for using unstable `const fn`.

//@ check-fail

#![feature(const_convert)]
#![feature(const_trait_impl)]

use std::ops::DerefMut;
use std::pin::Pin;

struct MyUnpinType {}

impl MyUnpinType {
    const fn at_self(&self) {}
    const fn at_mut_self(&mut self) {}
}

struct MyPinType(core::marker::PhantomPinned);

impl MyPinType {
    const fn at_self(&self) {}
    const fn at_mut_self(&mut self) {}
}

const fn call_mut_ref_unpin(mut r_unpin: Pin<&mut MyUnpinType>) {
    r_unpin.at_self();
    r_unpin.at_mut_self();
}

const fn call_ref_unpin(mut r_unpin: Pin<&MyUnpinType>) {
    r_unpin.at_self();
    r_unpin.at_mut_self(); //~ ERROR: cannot borrow data in dereference of `Pin<&MyUnpinType>` as mutable
}

const fn call_mut_ref_pin(mut r_pin: Pin<&mut MyPinType>) {
    r_pin.at_self();
    r_pin.at_mut_self(); //~ ERROR: cannot borrow data in dereference of `Pin<&mut MyPinType>` as mutable
}

const fn call_ref_pin(mut r_pin: Pin<&MyPinType>) {
    r_pin.at_self();
    r_pin.at_mut_self(); //~ ERROR: cannot borrow data in dereference of `Pin<&MyPinType>` as mutable
}

const fn coerce_unpin_rr<'a>(mut r_unpin: &'a mut Pin<&MyUnpinType>) -> &'a MyUnpinType {
    r_unpin
}

const fn coerce_unpin_rm<'a>(mut r_unpin: &'a mut Pin<&MyUnpinType>) -> &'a mut MyUnpinType {
    r_unpin //~ ERROR: cannot borrow data in dereference of `Pin<&MyUnpinType>` as mutable
}

const fn coerce_unpin_mr<'a>(mut r_unpin: &'a mut Pin<&mut MyUnpinType>) -> &'a MyUnpinType {
    r_unpin
}

const fn coerce_unpin_mm<'a>(mut r_unpin: &'a mut Pin<&mut MyUnpinType>) -> &'a mut MyUnpinType {
    r_unpin
}

const fn coerce_pin_rr<'a>(mut r_pin: &'a mut Pin<&MyPinType>) -> &'a MyPinType {
    r_pin
}

const fn coerce_pin_rm<'a>(mut r_pin: &'a mut Pin<&MyPinType>) -> &'a mut MyPinType {
    r_pin //~ ERROR: cannot borrow data in dereference of `Pin<&MyPinType>` as mutable
}

const fn coerce_pin_mr<'a>(mut r_pin: &'a mut Pin<&mut MyPinType>) -> &'a MyPinType {
    r_pin
}

const fn coerce_pin_mm<'a>(mut r_pin: &'a mut Pin<&mut MyPinType>) -> &'a mut MyPinType {
    r_pin //~ ERROR: cannot borrow data in dereference of `Pin<&mut MyPinType>` as mutable
}

fn main() {}