diff --git a/lib/cretonne/src/dbg.rs b/lib/cretonne/src/dbg.rs index dc7793f3d9..bf1b92ef75 100644 --- a/lib/cretonne/src/dbg.rs +++ b/lib/cretonne/src/dbg.rs @@ -15,7 +15,7 @@ use std::env; use std::ffi::OsStr; use std::fmt; use std::fs::File; -use std::io::{Write, BufWriter}; +use std::io::{self, Write}; use std::sync::atomic; use std::thread; @@ -56,20 +56,18 @@ fn initialize() -> bool { } thread_local! { - static WRITER : RefCell> = RefCell::new(open_file()); + static WRITER : RefCell> = RefCell::new(open_file()); } -/// Execute a closure with mutable access to the tracing file writer. +/// Write a line with the given format arguments. /// /// This is for use by the `dbg!` macro. -pub fn with_writer(f: F) -> R - where F: FnOnce(&mut Write) -> R -{ - WRITER.with(|rc| f(&mut *rc.borrow_mut())) +pub fn writeln_with_format_args(args: fmt::Arguments) -> io::Result<()> { + WRITER.with(|rc| writeln!(*rc.borrow_mut(), "{}", args)) } /// Open the tracing file for the current thread. -fn open_file() -> BufWriter { +fn open_file() -> io::BufWriter { let file = match thread::current().name() { None => File::create("cretonne.dbg"), Some(name) => { @@ -83,7 +81,7 @@ fn open_file() -> BufWriter { } } .expect("Can't open tracing file"); - BufWriter::new(file) + io::BufWriter::new(file) } /// Write a line to the debug trace file if tracing is enabled. @@ -95,7 +93,7 @@ macro_rules! dbg { if $crate::dbg::enabled() { // Drop the error result so we don't get compiler errors for ignoring it. // What are you going to do, log the error? - $crate::dbg::with_writer(|w| { writeln!(w, $($arg)+).ok(); }) + $crate::dbg::writeln_with_format_args(format_args!($($arg)+)).ok(); } } }