]> git.proxmox.com Git - rustc.git/blame - src/test/ui/mir/mir_codegen_critical_edge.rs
New upstream version 1.67.1+dfsg1
[rustc.git] / src / test / ui / mir / mir_codegen_critical_edge.rs
CommitLineData
b7449926 1// run-pass
0bf4aa26 2#![allow(dead_code)]
54a0048b
SL
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
8enum State {
9 Both,
10 Front,
11 Back
12}
13
14pub struct Foo<A: Iterator, B: Iterator> {
15 state: State,
16 a: A,
17 b: B
18}
19
20impl<A, B> Foo<A, B>
21where A: Iterator, B: Iterator<Item=A::Item>
22{
23 // This is the function we care about
54a0048b
SL
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
94b46f34 39// Make sure we actually codegen a version of the function
dc9dc135 40pub fn do_stuff(mut f: Foo<Box<dyn Iterator<Item=u32>>, Box<dyn Iterator<Item=u32>>>) {
54a0048b
SL
41 let _x = f.next();
42}
43
44fn main() {}