@@ -133,24 +133,32 @@ impl ProcMacroLibraryLibloading {
133133 }
134134}
135135
136- pub struct Expander {
136+ pub ( crate ) struct Expander {
137137 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+ }
138146}
139147
140148impl Expander {
141- pub fn new ( lib : & Utf8Path ) -> Result < Expander , LoadProcMacroDylibError > {
149+ pub ( crate ) fn new ( lib : & Utf8Path ) -> Result < Expander , LoadProcMacroDylibError > {
142150 // Some libraries for dynamic loading require canonicalized path even when it is
143151 // already absolute
144152 let lib = lib. canonicalize_utf8 ( ) ?;
145153
146- let lib = ensure_file_with_lock_free_access ( & lib) ?;
154+ let path = ensure_file_with_lock_free_access ( & lib) ?;
147155
148- let library = ProcMacroLibraryLibloading :: open ( lib . as_ref ( ) ) ?;
156+ let library = ProcMacroLibraryLibloading :: open ( path . as_ref ( ) ) ?;
149157
150- Ok ( Expander { inner : library } )
158+ Ok ( Expander { inner : library, path } )
151159 }
152160
153- pub fn expand < S : ProcMacroSrvSpan > (
161+ pub ( crate ) fn expand < S : ProcMacroSrvSpan > (
154162 & self ,
155163 macro_name : & str ,
156164 macro_body : tt:: Subtree < S > ,
@@ -169,7 +177,7 @@ impl Expander {
169177 result. map_err ( |e| e. into_string ( ) . unwrap_or_default ( ) )
170178 }
171179
172- pub fn list_macros ( & self ) -> Vec < ( String , ProcMacroKind ) > {
180+ pub ( crate ) fn list_macros ( & self ) -> Vec < ( String , ProcMacroKind ) > {
173181 self . inner . proc_macros . list_macros ( )
174182 }
175183}
@@ -198,7 +206,7 @@ fn ensure_file_with_lock_free_access(path: &Utf8Path) -> io::Result<Utf8PathBuf>
198206 unique_name. push_str ( file_name) ;
199207
200208 to. push ( unique_name) ;
201- std:: fs:: copy ( path, & to) . unwrap ( ) ;
209+ std:: fs:: copy ( path, & to) ? ;
202210 Ok ( to)
203211}
204212
0 commit comments