]> git.lizzy.rs Git - rust.git/blob - tests/ui/mir/mir_codegen_critical_edge.rs
Rollup merge of #107015 - cuviper:ra-riscv64, r=Mark-Simulacrum
[rust.git] / tests / ui / mir / mir_codegen_critical_edge.rs
1 // run-pass
2 #![allow(dead_code)]
3 // This code produces a CFG with critical edges that, if we don't
4 // handle properly, will cause invalid codegen.
5
6 #![feature(rustc_attrs)]
7
8 enum State {
9     Both,
10     Front,
11     Back
12 }
13
14 pub struct Foo<A: Iterator, B: Iterator> {
15     state: State,
16     a: A,
17     b: B
18 }
19
20 impl<A, B> Foo<A, B>
21 where A: Iterator, B: Iterator<Item=A::Item>
22 {
23     // This is the function we care about
24     fn next(&mut self) -> Option<A::Item> {
25         match self.state {
26             State::Both => match self.a.next() {
27                 elt @ Some(..) => elt,
28                 None => {
29                     self.state = State::Back;
30                     self.b.next()
31                 }
32             },
33             State::Front => self.a.next(),
34             State::Back => self.b.next(),
35         }
36     }
37 }
38
39 // Make sure we actually codegen a version of the function
40 pub fn do_stuff(mut f: Foo<Box<dyn Iterator<Item=u32>>, Box<dyn Iterator<Item=u32>>>) {
41     let _x = f.next();
42 }
43
44 fn main() {}