]> git.proxmox.com Git - rustc.git/blob - src/test/ui/never_type/diverging-fallback-control-flow.rs
New upstream version 1.41.1+dfsg1
[rustc.git] / src / test / ui / never_type / diverging-fallback-control-flow.rs
1 // run-pass
2
3 #![allow(dead_code)]
4 #![allow(unused_assignments)]
5 #![allow(unused_variables)]
6 #![allow(unreachable_code)]
7
8 // Test various cases where we permit an unconstrained variable
9 // to fallback based on control-flow.
10 //
11 // These represent current behavior, but are pretty dubious. I would
12 // like to revisit these and potentially change them. --nmatsakis
13
14 #![feature(never_type, never_type_fallback)]
15
16 trait BadDefault {
17 fn default() -> Self;
18 }
19
20 impl BadDefault for u32 {
21 fn default() -> Self {
22 0
23 }
24 }
25
26 impl BadDefault for ! {
27 fn default() -> ! {
28 panic!()
29 }
30 }
31
32 fn assignment() {
33 let x;
34
35 if true {
36 x = BadDefault::default();
37 } else {
38 x = return;
39 }
40 }
41
42 fn assignment_rev() {
43 let x;
44
45 if true {
46 x = return;
47 } else {
48 x = BadDefault::default();
49 }
50 }
51
52 fn if_then_else() {
53 let _x = if true {
54 BadDefault::default()
55 } else {
56 return;
57 };
58 }
59
60 fn if_then_else_rev() {
61 let _x = if true {
62 return;
63 } else {
64 BadDefault::default()
65 };
66 }
67
68 fn match_arm() {
69 let _x = match Ok(BadDefault::default()) {
70 Ok(v) => v,
71 Err(()) => return,
72 };
73 }
74
75 fn match_arm_rev() {
76 let _x = match Ok(BadDefault::default()) {
77 Err(()) => return,
78 Ok(v) => v,
79 };
80 }
81
82 fn loop_break() {
83 let _x = loop {
84 if false {
85 break return;
86 } else {
87 break BadDefault::default();
88 }
89 };
90 }
91
92 fn loop_break_rev() {
93 let _x = loop {
94 if false {
95 break return;
96 } else {
97 break BadDefault::default();
98 }
99 };
100 }
101
102 fn main() { }