Skip to content

Commit 8dbecb9

Browse files
committed
Auto merge of #160975 - bjorn3:proc_macro_refactors6, r=Mark-Simulacrum
Remove target argument from get_proc_macros Currently it will always load proc-macros for the host. In the future it may also start loading wasm proc-macros. This way rust-analyzer doesn't have to pick between both options itself. Part of #160389
2 parents c98d0cb + 5b3e277 commit 8dbecb9

3 files changed

Lines changed: 5 additions & 12 deletions

File tree

compiler/rustc_metadata/src/locator.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -970,17 +970,19 @@ fn get_flavor_from_path(path: &Path) -> CrateFlavor {
970970
}
971971
}
972972

973-
/// A function to fetch about all macros inside a proc-macro crate.
973+
/// A function to fetch all macros inside a proc-macro crate.
974974
///
975975
/// Used by rust-analyzer-proc-macro-srv.
976976
pub fn get_proc_macros(
977-
target: &Target,
978977
path: &Path,
979978
metadata_loader: &dyn MetadataLoader,
980979
cfg_version: &'static str,
981980
) -> IoResult<Vec<(ProcMacroClient, ProcMacroKind)>> {
981+
let host_tuple = TargetTuple::from_tuple(config::host_tuple());
982+
let (host, _) = Target::search(&host_tuple, Path::new(""), false).unwrap();
983+
982984
let metadata =
983-
get_metadata_section(target, CrateFlavor::Dylib, path, metadata_loader, cfg_version, None)
985+
get_metadata_section(&host, CrateFlavor::Dylib, path, metadata_loader, cfg_version, None)
984986
.map_err(|err| io::Error::other(err.to_string()))?;
985987
let stable_crate_id = metadata.get_root().stable_crate_id();
986988

src/tools/rust-analyzer/crates/proc-macro-srv/src/dylib.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ mod proc_macros;
55
use rustc_codegen_ssa::back::metadata::DefaultMetadataLoader;
66
use rustc_interface::util::rustc_version_str;
77
use rustc_proc_macro::bridge;
8-
use rustc_session::config::host_tuple;
9-
use rustc_target::spec::{Target, TargetTuple};
10-
use std::path::Path;
118
use std::{fs, io, time::SystemTime};
129
use temp_dir::TempDir;
1310

@@ -78,11 +75,7 @@ struct ProcMacroLibrary {
7875
impl ProcMacroLibrary {
7976
fn open(path: &Utf8Path) -> io::Result<Self> {
8077
let proc_macros = rustc_span::create_default_session_globals_then(|| {
81-
let (target, _) =
82-
Target::search(&TargetTuple::from_tuple(host_tuple()), Path::new(""), false)
83-
.unwrap();
8478
rustc_metadata::locator::get_proc_macros(
85-
&target,
8679
path.as_ref(),
8780
&DefaultMetadataLoader,
8881
rustc_version_str().unwrap_or("unknown"),

src/tools/rust-analyzer/crates/proc-macro-srv/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ extern crate rustc_interface;
2121
extern crate rustc_lexer;
2222
extern crate rustc_metadata;
2323
extern crate rustc_proc_macro;
24-
extern crate rustc_session;
2524
extern crate rustc_span;
26-
extern crate rustc_target;
2725

2826
mod bridge;
2927
mod dylib;

0 commit comments

Comments
 (0)