]> git.proxmox.com Git - rustc.git/blob - src/test/ui/nll/enum-drop-access.rs
New upstream version 1.66.0+dfsg1
[rustc.git] / src / test / ui / nll / enum-drop-access.rs
1 enum DropOption<T> {
2 Some(T),
3 None,
4 }
5
6 impl<T> Drop for DropOption<T> {
7 fn drop(&mut self) {}
8 }
9
10 // Dropping opt could access the value behind the reference,
11 fn drop_enum(opt: DropOption<&mut i32>) -> Option<&mut i32> {
12 match opt {
13 DropOption::Some(&mut ref mut r) => { //~ ERROR
14 Some(r)
15 },
16 DropOption::None => None,
17 }
18 }
19
20 fn optional_drop_enum(opt: Option<DropOption<&mut i32>>) -> Option<&mut i32> {
21 match opt {
22 Some(DropOption::Some(&mut ref mut r)) => { //~ ERROR
23 Some(r)
24 },
25 Some(DropOption::None) | None => None,
26 }
27 }
28
29 // Ok, dropping opt doesn't access the reference
30 fn optional_tuple(opt: Option<(&mut i32, String)>) -> Option<&mut i32> {
31 match opt {
32 Some((&mut ref mut r, _)) => {
33 Some(r)
34 },
35 None => None,
36 }
37 }
38
39 // Ok, dropping res doesn't access the Ok case.
40 fn different_variants(res: Result<&mut i32, String>) -> Option<&mut i32> {
41 match res {
42 Ok(&mut ref mut r) => {
43 Some(r)
44 },
45 Err(_) => None,
46 }
47 }
48
49 fn main() {}