]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-38437.rs
Consider privacy more carefully when suggesting accessing fields
[rust.git] / src / test / ui / issues / issue-38437.rs
1 // run-pass
2 #![allow(dead_code)]
3 // Check that drop elaboration clears the "master" discriminant
4 // drop flag even if it protects no fields.
5
6 struct Good(usize);
7 impl Drop for Good {
8     #[inline(never)]
9     fn drop(&mut self) {
10         println!("dropping Good({})", self.0);
11     }
12 }
13
14 struct Void;
15 impl Drop for Void {
16     #[inline(never)]
17     fn drop(&mut self) {
18         panic!("Suddenly, a Void appears.");
19     }
20 }
21
22 enum E {
23     Never(Void),
24     Fine(Good)
25 }
26
27 fn main() {
28     let mut go = true;
29
30     loop {
31         let next;
32         match go {
33             true => next = E::Fine(Good(123)),
34             false => return,
35         }
36
37         match next {
38             E::Never(_) => return,
39             E::Fine(_good) => go = false,
40         }
41
42         // `next` is dropped and StorageDead'd here. We must reset the
43         // discriminant's drop flag to avoid random variants being
44         // dropped.
45     }
46 }