diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-06-24 14:15:11 -0400 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-06-29 09:10:17 -0400 |
| commit | da5c835c8bc7c283a97dd9c7f183755473ecf810 (patch) | |
| tree | 7565b095d08f4e6f3b7db20b921715ed28bf3a59 /src/librustc_driver | |
| parent | 1aff8af213d76d746a4a86bf1b1c44af9d3d5691 (diff) | |
| download | rust-da5c835c8bc7c283a97dd9c7f183755473ecf810.tar.gz rust-da5c835c8bc7c283a97dd9c7f183755473ecf810.zip | |
Remove io::Result from syntax::print
Since we're now writing directly to the vector, there's no need to thread results through the whole printing infrastructure
Diffstat (limited to 'src/librustc_driver')
| -rw-r--r-- | src/librustc_driver/pretty.rs | 98 |
1 files changed, 44 insertions, 54 deletions
diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index f3bbf307b97..fcf790ca0f8 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -297,12 +297,9 @@ impl<'hir> HirPrinterSupport<'hir> for NoAnn<'hir> { impl<'hir> pprust::PpAnn for NoAnn<'hir> {} impl<'hir> pprust_hir::PpAnn for NoAnn<'hir> { - fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) - -> io::Result<()> { + fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) { if let Some(tcx) = self.tcx { pprust_hir::PpAnn::nested(tcx.hir(), state, nested) - } else { - Ok(()) } } } @@ -323,37 +320,37 @@ impl<'hir> PrinterSupport for IdentifiedAnnotation<'hir> { } impl<'hir> pprust::PpAnn for IdentifiedAnnotation<'hir> { - fn pre(&self, s: &mut pprust::State<'_>, node: pprust::AnnNode<'_>) -> io::Result<()> { + fn pre(&self, s: &mut pprust::State<'_>, node: pprust::AnnNode<'_>) { match node { pprust::AnnNode::Expr(_) => s.popen(), - _ => Ok(()), + _ => {} } } - fn post(&self, s: &mut pprust::State<'_>, node: pprust::AnnNode<'_>) -> io::Result<()> { + fn post(&self, s: &mut pprust::State<'_>, node: pprust::AnnNode<'_>) { match node { pprust::AnnNode::Ident(_) | - pprust::AnnNode::Name(_) => Ok(()), + pprust::AnnNode::Name(_) => {}, pprust::AnnNode::Item(item) => { - s.s.space()?; + s.s.space(); s.synth_comment(item.id.to_string()) } pprust::AnnNode::SubItem(id) => { - s.s.space()?; + s.s.space(); s.synth_comment(id.to_string()) } pprust::AnnNode::Block(blk) => { - s.s.space()?; + s.s.space(); s.synth_comment(format!("block {}", blk.id)) } pprust::AnnNode::Expr(expr) => { - s.s.space()?; - s.synth_comment(expr.id.to_string())?; + s.s.space(); + s.synth_comment(expr.id.to_string()); s.pclose() } pprust::AnnNode::Pat(pat) => { - s.s.space()?; - s.synth_comment(format!("pat {}", pat.id)) + s.s.space(); + s.synth_comment(format!("pat {}", pat.id)); } } } @@ -374,45 +371,42 @@ impl<'hir> HirPrinterSupport<'hir> for IdentifiedAnnotation<'hir> { } impl<'hir> pprust_hir::PpAnn for IdentifiedAnnotation<'hir> { - fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) - -> io::Result<()> { + fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) { if let Some(ref tcx) = self.tcx { pprust_hir::PpAnn::nested(tcx.hir(), state, nested) - } else { - Ok(()) } } - fn pre(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) -> io::Result<()> { + fn pre(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) { match node { pprust_hir::AnnNode::Expr(_) => s.popen(), - _ => Ok(()), + _ => {} } } - fn post(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) -> io::Result<()> { + fn post(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) { match node { - pprust_hir::AnnNode::Name(_) => Ok(()), + pprust_hir::AnnNode::Name(_) => {}, pprust_hir::AnnNode::Item(item) => { - s.s.space()?; + s.s.space(); s.synth_comment(format!("hir_id: {} hir local_id: {}", item.hir_id, item.hir_id.local_id.as_u32())) } pprust_hir::AnnNode::SubItem(id) => { - s.s.space()?; + s.s.space(); s.synth_comment(id.to_string()) } pprust_hir::AnnNode::Block(blk) => { - s.s.space()?; + s.s.space(); s.synth_comment(format!("block hir_id: {} hir local_id: {}", blk.hir_id, blk.hir_id.local_id.as_u32())) } pprust_hir::AnnNode::Expr(expr) => { - s.s.space()?; + s.s.space(); s.synth_comment(format!("expr hir_id: {} hir local_id: {}", - expr.hir_id, expr.hir_id.local_id.as_u32()))?; + expr.hir_id, expr.hir_id.local_id.as_u32())); s.pclose() } pprust_hir::AnnNode::Pat(pat) => { - s.s.space()?; + s.s.space(); s.synth_comment(format!("pat hir_id: {} hir local_id: {}", pat.hir_id, pat.hir_id.local_id.as_u32())) } @@ -435,19 +429,19 @@ impl<'a> PrinterSupport for HygieneAnnotation<'a> { } impl<'a> pprust::PpAnn for HygieneAnnotation<'a> { - fn post(&self, s: &mut pprust::State<'_>, node: pprust::AnnNode<'_>) -> io::Result<()> { + fn post(&self, s: &mut pprust::State<'_>, node: pprust::AnnNode<'_>) { match node { pprust::AnnNode::Ident(&ast::Ident { name, span }) => { - s.s.space()?; + s.s.space(); // FIXME #16420: this doesn't display the connections // between syntax contexts s.synth_comment(format!("{}{:?}", name.as_u32(), span.ctxt())) } pprust::AnnNode::Name(&name) => { - s.s.space()?; + s.s.space(); s.synth_comment(name.as_u32().to_string()) } - _ => Ok(()), + _ => {} } } } @@ -476,32 +470,30 @@ impl<'b, 'tcx> HirPrinterSupport<'tcx> for TypedAnnotation<'b, 'tcx> { } impl<'a, 'tcx> pprust_hir::PpAnn for TypedAnnotation<'a, 'tcx> { - fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) - -> io::Result<()> { + fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) { let old_tables = self.tables.get(); if let pprust_hir::Nested::Body(id) = nested { self.tables.set(self.tcx.body_tables(id)); } - pprust_hir::PpAnn::nested(self.tcx.hir(), state, nested)?; + pprust_hir::PpAnn::nested(self.tcx.hir(), state, nested); self.tables.set(old_tables); - Ok(()) } - fn pre(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) -> io::Result<()> { + fn pre(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) { match node { pprust_hir::AnnNode::Expr(_) => s.popen(), - _ => Ok(()), + _ => {} } } - fn post(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) -> io::Result<()> { + fn post(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) { match node { pprust_hir::AnnNode::Expr(expr) => { - s.s.space()?; - s.s.word("as")?; - s.s.space()?; - s.s.word(self.tables.get().expr_ty(expr).to_string())?; - s.pclose() + s.s.space(); + s.s.word("as"); + s.s.space(); + s.s.word(self.tables.get().expr_ty(expr).to_string()); + s.pclose(); } - _ => Ok(()), + _ => {}, } } } @@ -744,7 +736,7 @@ pub fn print_after_parsing(sess: &Session, out, annotation.pp_ann(), false) - }).unwrap() + }) } else { unreachable!(); }; @@ -831,14 +823,14 @@ pub fn print_after_hir_lowering<'tcx>( for node_id in uii.all_matching_node_ids(hir_map) { let hir_id = tcx.hir().node_to_hir_id(node_id); let node = hir_map.get(hir_id); - pp_state.print_node(node)?; - pp_state.s.space()?; + pp_state.print_node(node); + pp_state.s.space(); let path = annotation.node_path(hir_id) .expect("-Z unpretty missing node paths"); - pp_state.synth_comment(path)?; - pp_state.s.hardbreak()?; + pp_state.synth_comment(path); + pp_state.s.hardbreak(); } - pp_state.s.eof() + pp_state.s.eof(); }) } @@ -851,13 +843,11 @@ pub fn print_after_hir_lowering<'tcx>( let node = tcx.hir().get(hir_id); out.push_str(&format!("{:#?}", node)); } - Ok(()) }) } _ => unreachable!(), } - .unwrap(); write_output(out.into_bytes(), ofile); } |
