From 76c313ceb15228a8683ca1dd03ce277ed0b69d4c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 13 Feb 2014 04:31:19 -0800 Subject: Lift $dst outside the closure in write! If you were writing to something along the lines of `self.foo` then with the new closure rules it meant that you were borrowing `self` for the entirety of the closure, meaning that you couldn't format other fields of `self` at the same time as writing to a buffer contained in `self`. By lifting the borrow outside of the closure the borrow checker can better understand that you're only borrowing one of the fields at a time. This had to use type ascription as well in order to preserve trait object coercions. --- src/libstd/macros.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index be1fdc4594d..14ae7c9900c 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -145,16 +145,18 @@ macro_rules! format( #[macro_export] macro_rules! write( - ($dst:expr, $($arg:tt)*) => ( - format_args!(|args| { ::std::fmt::write($dst, args) }, $($arg)*) - ) + ($dst:expr, $($arg:tt)*) => ({ + let dst: &mut ::std::io::Writer = $dst; + format_args!(|args| { ::std::fmt::write(dst, args) }, $($arg)*) + }) ) #[macro_export] macro_rules! writeln( - ($dst:expr, $($arg:tt)*) => ( - format_args!(|args| { ::std::fmt::writeln($dst, args) }, $($arg)*) - ) + ($dst:expr, $($arg:tt)*) => ({ + let dst: &mut ::std::io::Writer = $dst; + format_args!(|args| { ::std::fmt::writeln(dst, args) }, $($arg)*) + }) ) #[macro_export] -- cgit 1.4.1-3-g733a5