Skip to content

Commit dad5cde

Browse files
authored
Auto merge of #37987 - plietar:cross-proc-macro, r=jseyfried
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
2 parents ebc0373 + 2cdde5a commit dad5cde

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/librustc_metadata/creader.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ impl<'a> CrateLoader<'a> {
344344
rejected_via_triple: vec![],
345345
rejected_via_kind: vec![],
346346
rejected_via_version: vec![],
347+
rejected_via_filename: vec![],
347348
should_match_name: true,
348349
is_proc_macro: Some(false),
349350
};
@@ -359,6 +360,7 @@ impl<'a> CrateLoader<'a> {
359360
rejected_via_triple: vec![],
360361
rejected_via_kind: vec![],
361362
rejected_via_version: vec![],
363+
rejected_via_filename: vec![],
362364
is_proc_macro: Some(true),
363365
..locate_ctxt
364366
};
@@ -502,6 +504,7 @@ impl<'a> CrateLoader<'a> {
502504
rejected_via_triple: vec![],
503505
rejected_via_kind: vec![],
504506
rejected_via_version: vec![],
507+
rejected_via_filename: vec![],
505508
should_match_name: true,
506509
is_proc_macro: None,
507510
};

src/librustc_metadata/locator.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ pub struct Context<'a> {
269269
pub rejected_via_triple: Vec<CrateMismatch>,
270270
pub rejected_via_kind: Vec<CrateMismatch>,
271271
pub rejected_via_version: Vec<CrateMismatch>,
272+
pub rejected_via_filename: Vec<CrateMismatch>,
272273
pub should_match_name: bool,
273274
pub is_proc_macro: Option<bool>,
274275
}
@@ -417,6 +418,18 @@ impl<'a> Context<'a> {
417418
got));
418419
}
419420
}
421+
if !self.rejected_via_filename.is_empty() {
422+
let dylibname = self.dylibname();
423+
let mismatches = self.rejected_via_filename.iter();
424+
for &CrateMismatch { ref path, .. } in mismatches {
425+
err.note(&format!("extern location for {} is of an unknown type: {}",
426+
self.crate_name,
427+
path.display()))
428+
.help(&format!("file name should be lib*.rlib or {}*.{}",
429+
dylibname.0,
430+
dylibname.1));
431+
}
432+
}
420433

421434
err.emit();
422435
self.sess.abort_if_errors();
@@ -743,13 +756,12 @@ impl<'a> Context<'a> {
743756
return true;
744757
}
745758
}
746-
sess.struct_err(&format!("extern location for {} is of an unknown type: {}",
747-
self.crate_name,
748-
loc.display()))
749-
.help(&format!("file name should be lib*.rlib or {}*.{}",
750-
dylibname.0,
751-
dylibname.1))
752-
.emit();
759+
760+
self.rejected_via_filename.push(CrateMismatch {
761+
path: loc.clone(),
762+
got: String::new(),
763+
});
764+
753765
false
754766
});
755767

0 commit comments

Comments
 (0)