From 8175098e4dd1ce3384c9f30f526aa58ba4ed950b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=C4=9Fuz=20A=C4=9Fcayaz=C4=B1?= Date: Tue, 14 Nov 2023 13:06:58 +0300 Subject: [PATCH] remove unwrap --- .../rustc_smir/src/rustc_internal/pretty.rs | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_smir/src/rustc_internal/pretty.rs b/compiler/rustc_smir/src/rustc_internal/pretty.rs index 45917630cf3e9..67995b1811046 100644 --- a/compiler/rustc_smir/src/rustc_internal/pretty.rs +++ b/compiler/rustc_smir/src/rustc_internal/pretty.rs @@ -12,20 +12,25 @@ use super::{internal, run}; pub fn write_smir_pretty<'tcx>(tcx: TyCtxt<'tcx>, w: &mut dyn io::Write) -> io::Result<()> { writeln!(w, "// WARNING: This is highly experimental output it's intended for stable-mir developers only.").unwrap(); writeln!(w, "// If you find a bug or want to improve the output open a issue at https://github.com/rust-lang/project-stable-mir.").unwrap(); + run(tcx, || { let items = stable_mir::all_local_items(); - items.iter().for_each(|item| { + let _ = items.iter().map(|item| -> io::Result<()> { // Because we can't return a Result from a closure, we have to unwrap here. - writeln!(w, "{}", function_name(*item, tcx)).unwrap(); - writeln!(w, "{}", function_body(*item, tcx)).unwrap(); - item.body().blocks.iter().enumerate().for_each(|(index, block)| { - writeln!(w, " bb{}: {{", index).unwrap(); - block.statements.iter().for_each(|statement| { - writeln!(w, "{}", pretty_statement(&statement.kind, tcx)).unwrap(); - }); + writeln!(w, "{}", function_name(*item, tcx))?; + writeln!(w, "{}", function_body(*item, tcx))?; + let _ = item.body().blocks.iter().enumerate().map(|(index, block)| -> io::Result<()> { + writeln!(w, " bb{}: {{", index)?; + let _ = block.statements.iter().map(|statement| -> io::Result<()> { + writeln!(w, "{}", pretty_statement(&statement.kind, tcx))?; + Ok(()) + }).collect::>(); writeln!(w, " }}").unwrap(); - }) - }) + Ok(()) + }).collect::>(); + Ok(()) + }).collect::>(); + }); Ok(()) }