From 368b12e7cdf563f9b94fb86d33666e8bd0b88a06 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Wed, 19 Oct 2016 18:27:22 -0700 Subject: [PATCH] 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. --- lib/cretonne/src/ir/builder.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/cretonne/src/ir/builder.rs b/lib/cretonne/src/ir/builder.rs index e8646d0dd1..a360263138 100644 --- a/lib/cretonne/src/ir/builder.rs +++ b/lib/cretonne/src/ir/builder.rs @@ -49,15 +49,15 @@ impl InstBuilder for T {} /// /// 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. -pub struct Builder<'a> { - pub dfg: &'a mut DataFlowGraph, - pub pos: &'a mut Cursor<'a>, +pub struct Builder<'c, 'fc: 'c, 'fd> { + pub pos: &'c mut Cursor<'fc>, + 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`. /// 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 { dfg: dfg, 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 { self.dfg }