]>
Commit | Line | Data |
---|---|---|
3c0e092e XL |
1 | // compile-flags: --crate-type=lib |
2 | #![feature(const_mut_refs)] | |
3 | #![feature(const_precise_live_drops)] | |
4 | #![feature(const_swap)] | |
5 | #![feature(raw_ref_op)] | |
6 | ||
7 | // Mutable borrow of a field with drop impl. | |
8 | pub const fn f() { | |
9 | let mut a: (u32, Option<String>) = (0, None); //~ ERROR destructors cannot be evaluated | |
10 | let _ = &mut a.1; | |
11 | } | |
12 | ||
13 | // Mutable borrow of a type with drop impl. | |
14 | pub const A1: () = { | |
15 | let mut x = None; //~ ERROR destructors cannot be evaluated | |
16 | let mut y = Some(String::new()); | |
17 | let a = &mut x; | |
18 | let b = &mut y; | |
19 | std::mem::swap(a, b); | |
20 | std::mem::forget(y); | |
21 | }; | |
22 | ||
23 | // Mutable borrow of a type with drop impl. | |
24 | pub const A2: () = { | |
25 | let mut x = None; | |
26 | let mut y = Some(String::new()); | |
27 | let a = &mut x; | |
28 | let b = &mut y; | |
29 | std::mem::swap(a, b); | |
30 | std::mem::forget(y); | |
31 | let _z = x; //~ ERROR destructors cannot be evaluated | |
32 | }; | |
33 | ||
34 | // Shared borrow of a type that might be !Freeze and Drop. | |
35 | pub const fn g1<T>() { | |
36 | let x: Option<T> = None; //~ ERROR destructors cannot be evaluated | |
37 | let _ = x.is_some(); | |
38 | } | |
39 | ||
40 | // Shared borrow of a type that might be !Freeze and Drop. | |
41 | pub const fn g2<T>() { | |
42 | let x: Option<T> = None; | |
43 | let _ = x.is_some(); | |
44 | let _y = x; //~ ERROR destructors cannot be evaluated | |
45 | } | |
46 | ||
47 | // Mutable raw reference to a Drop type. | |
48 | pub const fn address_of_mut() { | |
49 | let mut x: Option<String> = None; //~ ERROR destructors cannot be evaluated | |
50 | &raw mut x; | |
51 | ||
52 | let mut y: Option<String> = None; //~ ERROR destructors cannot be evaluated | |
53 | std::ptr::addr_of_mut!(y); | |
54 | } | |
55 | ||
56 | // Const raw reference to a Drop type. Conservatively assumed to allow mutation | |
57 | // until resolution of https://github.com/rust-lang/rust/issues/56604. | |
58 | pub const fn address_of_const() { | |
59 | let x: Option<String> = None; //~ ERROR destructors cannot be evaluated | |
60 | &raw const x; | |
61 | ||
62 | let y: Option<String> = None; //~ ERROR destructors cannot be evaluated | |
63 | std::ptr::addr_of!(y); | |
64 | } |