@@ -133,24 +133,32 @@ impl ProcMacroLibraryLibloading {
133
133
}
134
134
}
135
135
136
- pub struct Expander {
136
+ pub ( crate ) struct Expander {
137
137
inner : ProcMacroLibraryLibloading ,
138
+ path : Utf8PathBuf ,
139
+ }
140
+
141
+ impl Drop for Expander {
142
+ fn drop ( & mut self ) {
143
+ #[ cfg( windows) ]
144
+ std:: fs:: remove_file ( & self . path ) . ok ( ) ;
145
+ }
138
146
}
139
147
140
148
impl Expander {
141
- pub fn new ( lib : & Utf8Path ) -> Result < Expander , LoadProcMacroDylibError > {
149
+ pub ( crate ) fn new ( lib : & Utf8Path ) -> Result < Expander , LoadProcMacroDylibError > {
142
150
// Some libraries for dynamic loading require canonicalized path even when it is
143
151
// already absolute
144
152
let lib = lib. canonicalize_utf8 ( ) ?;
145
153
146
- let lib = ensure_file_with_lock_free_access ( & lib) ?;
154
+ let path = ensure_file_with_lock_free_access ( & lib) ?;
147
155
148
- let library = ProcMacroLibraryLibloading :: open ( lib . as_ref ( ) ) ?;
156
+ let library = ProcMacroLibraryLibloading :: open ( path . as_ref ( ) ) ?;
149
157
150
- Ok ( Expander { inner : library } )
158
+ Ok ( Expander { inner : library, path } )
151
159
}
152
160
153
- pub fn expand < S : ProcMacroSrvSpan > (
161
+ pub ( crate ) fn expand < S : ProcMacroSrvSpan > (
154
162
& self ,
155
163
macro_name : & str ,
156
164
macro_body : tt:: Subtree < S > ,
@@ -169,7 +177,7 @@ impl Expander {
169
177
result. map_err ( |e| e. into_string ( ) . unwrap_or_default ( ) )
170
178
}
171
179
172
- pub fn list_macros ( & self ) -> Vec < ( String , ProcMacroKind ) > {
180
+ pub ( crate ) fn list_macros ( & self ) -> Vec < ( String , ProcMacroKind ) > {
173
181
self . inner . proc_macros . list_macros ( )
174
182
}
175
183
}
@@ -198,7 +206,7 @@ fn ensure_file_with_lock_free_access(path: &Utf8Path) -> io::Result<Utf8PathBuf>
198
206
unique_name. push_str ( file_name) ;
199
207
200
208
to. push ( unique_name) ;
201
- std:: fs:: copy ( path, & to) . unwrap ( ) ;
209
+ std:: fs:: copy ( path, & to) ? ;
202
210
Ok ( to)
203
211
}
204
212
0 commit comments