Skip to content

Commit

Permalink
Refactor call_with_pp functions to not take a payload.
Browse files Browse the repository at this point in the history
This is needless noise; the closure we take is FnOnce, so move || {} is
fine to pass other parameters necessary.
  • Loading branch information
Mark-Simulacrum committed Jul 11, 2017
1 parent 0343136 commit 40f03a1
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions src/librustc_driver/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,67 +163,65 @@ pub fn parse_pretty(sess: &Session,

impl PpSourceMode {
/// Constructs a `PrinterSupport` object and passes it to `f`.
fn call_with_pp_support<'tcx, A, B, F>(&self,
fn call_with_pp_support<'tcx, A, F>(&self,
sess: &'tcx Session,
hir_map: Option<&hir_map::Map<'tcx>>,
payload: B,
f: F)
-> A
where F: FnOnce(&PrinterSupport, B) -> A
where F: FnOnce(&PrinterSupport) -> A
{
match *self {
PpmNormal | PpmEveryBodyLoops | PpmExpanded => {
let annotation = NoAnn {
sess: sess,
hir_map: hir_map.map(|m| m.clone()),
};
f(&annotation, payload)
f(&annotation)
}

PpmIdentified | PpmExpandedIdentified => {
let annotation = IdentifiedAnnotation {
sess: sess,
hir_map: hir_map.map(|m| m.clone()),
};
f(&annotation, payload)
f(&annotation)
}
PpmExpandedHygiene => {
let annotation = HygieneAnnotation {
sess: sess,
};
f(&annotation, payload)
f(&annotation)
}
_ => panic!("Should use call_with_pp_support_hir"),
}
}
fn call_with_pp_support_hir<'tcx, A, B, F>(&self,
fn call_with_pp_support_hir<'tcx, A, F>(&self,
sess: &'tcx Session,
hir_map: &hir_map::Map<'tcx>,
analysis: &ty::CrateAnalysis,
resolutions: &Resolutions,
arena: &'tcx DroplessArena,
arenas: &'tcx GlobalArenas<'tcx>,
id: &str,
payload: B,
f: F)
-> A
where F: FnOnce(&HirPrinterSupport, B, &hir::Crate) -> A
where F: FnOnce(&HirPrinterSupport, &hir::Crate) -> A
{
match *self {
PpmNormal => {
let annotation = NoAnn {
sess: sess,
hir_map: Some(hir_map.clone()),
};
f(&annotation, payload, hir_map.forest.krate())
f(&annotation, hir_map.forest.krate())
}

PpmIdentified => {
let annotation = IdentifiedAnnotation {
sess: sess,
hir_map: Some(hir_map.clone()),
};
f(&annotation, payload, hir_map.forest.krate())
f(&annotation, hir_map.forest.krate())
}
PpmTyped => {
abort_on_err(driver::phase_3_run_analysis_passes(sess,
Expand All @@ -240,7 +238,7 @@ impl PpSourceMode {
tables: Cell::new(&empty_tables)
};
let _ignore = tcx.dep_graph.in_ignore();
f(&annotation, payload, hir_map.forest.krate())
f(&annotation, hir_map.forest.krate())
}),
sess)
}
Expand Down Expand Up @@ -825,15 +823,15 @@ pub fn print_after_parsing(sess: &Session,
if let PpmSource(s) = ppm {
// Silently ignores an identified node.
let out: &mut Write = &mut out;
s.call_with_pp_support(sess, None, box out, |annotation, out| {
s.call_with_pp_support(sess, None, move |annotation| {
debug!("pretty printing source code {:?}", s);
let sess = annotation.sess();
pprust::print_crate(sess.codemap(),
&sess.parse_sess,
krate,
src_name.to_string(),
&mut rdr,
out,
box out,
annotation.pp_ann(),
false)
})
Expand Down Expand Up @@ -883,15 +881,15 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
(PpmSource(s), _) => {
// Silently ignores an identified node.
let out: &mut Write = &mut out;
s.call_with_pp_support(sess, Some(hir_map), box out, |annotation, out| {
s.call_with_pp_support(sess, Some(hir_map), move |annotation| {
debug!("pretty printing source code {:?}", s);
let sess = annotation.sess();
pprust::print_crate(sess.codemap(),
&sess.parse_sess,
krate,
src_name.to_string(),
&mut rdr,
out,
box out,
annotation.pp_ann(),
true)
})
Expand All @@ -906,16 +904,15 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
arena,
arenas,
crate_name,
box out,
|annotation, out, krate| {
move |annotation, krate| {
debug!("pretty printing source code {:?}", s);
let sess = annotation.sess();
pprust_hir::print_crate(sess.codemap(),
&sess.parse_sess,
krate,
src_name.to_string(),
&mut rdr,
out,
box out,
annotation.pp_ann(),
true)
})
Expand All @@ -930,8 +927,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
arena,
arenas,
crate_name,
(out, uii),
|annotation, (out, uii), _| {
move |annotation, _| {
debug!("pretty printing source code {:?}", s);
let sess = annotation.sess();
let hir_map = annotation.hir_map().expect("--unpretty missing HIR map");
Expand Down

0 comments on commit 40f03a1

Please sign in to comment.