Skip to content

Reuse CrateNum for proc-macro crates even when cross-compiling #86876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,11 @@ impl<'a> CrateLoader<'a> {
// don't want to match a host crate against an equivalent target one
// already loaded.
let root = library.metadata.get_root();
Ok(Some(if locator.triple == self.sess.opts.target_triple {
// FIXME: why is this condition necessary? It was adding in #33625 but I
// don't know why and the original author doesn't remember ...
let can_reuse_cratenum =
locator.triple == self.sess.opts.target_triple || locator.is_proc_macro == Some(true);
Ok(Some(if can_reuse_cratenum {
let mut result = LoadResult::Loaded(library);
self.cstore.iter_crate_data(|cnum, data| {
if data.name() == root.name() && root.hash() == data.hash() {
Expand Down
12 changes: 12 additions & 0 deletions src/test/ui/crate-loading/auxiliary/proc-macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// force-host
// no-prefer-dynamic
#![crate_name = "reproduction"]
#![crate_type = "proc-macro"]

extern crate proc_macro;
use proc_macro::TokenStream;

#[proc_macro]
pub fn mac(input: TokenStream) -> TokenStream {
input
}
8 changes: 8 additions & 0 deletions src/test/ui/crate-loading/cross-compiled-proc-macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// edition:2018
// compile-flags:--extern reproduction
// aux-build:proc-macro.rs
// check-pass

reproduction::mac!();

fn main() {}