]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/qualif-indirect-mutation-fail.rs
Consider indirect mutation during const qualification dataflow
[rust.git] / src / test / ui / consts / qualif-indirect-mutation-fail.rs
1 // compile-flags: --crate-type=lib
2 #![feature(const_mut_refs)]
3 #![feature(const_precise_live_drops)]
4 #![feature(const_swap)]
5
6 // Mutable borrow of a field with drop impl.
7 pub const fn f() {
8     let mut a: (u32, Option<String>) = (0, None); //~ ERROR destructors cannot be evaluated
9     let _ = &mut a.1;
10 }
11
12 // Mutable borrow of a type with drop impl.
13 pub const A1: () = {
14     let mut x = None; //~ ERROR destructors cannot be evaluated
15     let mut y = Some(String::new());
16     let a = &mut x;
17     let b = &mut y;
18     std::mem::swap(a, b);
19     std::mem::forget(y);
20 };
21
22 // Mutable borrow of a type with drop impl.
23 pub const A2: () = {
24     let mut x = None;
25     let mut y = Some(String::new());
26     let a = &mut x;
27     let b = &mut y;
28     std::mem::swap(a, b);
29     std::mem::forget(y);
30     let _z = x; //~ ERROR destructors cannot be evaluated
31 };
32
33 // Shared borrow of a type that might be !Freeze and Drop.
34 pub const fn g1<T>() {
35     let x: Option<T> = None; //~ ERROR destructors cannot be evaluated
36     let _ = x.is_some();
37 }
38
39 // Shared borrow of a type that might be !Freeze and Drop.
40 pub const fn g2<T>() {
41     let x: Option<T> = None;
42     let _ = x.is_some();
43     let _y = x; //~ ERROR destructors cannot be evaluated
44 }