...">

creader: Host crate loaded twice produces different CrateNums if host != target · Issue #56935 · rust-lang/rust (original) (raw)

Reproduction (as an UI test):

// force-host // no-prefer-dynamic

#![crate_type = "proc-macro"]

extern crate proc_macro; use proc_macro::TokenStream;

#[proc_macro] pub fn mac(input: TokenStream) -> TokenStream { input }

// edition:2018 // compile-flags:--extern reproduction // aux-build:reproduction.rs

reproduction::mac!();

fn main() {}

Assuming x86_64-unknown-linux-gnu host

./x.py test --bless --stage 1 --target i686-unknown-linux-gnu src/test/ui --test-args reproduction

Name resolution will try to load the crate twice, first in initial pass, then in validation pass.
The results will be different due to different loaded CrateNums, so we get the "inconsistent resolution for a macro" assertion.

This happens due to the locate_ctxt.triple == &self.sess.opts.target_triple condition in CrateLoader::load preventing reuse of CrateNums for host crates during cross-compilation.

cc @alexcrichton probably