From 6935782b07c1caf2cc78c44faf28cc4cf0658fe8 Mon Sep 17 00:00:00 2001 From: James Miller Date: Sat, 12 Mar 2016 20:18:26 +1300 Subject: [PATCH] Add a test --- src/test/run-pass/mir_trans_critical_edge.rs | 53 ++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/test/run-pass/mir_trans_critical_edge.rs diff --git a/src/test/run-pass/mir_trans_critical_edge.rs b/src/test/run-pass/mir_trans_critical_edge.rs new file mode 100644 index 000000000000..320f40175926 --- /dev/null +++ b/src/test/run-pass/mir_trans_critical_edge.rs @@ -0,0 +1,53 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// This code produces a CFG with critical edges that, if we don't +// handle properly, will cause invalid codegen. + +#![feature(rustc_attrs)] + +enum State { + Both, + Front, + Back +} + +pub struct Foo { + state: State, + a: A, + b: B +} + +impl Foo +where A: Iterator, B: Iterator +{ + // This is the function we care about + #[rustc_mir] + fn next(&mut self) -> Option { + match self.state { + State::Both => match self.a.next() { + elt @ Some(..) => elt, + None => { + self.state = State::Back; + self.b.next() + } + }, + State::Front => self.a.next(), + State::Back => self.b.next(), + } + } +} + +// Make sure we actually translate a version of the function +pub fn do_stuff(mut f: Foo>, Box>>) { + let _x = f.next(); +} + +fn main() {}