From: Pierre-Emmanuel Patry Date: Mon, 4 Sep 2023 10:19:13 +0000 (+0200) Subject: gccrs: Clarify package import procedure X-Git-Tag: basepoints/gcc-15~2148 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3713338d986b750a56ca60c9683727d972c47f90;p=thirdparty%2Fgcc.git gccrs: Clarify package import procedure This part of the code is a bit tricky as it calls multiple functions with almost the same name and slightly different behaviors. It was even more with a meaningless variable name. gcc/rust/ChangeLog: * rust-session-manager.cc (Session::load_extern_crate): Change variable name, add temporaries and comments. Signed-off-by: Pierre-Emmanuel Patry --- diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc index 2a8ef9721311..63f839e7c9db 100644 --- a/gcc/rust/rust-session-manager.cc +++ b/gcc/rust/rust-session-manager.cc @@ -1008,27 +1008,35 @@ Session::load_extern_crate (const std::string &crate_name, location_t locus) auto cli_extern_crate = extern_crates.find (crate_name); std::pair, std::vector> - s; + package_result; if (cli_extern_crate != extern_crates.end ()) { auto path = cli_extern_crate->second; - s = Import::try_package_in_directory (path, locus); + package_result = Import::try_package_in_directory (path, locus); } else { - s = Import::open_package (import_name, locus, relative_import_path); + package_result + = Import::open_package (import_name, locus, relative_import_path); } - if (s.first == NULL && s.second.empty ()) + + auto stream = std::move (package_result.first); + auto proc_macros = std::move (package_result.second); + + if (stream == NULL // No stream and + && proc_macros.empty ()) // no proc macros { rust_error_at (locus, "failed to locate crate %<%s%>", import_name.c_str ()); return UNKNOWN_NODEID; } - auto extern_crate = s.first == nullptr - ? Imports::ExternCrate (crate_name, s.second) - : Imports::ExternCrate (*s.first); - if (s.first != nullptr) + auto extern_crate + = stream == nullptr + ? Imports::ExternCrate (crate_name, + proc_macros) // Import proc macros + : Imports::ExternCrate (*stream); // Import from stream + if (stream != nullptr) { bool ok = extern_crate.load (locus); if (!ok)