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