Use more precise lifetimes for Builder.

Distinguish the lifetime of the Cursor and its referenced function
layout.

Use two separate function lifetimes: 'fc and 'fd. The borrow checker
seems to get confused if we don't.
This commit is contained in:
Jakob Stoklund Olesen
2016-10-19 18:27:22 -07:00
parent eef5de1cf0
commit 4cd33b210e

View File

@@ -49,15 +49,15 @@ impl<T: InstBuilderBase> InstBuilder for T {}
/// ///
/// A `Builder` holds mutable references to a data flow graph and a layout cursor. It provides /// A `Builder` holds mutable references to a data flow graph and a layout cursor. It provides
/// convenience method for creating and inserting instructions at the current cursor position. /// convenience method for creating and inserting instructions at the current cursor position.
pub struct Builder<'a> { pub struct Builder<'c, 'fc: 'c, 'fd> {
pub dfg: &'a mut DataFlowGraph, pub pos: &'c mut Cursor<'fc>,
pub pos: &'a mut Cursor<'a>, pub dfg: &'fd mut DataFlowGraph,
} }
impl<'a> Builder<'a> { impl<'c, 'fc, 'fd> Builder<'c, 'fc, 'fd> {
/// Create a new builder which inserts instructions at `pos`. /// Create a new builder which inserts instructions at `pos`.
/// The `dfg` and `pos.layout` references should be from the same `Function`. /// The `dfg` and `pos.layout` references should be from the same `Function`.
pub fn new(dfg: &'a mut DataFlowGraph, pos: &'a mut Cursor<'a>) -> Builder<'a> { pub fn new(dfg: &'fd mut DataFlowGraph, pos: &'c mut Cursor<'fc>) -> Builder<'c, 'fc, 'fd> {
Builder { Builder {
dfg: dfg, dfg: dfg,
pos: pos, pos: pos,
@@ -78,7 +78,7 @@ impl<'a> Builder<'a> {
} }
} }
impl<'a> InstBuilderBase for Builder<'a> { impl<'c, 'fc, 'fd> InstBuilderBase for Builder<'c, 'fc, 'fd> {
fn data_flow_graph(&self) -> &DataFlowGraph { fn data_flow_graph(&self) -> &DataFlowGraph {
self.dfg self.dfg
} }