From 2cdde5aef494b303b6d4e634f0d5bcce02d0acdc Mon Sep 17 00:00:00 2001 From: Paul Lietar Date: Thu, 24 Nov 2016 22:12:36 +0000 Subject: [PATCH] Delay error reporting of filename mismatch. When cross compiling with procedural macros, the crate loader starts by looking for a target crate, before trying with a host crate. Rather than emitting an error immediately if the host and target extension differ, the compiler should delay it until both attempts have failed. Fixes #37899 r? @jseyfried --- src/librustc_metadata/creader.rs | 3 +++ src/librustc_metadata/locator.rs | 26 +++++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 27c00481bfd..372152d2b0a 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -344,6 +344,7 @@ impl<'a> CrateLoader<'a> { rejected_via_triple: vec![], rejected_via_kind: vec![], rejected_via_version: vec![], + rejected_via_filename: vec![], should_match_name: true, is_proc_macro: Some(false), }; @@ -359,6 +360,7 @@ impl<'a> CrateLoader<'a> { rejected_via_triple: vec![], rejected_via_kind: vec![], rejected_via_version: vec![], + rejected_via_filename: vec![], is_proc_macro: Some(true), ..locate_ctxt }; @@ -502,6 +504,7 @@ impl<'a> CrateLoader<'a> { rejected_via_triple: vec![], rejected_via_kind: vec![], rejected_via_version: vec![], + rejected_via_filename: vec![], should_match_name: true, is_proc_macro: None, }; diff --git a/src/librustc_metadata/locator.rs b/src/librustc_metadata/locator.rs index 868bc363791..de465ea92f6 100644 --- a/src/librustc_metadata/locator.rs +++ b/src/librustc_metadata/locator.rs @@ -269,6 +269,7 @@ pub struct Context<'a> { pub rejected_via_triple: Vec, pub rejected_via_kind: Vec, pub rejected_via_version: Vec, + pub rejected_via_filename: Vec, pub should_match_name: bool, pub is_proc_macro: Option, } @@ -417,6 +418,18 @@ impl<'a> Context<'a> { got)); } } + if !self.rejected_via_filename.is_empty() { + let dylibname = self.dylibname(); + let mismatches = self.rejected_via_filename.iter(); + for &CrateMismatch { ref path, .. } in mismatches { + err.note(&format!("extern location for {} is of an unknown type: {}", + self.crate_name, + path.display())) + .help(&format!("file name should be lib*.rlib or {}*.{}", + dylibname.0, + dylibname.1)); + } + } err.emit(); self.sess.abort_if_errors(); @@ -743,13 +756,12 @@ impl<'a> Context<'a> { return true; } } - sess.struct_err(&format!("extern location for {} is of an unknown type: {}", - self.crate_name, - loc.display())) - .help(&format!("file name should be lib*.rlib or {}*.{}", - dylibname.0, - dylibname.1)) - .emit(); + + self.rejected_via_filename.push(CrateMismatch { + path: loc.clone(), + got: String::new(), + }); + false });