Skip to content

Commit f41f327

Browse files
committed
Auto merge of #30185 - fhahn:improve-borrowck-public-accessibility, r=pnkfelix
This PR makes `AnalysisData` and`BorrowckCtxt` public. Those types are returned by the public function `build_borrowck_dataflow_data_for_fn` and are needed if a caller wants to pass on the return values. It also removes `FnPartsWithCFG`, which required callers of `build_borrowck_dataflow_data_for_fn` to have a reference to a `CFG` with the same lifetime as `FnParts`, which is more limiting than required.
2 parents e70c733 + b1b40c7 commit f41f327

File tree

3 files changed

+14
-28
lines changed

3 files changed

+14
-28
lines changed

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub use self::MovedValueUseKind::*;
2121
use self::InteriorKind::*;
2222

2323
use rustc::front::map as hir_map;
24-
use rustc::front::map::blocks::{FnLikeNode, FnParts};
24+
use rustc::front::map::blocks::FnParts;
2525
use rustc::middle::cfg;
2626
use rustc::middle::dataflow::DataFlowContext;
2727
use rustc::middle::dataflow::BitwiseOperator;
@@ -227,25 +227,12 @@ fn build_borrowck_dataflow_data<'a, 'tcx>(this: &mut BorrowckCtxt<'a, 'tcx>,
227227
move_data:flowed_moves }
228228
}
229229

230-
/// This and a `ty::ctxt` is all you need to run the dataflow analyses
231-
/// used in the borrow checker.
232-
pub struct FnPartsWithCFG<'a> {
233-
pub fn_parts: FnParts<'a>,
234-
pub cfg: &'a cfg::CFG,
235-
}
236-
237-
impl<'a> FnPartsWithCFG<'a> {
238-
pub fn from_fn_like(f: &'a FnLikeNode,
239-
g: &'a cfg::CFG) -> FnPartsWithCFG<'a> {
240-
FnPartsWithCFG { fn_parts: f.to_fn_parts(), cfg: g }
241-
}
242-
}
243-
244230
/// Accessor for introspective clients inspecting `AnalysisData` and
245231
/// the `BorrowckCtxt` itself , e.g. the flowgraph visualizer.
246232
pub fn build_borrowck_dataflow_data_for_fn<'a, 'tcx>(
247233
tcx: &'a ty::ctxt<'tcx>,
248-
input: FnPartsWithCFG<'a>)
234+
fn_parts: FnParts<'a>,
235+
cfg: &cfg::CFG)
249236
-> (BorrowckCtxt<'a, 'tcx>, AnalysisData<'a, 'tcx>)
250237
{
251238

@@ -260,15 +247,13 @@ pub fn build_borrowck_dataflow_data_for_fn<'a, 'tcx>(
260247
}
261248
};
262249

263-
let p = input.fn_parts;
264-
265250
let dataflow_data = build_borrowck_dataflow_data(&mut bccx,
266-
p.kind,
267-
&*p.decl,
268-
input.cfg,
269-
&*p.body,
270-
p.span,
271-
p.id);
251+
fn_parts.kind,
252+
&*fn_parts.decl,
253+
cfg,
254+
&*fn_parts.body,
255+
fn_parts.span,
256+
fn_parts.id);
272257

273258
(bccx, dataflow_data)
274259
}

src/librustc_borrowck/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extern crate rustc_front;
3838

3939
pub use borrowck::check_crate;
4040
pub use borrowck::build_borrowck_dataflow_data_for_fn;
41-
pub use borrowck::FnPartsWithCFG;
41+
pub use borrowck::{AnalysisData, BorrowckCtxt};
4242

4343
// NB: This module needs to be declared first so diagnostics are
4444
// registered before they are used.

src/librustc_driver/pretty.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -888,9 +888,10 @@ fn print_flowgraph<W: Write>(variants: Vec<borrowck_dot::Variant>,
888888
return Ok(());
889889
}
890890
blocks::FnLikeCode(fn_like) => {
891-
let fn_parts = borrowck::FnPartsWithCFG::from_fn_like(&fn_like, &cfg);
892-
let (bccx, analysis_data) = borrowck::build_borrowck_dataflow_data_for_fn(tcx,
893-
fn_parts);
891+
let (bccx, analysis_data) =
892+
borrowck::build_borrowck_dataflow_data_for_fn(tcx,
893+
fn_like.to_fn_parts(),
894+
&cfg);
894895

895896
let lcfg = borrowck_dot::DataflowLabeller {
896897
inner: lcfg,

0 commit comments

Comments
 (0)