File tree Expand file tree Collapse file tree 2 files changed +17
-5
lines changed Expand file tree Collapse file tree 2 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -80,10 +80,17 @@ macro_rules! object {
80
80
// TODO: Consider T: Debug bound
81
81
impl <$( $t $( : $b) ?) ,* > :: core:: fmt:: Debug for $name<$( $t) ,* > {
82
82
fn fmt( & self , f: & mut :: core:: fmt:: Formatter <' _>) -> :: core:: fmt:: Result {
83
- use $crate:: { INSObject , INSString } ;
84
- :: objc2:: rc:: autoreleasepool( |pool| {
85
- :: core:: fmt:: Debug :: fmt( self . description( ) . as_str( pool) , f)
86
- } )
83
+ use :: objc2:: MessageReceiver ;
84
+ use :: alloc:: borrow:: ToOwned ;
85
+ use $crate:: { INSObject , INSString , NSObject } ;
86
+ // "downgrading" to NSObject and calling `to_owned` to work
87
+ // around `f` and Self not being AutoreleaseSafe.
88
+ // TODO: Fix this!
89
+ let this: & NSObject = unsafe { & * self . as_raw_receiver( ) . cast( ) } ;
90
+ let s = :: objc2:: rc:: autoreleasepool( |pool| {
91
+ this. description( ) . as_str( pool) . to_owned( )
92
+ } ) ;
93
+ :: core:: fmt:: Debug :: fmt( & s, f)
87
94
}
88
95
}
89
96
} ;
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ use core::slice;
5
5
use core:: str;
6
6
use std:: os:: raw:: c_char;
7
7
8
+ use alloc:: borrow:: ToOwned ;
8
9
use objc2:: ffi;
9
10
use objc2:: msg_send;
10
11
use objc2:: rc:: { autoreleasepool, AutoreleasePool } ;
@@ -119,7 +120,11 @@ unsafe impl INSCopying for NSString {
119
120
120
121
impl fmt:: Display for NSString {
121
122
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
122
- autoreleasepool ( |pool| fmt:: Display :: fmt ( self . as_str ( pool) , f) )
123
+ // The call to `to_owned` is unfortunate, but is required to work
124
+ // around `f` not being AutoreleaseSafe.
125
+ // TODO: Fix this!
126
+ let s = autoreleasepool ( |pool| self . as_str ( pool) . to_owned ( ) ) ;
127
+ fmt:: Display :: fmt ( & s, f)
123
128
}
124
129
}
125
130
You can’t perform that action at this time.
0 commit comments