Skip to content

Commit ed96e4f

Browse files
Rollup merge of rust-lang#37296 - srinivasreddy:librustc_driver, r=nikomatsakis
run rustfmt on librustc_driver folder
2 parents 9820bd0 + f32ce9c commit ed96e4f

File tree

3 files changed

+191
-188
lines changed

3 files changed

+191
-188
lines changed

src/librustc_driver/pretty.rs

+145-133
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ impl PpMode {
101101

102102
pub fn needs_analysis(&self) -> bool {
103103
match *self {
104-
PpmMir | PpmMirCFG | PpmFlowGraph(_) => true,
105-
_ => false,
104+
PpmMir | PpmMirCFG | PpmFlowGraph(_) => true,
105+
_ => false,
106106
}
107107
}
108108
}
@@ -233,14 +233,11 @@ impl PpSourceMode {
233233
arenas,
234234
id,
235235
|tcx, _, _, _| {
236-
let annotation = TypedAnnotation {
237-
tcx: tcx,
238-
};
236+
let annotation = TypedAnnotation { tcx: tcx };
239237
let _ignore = tcx.dep_graph.in_ignore();
240-
f(&annotation,
241-
payload,
242-
ast_map.forest.krate())
243-
}), sess)
238+
f(&annotation, payload, ast_map.forest.krate())
239+
}),
240+
sess)
244241
}
245242
_ => panic!("Should use call_with_pp_support"),
246243
}
@@ -281,9 +278,11 @@ trait HirPrinterSupport<'ast>: pprust_hir::PpAnn {
281278
/// Computes an user-readable representation of a path, if possible.
282279
fn node_path(&self, id: ast::NodeId) -> Option<String> {
283280
self.ast_map().and_then(|map| map.def_path_from_id(id)).map(|path| {
284-
path.data.into_iter().map(|elem| {
285-
elem.data.to_string()
286-
}).collect::<Vec<_>>().join("::")
281+
path.data
282+
.into_iter()
283+
.map(|elem| elem.data.to_string())
284+
.collect::<Vec<_>>()
285+
.join("::")
287286
})
288287
}
289288
}
@@ -352,7 +351,8 @@ impl<'ast> pprust::PpAnn for IdentifiedAnnotation<'ast> {
352351
}
353352
fn post(&self, s: &mut pprust::State, node: pprust::AnnNode) -> io::Result<()> {
354353
match node {
355-
pprust::NodeIdent(_) | pprust::NodeName(_) => Ok(()),
354+
pprust::NodeIdent(_) |
355+
pprust::NodeName(_) => Ok(()),
356356

357357
pprust::NodeItem(item) => {
358358
pp::space(&mut s.s)?;
@@ -617,15 +617,14 @@ impl ReplaceBodyWithLoop {
617617
impl fold::Folder for ReplaceBodyWithLoop {
618618
fn fold_item_kind(&mut self, i: ast::ItemKind) -> ast::ItemKind {
619619
match i {
620-
ast::ItemKind::Static(..) | ast::ItemKind::Const(..) => {
620+
ast::ItemKind::Static(..) |
621+
ast::ItemKind::Const(..) => {
621622
self.within_static_or_const = true;
622623
let ret = fold::noop_fold_item_kind(i, self);
623624
self.within_static_or_const = false;
624625
return ret;
625626
}
626-
_ => {
627-
fold::noop_fold_item_kind(i, self)
628-
}
627+
_ => fold::noop_fold_item_kind(i, self),
629628
}
630629
}
631630

@@ -656,11 +655,15 @@ impl fold::Folder for ReplaceBodyWithLoop {
656655
fn fold_block(&mut self, b: P<ast::Block>) -> P<ast::Block> {
657656
fn expr_to_block(rules: ast::BlockCheckMode, e: Option<P<ast::Expr>>) -> P<ast::Block> {
658657
P(ast::Block {
659-
stmts: e.map(|e| ast::Stmt {
660-
id: ast::DUMMY_NODE_ID,
661-
span: e.span,
662-
node: ast::StmtKind::Expr(e),
663-
}).into_iter().collect(),
658+
stmts: e.map(|e| {
659+
ast::Stmt {
660+
id: ast::DUMMY_NODE_ID,
661+
span: e.span,
662+
node: ast::StmtKind::Expr(e),
663+
}
664+
})
665+
.into_iter()
666+
.collect(),
664667
rules: rules,
665668
id: ast::DUMMY_NODE_ID,
666669
span: syntax_pos::DUMMY_SP,
@@ -721,9 +724,7 @@ fn print_flowgraph<'a, 'tcx, W: Write>(variants: Vec<borrowck_dot::Variant>,
721724
}
722725
blocks::FnLikeCode(fn_like) => {
723726
let (bccx, analysis_data) =
724-
borrowck::build_borrowck_dataflow_data_for_fn(tcx,
725-
fn_like.to_fn_parts(),
726-
&cfg);
727+
borrowck::build_borrowck_dataflow_data_for_fn(tcx, fn_like.to_fn_parts(), &cfg);
727728

728729
let lcfg = borrowck_dot::DataflowLabeller {
729730
inner: lcfg,
@@ -756,13 +757,13 @@ pub fn fold_crate(krate: ast::Crate, ppm: PpMode) -> ast::Crate {
756757
fn get_source(input: &Input, sess: &Session) -> (Vec<u8>, String) {
757758
let src_name = driver::source_name(input);
758759
let src = sess.codemap()
759-
.get_filemap(&src_name)
760-
.unwrap()
761-
.src
762-
.as_ref()
763-
.unwrap()
764-
.as_bytes()
765-
.to_vec();
760+
.get_filemap(&src_name)
761+
.unwrap()
762+
.src
763+
.as_ref()
764+
.unwrap()
765+
.as_bytes()
766+
.to_vec();
766767
(src, src_name)
767768
}
768769

@@ -795,17 +796,18 @@ pub fn print_after_parsing(sess: &Session,
795796
// Silently ignores an identified node.
796797
let out: &mut Write = &mut out;
797798
s.call_with_pp_support(sess, None, box out, |annotation, out| {
798-
debug!("pretty printing source code {:?}", s);
799-
let sess = annotation.sess();
800-
pprust::print_crate(sess.codemap(),
801-
sess.diagnostic(),
802-
krate,
803-
src_name.to_string(),
804-
&mut rdr,
805-
out,
806-
annotation.pp_ann(),
807-
false)
808-
}).unwrap()
799+
debug!("pretty printing source code {:?}", s);
800+
let sess = annotation.sess();
801+
pprust::print_crate(sess.codemap(),
802+
sess.diagnostic(),
803+
krate,
804+
src_name.to_string(),
805+
&mut rdr,
806+
out,
807+
annotation.pp_ann(),
808+
false)
809+
})
810+
.unwrap()
809811
} else {
810812
unreachable!();
811813
};
@@ -828,8 +830,15 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
828830
let _ignore = dep_graph.in_ignore();
829831

830832
if ppm.needs_analysis() {
831-
print_with_analysis(sess, ast_map, analysis, resolutions,
832-
crate_name, arenas, ppm, opt_uii, ofile);
833+
print_with_analysis(sess,
834+
ast_map,
835+
analysis,
836+
resolutions,
837+
crate_name,
838+
arenas,
839+
ppm,
840+
opt_uii,
841+
ofile);
833842
return;
834843
}
835844

@@ -839,82 +848,82 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
839848
let mut out = Vec::new();
840849

841850
match (ppm, opt_uii) {
842-
(PpmSource(s), _) => {
843-
// Silently ignores an identified node.
844-
let out: &mut Write = &mut out;
845-
s.call_with_pp_support(sess, Some(ast_map), box out, |annotation, out| {
846-
debug!("pretty printing source code {:?}", s);
847-
let sess = annotation.sess();
848-
pprust::print_crate(sess.codemap(),
849-
sess.diagnostic(),
850-
krate,
851-
src_name.to_string(),
852-
&mut rdr,
853-
out,
854-
annotation.pp_ann(),
855-
true)
856-
})
857-
}
851+
(PpmSource(s), _) => {
852+
// Silently ignores an identified node.
853+
let out: &mut Write = &mut out;
854+
s.call_with_pp_support(sess, Some(ast_map), box out, |annotation, out| {
855+
debug!("pretty printing source code {:?}", s);
856+
let sess = annotation.sess();
857+
pprust::print_crate(sess.codemap(),
858+
sess.diagnostic(),
859+
krate,
860+
src_name.to_string(),
861+
&mut rdr,
862+
out,
863+
annotation.pp_ann(),
864+
true)
865+
})
866+
}
858867

859-
(PpmHir(s), None) => {
860-
let out: &mut Write = &mut out;
861-
s.call_with_pp_support_hir(sess,
862-
ast_map,
863-
analysis,
864-
resolutions,
865-
arenas,
866-
crate_name,
867-
box out,
868-
|annotation, out, krate| {
869-
debug!("pretty printing source code {:?}", s);
870-
let sess = annotation.sess();
871-
pprust_hir::print_crate(sess.codemap(),
872-
sess.diagnostic(),
873-
krate,
874-
src_name.to_string(),
875-
&mut rdr,
876-
out,
877-
annotation.pp_ann(),
878-
true)
879-
})
880-
}
868+
(PpmHir(s), None) => {
869+
let out: &mut Write = &mut out;
870+
s.call_with_pp_support_hir(sess,
871+
ast_map,
872+
analysis,
873+
resolutions,
874+
arenas,
875+
crate_name,
876+
box out,
877+
|annotation, out, krate| {
878+
debug!("pretty printing source code {:?}", s);
879+
let sess = annotation.sess();
880+
pprust_hir::print_crate(sess.codemap(),
881+
sess.diagnostic(),
882+
krate,
883+
src_name.to_string(),
884+
&mut rdr,
885+
out,
886+
annotation.pp_ann(),
887+
true)
888+
})
889+
}
881890

882-
(PpmHir(s), Some(uii)) => {
883-
let out: &mut Write = &mut out;
884-
s.call_with_pp_support_hir(sess,
885-
ast_map,
886-
analysis,
887-
resolutions,
888-
arenas,
889-
crate_name,
890-
(out,uii),
891-
|annotation, (out,uii), _| {
892-
debug!("pretty printing source code {:?}", s);
893-
let sess = annotation.sess();
894-
let ast_map = annotation.ast_map().expect("--unpretty missing HIR map");
895-
let mut pp_state =
896-
pprust_hir::State::new_from_input(sess.codemap(),
897-
sess.diagnostic(),
898-
src_name.to_string(),
899-
&mut rdr,
900-
box out,
901-
annotation.pp_ann(),
902-
true,
903-
Some(ast_map.krate()));
904-
for node_id in uii.all_matching_node_ids(ast_map) {
905-
let node = ast_map.get(node_id);
906-
pp_state.print_node(&node)?;
907-
pp::space(&mut pp_state.s)?;
908-
let path = annotation.node_path(node_id)
909-
.expect("--unpretty missing node paths");
910-
pp_state.synth_comment(path)?;
911-
pp::hardbreak(&mut pp_state.s)?;
912-
}
913-
pp::eof(&mut pp_state.s)
914-
})
915-
}
916-
_ => unreachable!(),
917-
}.unwrap();
891+
(PpmHir(s), Some(uii)) => {
892+
let out: &mut Write = &mut out;
893+
s.call_with_pp_support_hir(sess,
894+
ast_map,
895+
analysis,
896+
resolutions,
897+
arenas,
898+
crate_name,
899+
(out, uii),
900+
|annotation, (out, uii), _| {
901+
debug!("pretty printing source code {:?}", s);
902+
let sess = annotation.sess();
903+
let ast_map = annotation.ast_map().expect("--unpretty missing HIR map");
904+
let mut pp_state = pprust_hir::State::new_from_input(sess.codemap(),
905+
sess.diagnostic(),
906+
src_name.to_string(),
907+
&mut rdr,
908+
box out,
909+
annotation.pp_ann(),
910+
true,
911+
Some(ast_map.krate()));
912+
for node_id in uii.all_matching_node_ids(ast_map) {
913+
let node = ast_map.get(node_id);
914+
pp_state.print_node(&node)?;
915+
pp::space(&mut pp_state.s)?;
916+
let path = annotation.node_path(node_id)
917+
.expect("--unpretty missing node paths");
918+
pp_state.synth_comment(path)?;
919+
pp::hardbreak(&mut pp_state.s)?;
920+
}
921+
pp::eof(&mut pp_state.s)
922+
})
923+
}
924+
_ => unreachable!(),
925+
}
926+
.unwrap();
918927

919928
write_output(out, ofile);
920929
}
@@ -955,27 +964,28 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
955964
let def_id = tcx.map.local_def_id(nodeid);
956965
match ppm {
957966
PpmMir => write_mir_pretty(tcx, iter::once(def_id), &mut out),
958-
PpmMirCFG => {
959-
write_mir_graphviz(tcx, iter::once(def_id), &mut out)
960-
}
967+
PpmMirCFG => write_mir_graphviz(tcx, iter::once(def_id), &mut out),
961968
_ => unreachable!(),
962969
}?;
963970
} else {
964971
match ppm {
965-
PpmMir => write_mir_pretty(tcx,
966-
tcx.mir_map.borrow().keys().into_iter(),
967-
&mut out),
968-
PpmMirCFG => write_mir_graphviz(tcx,
969-
tcx.mir_map.borrow().keys().into_iter(),
970-
&mut out),
972+
PpmMir => {
973+
write_mir_pretty(tcx, tcx.mir_map.borrow().keys().into_iter(), &mut out)
974+
}
975+
PpmMirCFG => {
976+
write_mir_graphviz(tcx,
977+
tcx.mir_map.borrow().keys().into_iter(),
978+
&mut out)
979+
}
971980
_ => unreachable!(),
972981
}?;
973982
}
974983
Ok(())
975984
}
976985
PpmFlowGraph(mode) => {
977-
let nodeid = nodeid.expect("`pretty flowgraph=..` needs NodeId (int) or \
978-
unique path suffix (b::c::d)");
986+
let nodeid =
987+
nodeid.expect("`pretty flowgraph=..` needs NodeId (int) or unique path \
988+
suffix (b::c::d)");
979989
let node = tcx.map.find(nodeid).unwrap_or_else(|| {
980990
tcx.sess.fatal(&format!("--pretty flowgraph couldn't find id: {}", nodeid))
981991
});
@@ -990,8 +1000,8 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
9901000
print_flowgraph(variants, tcx, code, mode, out)
9911001
}
9921002
None => {
993-
let message = format!("--pretty=flowgraph needs block, fn, or method; got \
994-
{:?}",
1003+
let message = format!("--pretty=flowgraph needs block, fn, or method; \
1004+
got {:?}",
9951005
node);
9961006

9971007
// Point to what was found, if there's an accessible span.
@@ -1004,7 +1014,9 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
10041014
}
10051015
_ => unreachable!(),
10061016
}
1007-
}), sess).unwrap();
1017+
}),
1018+
sess)
1019+
.unwrap();
10081020

10091021
write_output(out, ofile);
10101022
}

0 commit comments

Comments
 (0)