diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index 69221475356d7..354a02911b650 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -677,7 +677,15 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> { stable_crate_id: StableCrateId, ) -> Result<&'static [ProcMacro], CrateError> { // Make sure the path contains a / or the linker will search for it. - let path = env::current_dir().unwrap().join(path); + // + // FIXME(https://github.com/rust-lang/rust/issues/92750): use std::path::absolute. + let buf; + let path = if path.is_absolute() { + path + } else { + buf = env::current_dir().unwrap().join(path); + &buf + }; let lib = load_dylib(&path, 5).map_err(|err| CrateError::DlOpen(err))?; let sym_name = self.sess.generate_proc_macro_decls_symbol(stable_crate_id); diff --git a/compiler/rustc_plugin_impl/src/load.rs b/compiler/rustc_plugin_impl/src/load.rs index 27e5cb9f0d014..db868244cf341 100644 --- a/compiler/rustc_plugin_impl/src/load.rs +++ b/compiler/rustc_plugin_impl/src/load.rs @@ -11,7 +11,7 @@ use rustc_span::symbol::{sym, Ident}; use std::env; use std::mem; -use std::path::PathBuf; +use std::path::Path; /// Pointer to a registrar function. type PluginRegistrarFn = fn(&mut Registry<'_>); @@ -51,7 +51,7 @@ fn load_plugin( ident: Ident, ) { let lib = locator::find_plugin_registrar(sess, metadata_loader, ident.span, ident.name); - let fun = dylink_registrar(lib).unwrap_or_else(|err| { + let fun = dylink_registrar(&lib).unwrap_or_else(|err| { // This is fatal: there are almost certainly macros we need inside this crate, so // continuing would spew "macro undefined" errors. sess.emit_fatal(LoadPluginError { span: ident.span, msg: err.to_string() }); @@ -60,11 +60,19 @@ fn load_plugin( } /// Dynamically link a registrar function into the compiler process. -fn dylink_registrar(lib_path: PathBuf) -> Result { +fn dylink_registrar(lib_path: &Path) -> Result { // Make sure the path contains a / or the linker will search for it. - let lib_path = env::current_dir().unwrap().join(&lib_path); + // + // FIXME(https://github.com/rust-lang/rust/issues/92750): use std::path::absolute. + let buf; + let lib_path = if lib_path.is_absolute() { + lib_path + } else { + buf = env::current_dir().unwrap().join(lib_path); + &buf + }; - let lib = unsafe { Library::new(&lib_path) }?; + let lib = unsafe { Library::new(lib_path) }?; let registrar_sym = unsafe { lib.get::(b"__rustc_plugin_registrar") }?;