From f32ce9c1421adfd957d357664e6dc95375ebaab0 Mon Sep 17 00:00:00 2001 From: Srinivas Reddy Thatiparthy Date: Thu, 20 Oct 2016 07:08:43 +0530 Subject: [PATCH] run rustfmt on librustc_driver folder --- src/librustc_driver/pretty.rs | 278 +++++++++++++------------ src/librustc_driver/target_features.rs | 25 +-- src/librustc_driver/test.rs | 76 +++---- 3 files changed, 191 insertions(+), 188 deletions(-) diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 10ff7dc89f9a3..289a7348cc8dd 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -101,8 +101,8 @@ impl PpMode { pub fn needs_analysis(&self) -> bool { match *self { - PpmMir | PpmMirCFG | PpmFlowGraph(_) => true, - _ => false, + PpmMir | PpmMirCFG | PpmFlowGraph(_) => true, + _ => false, } } } @@ -233,14 +233,11 @@ impl PpSourceMode { arenas, id, |tcx, _, _, _| { - let annotation = TypedAnnotation { - tcx: tcx, - }; + let annotation = TypedAnnotation { tcx: tcx }; let _ignore = tcx.dep_graph.in_ignore(); - f(&annotation, - payload, - ast_map.forest.krate()) - }), sess) + f(&annotation, payload, ast_map.forest.krate()) + }), + sess) } _ => panic!("Should use call_with_pp_support"), } @@ -281,9 +278,11 @@ trait HirPrinterSupport<'ast>: pprust_hir::PpAnn { /// Computes an user-readable representation of a path, if possible. fn node_path(&self, id: ast::NodeId) -> Option { self.ast_map().and_then(|map| map.def_path_from_id(id)).map(|path| { - path.data.into_iter().map(|elem| { - elem.data.to_string() - }).collect::>().join("::") + path.data + .into_iter() + .map(|elem| elem.data.to_string()) + .collect::>() + .join("::") }) } } @@ -352,7 +351,8 @@ impl<'ast> pprust::PpAnn for IdentifiedAnnotation<'ast> { } fn post(&self, s: &mut pprust::State, node: pprust::AnnNode) -> io::Result<()> { match node { - pprust::NodeIdent(_) | pprust::NodeName(_) => Ok(()), + pprust::NodeIdent(_) | + pprust::NodeName(_) => Ok(()), pprust::NodeItem(item) => { pp::space(&mut s.s)?; @@ -617,15 +617,14 @@ impl ReplaceBodyWithLoop { impl fold::Folder for ReplaceBodyWithLoop { fn fold_item_kind(&mut self, i: ast::ItemKind) -> ast::ItemKind { match i { - ast::ItemKind::Static(..) | ast::ItemKind::Const(..) => { + ast::ItemKind::Static(..) | + ast::ItemKind::Const(..) => { self.within_static_or_const = true; let ret = fold::noop_fold_item_kind(i, self); self.within_static_or_const = false; return ret; } - _ => { - fold::noop_fold_item_kind(i, self) - } + _ => fold::noop_fold_item_kind(i, self), } } @@ -656,11 +655,15 @@ impl fold::Folder for ReplaceBodyWithLoop { fn fold_block(&mut self, b: P) -> P { fn expr_to_block(rules: ast::BlockCheckMode, e: Option>) -> P { P(ast::Block { - stmts: e.map(|e| ast::Stmt { - id: ast::DUMMY_NODE_ID, - span: e.span, - node: ast::StmtKind::Expr(e), - }).into_iter().collect(), + stmts: e.map(|e| { + ast::Stmt { + id: ast::DUMMY_NODE_ID, + span: e.span, + node: ast::StmtKind::Expr(e), + } + }) + .into_iter() + .collect(), rules: rules, id: ast::DUMMY_NODE_ID, span: syntax_pos::DUMMY_SP, @@ -721,9 +724,7 @@ fn print_flowgraph<'a, 'tcx, W: Write>(variants: Vec, } blocks::FnLikeCode(fn_like) => { let (bccx, analysis_data) = - borrowck::build_borrowck_dataflow_data_for_fn(tcx, - fn_like.to_fn_parts(), - &cfg); + borrowck::build_borrowck_dataflow_data_for_fn(tcx, fn_like.to_fn_parts(), &cfg); let lcfg = borrowck_dot::DataflowLabeller { inner: lcfg, @@ -756,13 +757,13 @@ pub fn fold_crate(krate: ast::Crate, ppm: PpMode) -> ast::Crate { fn get_source(input: &Input, sess: &Session) -> (Vec, String) { let src_name = driver::source_name(input); let src = sess.codemap() - .get_filemap(&src_name) - .unwrap() - .src - .as_ref() - .unwrap() - .as_bytes() - .to_vec(); + .get_filemap(&src_name) + .unwrap() + .src + .as_ref() + .unwrap() + .as_bytes() + .to_vec(); (src, src_name) } @@ -795,17 +796,18 @@ pub fn print_after_parsing(sess: &Session, // Silently ignores an identified node. let out: &mut Write = &mut out; s.call_with_pp_support(sess, None, box out, |annotation, out| { - debug!("pretty printing source code {:?}", s); - let sess = annotation.sess(); - pprust::print_crate(sess.codemap(), - sess.diagnostic(), - krate, - src_name.to_string(), - &mut rdr, - out, - annotation.pp_ann(), - false) - }).unwrap() + debug!("pretty printing source code {:?}", s); + let sess = annotation.sess(); + pprust::print_crate(sess.codemap(), + sess.diagnostic(), + krate, + src_name.to_string(), + &mut rdr, + out, + annotation.pp_ann(), + false) + }) + .unwrap() } else { unreachable!(); }; @@ -828,8 +830,15 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session, let _ignore = dep_graph.in_ignore(); if ppm.needs_analysis() { - print_with_analysis(sess, ast_map, analysis, resolutions, - crate_name, arenas, ppm, opt_uii, ofile); + print_with_analysis(sess, + ast_map, + analysis, + resolutions, + crate_name, + arenas, + ppm, + opt_uii, + ofile); return; } @@ -839,82 +848,82 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session, let mut out = Vec::new(); match (ppm, opt_uii) { - (PpmSource(s), _) => { - // Silently ignores an identified node. - let out: &mut Write = &mut out; - s.call_with_pp_support(sess, Some(ast_map), box out, |annotation, out| { - debug!("pretty printing source code {:?}", s); - let sess = annotation.sess(); - pprust::print_crate(sess.codemap(), - sess.diagnostic(), - krate, - src_name.to_string(), - &mut rdr, - out, - annotation.pp_ann(), - true) - }) - } + (PpmSource(s), _) => { + // Silently ignores an identified node. + let out: &mut Write = &mut out; + s.call_with_pp_support(sess, Some(ast_map), box out, |annotation, out| { + debug!("pretty printing source code {:?}", s); + let sess = annotation.sess(); + pprust::print_crate(sess.codemap(), + sess.diagnostic(), + krate, + src_name.to_string(), + &mut rdr, + out, + annotation.pp_ann(), + true) + }) + } - (PpmHir(s), None) => { - let out: &mut Write = &mut out; - s.call_with_pp_support_hir(sess, - ast_map, - analysis, - resolutions, - arenas, - crate_name, - box out, - |annotation, out, krate| { - debug!("pretty printing source code {:?}", s); - let sess = annotation.sess(); - pprust_hir::print_crate(sess.codemap(), - sess.diagnostic(), - krate, - src_name.to_string(), - &mut rdr, - out, - annotation.pp_ann(), - true) - }) - } + (PpmHir(s), None) => { + let out: &mut Write = &mut out; + s.call_with_pp_support_hir(sess, + ast_map, + analysis, + resolutions, + arenas, + crate_name, + box out, + |annotation, out, krate| { + debug!("pretty printing source code {:?}", s); + let sess = annotation.sess(); + pprust_hir::print_crate(sess.codemap(), + sess.diagnostic(), + krate, + src_name.to_string(), + &mut rdr, + out, + annotation.pp_ann(), + true) + }) + } - (PpmHir(s), Some(uii)) => { - let out: &mut Write = &mut out; - s.call_with_pp_support_hir(sess, - ast_map, - analysis, - resolutions, - arenas, - crate_name, - (out,uii), - |annotation, (out,uii), _| { - debug!("pretty printing source code {:?}", s); - let sess = annotation.sess(); - let ast_map = annotation.ast_map().expect("--unpretty missing HIR map"); - let mut pp_state = - pprust_hir::State::new_from_input(sess.codemap(), - sess.diagnostic(), - src_name.to_string(), - &mut rdr, - box out, - annotation.pp_ann(), - true, - Some(ast_map.krate())); - for node_id in uii.all_matching_node_ids(ast_map) { - let node = ast_map.get(node_id); - pp_state.print_node(&node)?; - pp::space(&mut pp_state.s)?; - let path = annotation.node_path(node_id) - .expect("--unpretty missing node paths"); - pp_state.synth_comment(path)?; - pp::hardbreak(&mut pp_state.s)?; - } - pp::eof(&mut pp_state.s) - }) - } - _ => unreachable!(), - }.unwrap(); + (PpmHir(s), Some(uii)) => { + let out: &mut Write = &mut out; + s.call_with_pp_support_hir(sess, + ast_map, + analysis, + resolutions, + arenas, + crate_name, + (out, uii), + |annotation, (out, uii), _| { + debug!("pretty printing source code {:?}", s); + let sess = annotation.sess(); + let ast_map = annotation.ast_map().expect("--unpretty missing HIR map"); + let mut pp_state = pprust_hir::State::new_from_input(sess.codemap(), + sess.diagnostic(), + src_name.to_string(), + &mut rdr, + box out, + annotation.pp_ann(), + true, + Some(ast_map.krate())); + for node_id in uii.all_matching_node_ids(ast_map) { + let node = ast_map.get(node_id); + pp_state.print_node(&node)?; + pp::space(&mut pp_state.s)?; + let path = annotation.node_path(node_id) + .expect("--unpretty missing node paths"); + pp_state.synth_comment(path)?; + pp::hardbreak(&mut pp_state.s)?; + } + pp::eof(&mut pp_state.s) + }) + } + _ => unreachable!(), + } + .unwrap(); write_output(out, ofile); } @@ -955,27 +964,28 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session, let def_id = tcx.map.local_def_id(nodeid); match ppm { PpmMir => write_mir_pretty(tcx, iter::once(def_id), &mut out), - PpmMirCFG => { - write_mir_graphviz(tcx, iter::once(def_id), &mut out) - } + PpmMirCFG => write_mir_graphviz(tcx, iter::once(def_id), &mut out), _ => unreachable!(), }?; } else { match ppm { - PpmMir => write_mir_pretty(tcx, - tcx.mir_map.borrow().keys().into_iter(), - &mut out), - PpmMirCFG => write_mir_graphviz(tcx, - tcx.mir_map.borrow().keys().into_iter(), - &mut out), + PpmMir => { + write_mir_pretty(tcx, tcx.mir_map.borrow().keys().into_iter(), &mut out) + } + PpmMirCFG => { + write_mir_graphviz(tcx, + tcx.mir_map.borrow().keys().into_iter(), + &mut out) + } _ => unreachable!(), }?; } Ok(()) } PpmFlowGraph(mode) => { - let nodeid = nodeid.expect("`pretty flowgraph=..` needs NodeId (int) or \ - unique path suffix (b::c::d)"); + let nodeid = + nodeid.expect("`pretty flowgraph=..` needs NodeId (int) or unique path \ + suffix (b::c::d)"); let node = tcx.map.find(nodeid).unwrap_or_else(|| { tcx.sess.fatal(&format!("--pretty flowgraph couldn't find id: {}", nodeid)) }); @@ -990,8 +1000,8 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session, print_flowgraph(variants, tcx, code, mode, out) } None => { - let message = format!("--pretty=flowgraph needs block, fn, or method; got \ - {:?}", + let message = format!("--pretty=flowgraph needs block, fn, or method; \ + got {:?}", node); // 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, } _ => unreachable!(), } - }), sess).unwrap(); + }), + sess) + .unwrap(); write_output(out, ofile); } diff --git a/src/librustc_driver/target_features.rs b/src/librustc_driver/target_features.rs index f2020303089d2..ba51947a33301 100644 --- a/src/librustc_driver/target_features.rs +++ b/src/librustc_driver/target_features.rs @@ -20,26 +20,11 @@ use libc::c_char; // detection code will walk past the end of the feature array, // leading to crashes. -const ARM_WHITELIST: &'static [&'static str] = &[ - "neon\0", - "vfp2\0", - "vfp3\0", - "vfp4\0", -]; +const ARM_WHITELIST: &'static [&'static str] = &["neon\0", "vfp2\0", "vfp3\0", "vfp4\0"]; -const X86_WHITELIST: &'static [&'static str] = &[ - "avx\0", - "avx2\0", - "bmi\0", - "bmi2\0", - "sse\0", - "sse2\0", - "sse3\0", - "sse4.1\0", - "sse4.2\0", - "ssse3\0", - "tbm\0", -]; +const X86_WHITELIST: &'static [&'static str] = &["avx\0", "avx2\0", "bmi\0", "bmi2\0", "sse\0", + "sse2\0", "sse3\0", "sse4.1\0", "sse4.2\0", + "ssse3\0", "tbm\0"]; /// Add `target_feature = "..."` cfgs for a variety of platform /// specific features (SSE, NEON etc.). @@ -59,7 +44,7 @@ pub fn add_configuration(cfg: &mut ast::CrateConfig, sess: &Session) { for feat in whitelist { assert_eq!(feat.chars().last(), Some('\0')); if unsafe { LLVMRustHasFeature(target_machine, feat.as_ptr() as *const c_char) } { - cfg.push(attr::mk_name_value_item_str(tf.clone(), intern(&feat[..feat.len()-1]))) + cfg.push(attr::mk_name_value_item_str(tf.clone(), intern(&feat[..feat.len() - 1]))) } } } diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs index c400610a688a0..f8946528a0091 100644 --- a/src/librustc_driver/test.rs +++ b/src/librustc_driver/test.rs @@ -40,7 +40,7 @@ use syntax_pos::DUMMY_SP; use rustc::hir; -struct Env<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { +struct Env<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { infcx: &'a infer::InferCtxt<'a, 'gcx, 'tcx>, } @@ -86,8 +86,7 @@ impl Emitter for ExpectErrorEmitter { fn errors(msgs: &[&str]) -> (Box, usize) { let v = msgs.iter().map(|m| m.to_string()).collect(); - (box ExpectErrorEmitter { messages: v } as Box, - msgs.len()) + (box ExpectErrorEmitter { messages: v } as Box, msgs.len()) } fn test_env(source_string: &str, @@ -103,8 +102,12 @@ fn test_env(source_string: &str, let dep_graph = DepGraph::new(false); let _ignore = dep_graph.in_ignore(); let cstore = Rc::new(CStore::new(&dep_graph)); - let sess = session::build_session_(options, &dep_graph, None, diagnostic_handler, - Rc::new(CodeMap::new()), cstore.clone()); + let sess = session::build_session_(options, + &dep_graph, + None, + diagnostic_handler, + Rc::new(CodeMap::new()), + cstore.clone()); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); let krate_config = Vec::new(); let input = config::Input::Str { @@ -113,9 +116,15 @@ fn test_env(source_string: &str, }; let krate = driver::phase_1_parse_input(&sess, krate_config, &input).unwrap(); let driver::ExpansionResult { defs, resolutions, mut hir_forest, .. } = { - driver::phase_2_configure_and_expand( - &sess, &cstore, krate, None, "test", None, MakeGlobMap::No, |_| Ok(()), - ).expect("phase 2 aborted") + driver::phase_2_configure_and_expand(&sess, + &cstore, + krate, + None, + "test", + None, + MakeGlobMap::No, + |_| Ok(())) + .expect("phase 2 aborted") }; let _ignore = dep_graph.in_ignore(); @@ -168,14 +177,22 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> { let node = ast::NodeId::from_u32; let dscope = self.infcx - .tcx - .region_maps - .intern_code_extent(CodeExtentData::DestructionScope(node(1)), - region::ROOT_CODE_EXTENT); + .tcx + .region_maps + .intern_code_extent(CodeExtentData::DestructionScope(node(1)), + region::ROOT_CODE_EXTENT); self.create_region_hierarchy(&RH { - id: node(1), - sub: &[RH { id: node(10), sub: &[] }, RH { id: node(11), sub: &[] }], - }, dscope); + id: node(1), + sub: &[RH { + id: node(10), + sub: &[], + }, + RH { + id: node(11), + sub: &[], + }], + }, + dscope); } #[allow(dead_code)] // this seems like it could be useful, even if we don't use it now @@ -214,22 +231,16 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> { hir::ItemStatic(..) | hir::ItemFn(..) | hir::ItemForeignMod(..) | - hir::ItemTy(..) => { - None - } + hir::ItemTy(..) => None, hir::ItemEnum(..) | hir::ItemStruct(..) | hir::ItemUnion(..) | hir::ItemTrait(..) | hir::ItemImpl(..) | - hir::ItemDefaultImpl(..) => { - None - } + hir::ItemDefaultImpl(..) => None, - hir::ItemMod(ref m) => { - search_mod(this, m, idx, names) - } + hir::ItemMod(ref m) => search_mod(this, m, idx, names), }; } } @@ -282,10 +293,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> { self.infcx.tcx.mk_param(index, token::intern(&name[..])) } - pub fn re_early_bound(&self, - index: u32, - name: &'static str) - -> &'tcx ty::Region { + pub fn re_early_bound(&self, index: u32, name: &'static str) -> &'tcx ty::Region { let name = token::intern(name); self.infcx.tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { index: index, @@ -293,7 +301,9 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> { })) } - pub fn re_late_bound_with_debruijn(&self, id: u32, debruijn: ty::DebruijnIndex) + pub fn re_late_bound_with_debruijn(&self, + id: u32, + debruijn: ty::DebruijnIndex) -> &'tcx ty::Region { self.infcx.tcx.mk_region(ty::ReLateBound(debruijn, ty::BrAnon(id))) } @@ -395,9 +405,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> { self.assert_eq(t, t_lub); } - Err(ref e) => { - panic!("unexpected error in LUB: {}", e) - } + Err(ref e) => panic!("unexpected error in LUB: {}", e), } } @@ -405,9 +413,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> { pub fn check_glb(&self, t1: Ty<'tcx>, t2: Ty<'tcx>, t_glb: Ty<'tcx>) { debug!("check_glb(t1={}, t2={}, t_glb={})", t1, t2, t_glb); match self.glb(t1, t2) { - Err(e) => { - panic!("unexpected error computing LUB: {:?}", e) - } + Err(e) => panic!("unexpected error computing LUB: {:?}", e), Ok(InferOk { obligations, value: t }) => { // FIXME(#32730) once obligations are being propagated, assert the right thing. assert!(obligations.is_empty());