Fix symbol conflict diagnostic mistakenly being shown instead of missing crate diagnostic

This commit is contained in:
Oli Scherer 2023-05-11 11:32:58 +00:00
parent 17a681000b
commit 6d1a1cf354
3 changed files with 21 additions and 4 deletions

View File

@ -148,11 +148,15 @@ fn intern_stable_crate_id(&mut self, root: &CrateRoot) -> Result<CrateNum, Crate
assert_eq!(self.metas.len(), self.stable_crate_ids.len());
let num = CrateNum::new(self.stable_crate_ids.len());
if let Some(&existing) = self.stable_crate_ids.get(&root.stable_crate_id()) {
let crate_name0 = root.name();
if let Some(crate_name1) = self.metas[existing].as_ref().map(|data| data.name()) {
// Check for (potential) conflicts with the local crate
if existing == LOCAL_CRATE {
Err(CrateError::SymbolConflictsCurrent(root.name()))
} else if let Some(crate_name1) = self.metas[existing].as_ref().map(|data| data.name())
{
let crate_name0 = root.name();
Err(CrateError::StableCrateIdCollision(crate_name0, crate_name1))
} else {
Err(CrateError::SymbolConflictsCurrent(crate_name0))
Err(CrateError::NotFound(root.name()))
}
} else {
self.metas.push(None);

View File

@ -961,6 +961,7 @@ pub(crate) enum CrateError {
DlSym(String),
LocatorCombined(Box<CombinedLocatorError>),
NonDylibPlugin(Symbol),
NotFound(Symbol),
}
enum MetadataError<'a> {
@ -1131,6 +1132,18 @@ pub(crate) fn report(self, sess: &Session, span: Span, missing_core: bool) {
CrateError::NonDylibPlugin(crate_name) => {
sess.emit_err(errors::NoDylibPlugin { span, crate_name });
}
CrateError::NotFound(crate_name) => {
sess.emit_err(errors::CannotFindCrate {
span,
crate_name,
add_info: String::new(),
missing_core,
current_crate: sess.opts.crate_name.clone().unwrap_or("<unknown>".to_string()),
is_nightly_build: sess.is_nightly_build(),
profiler_runtime: Symbol::intern(&sess.opts.unstable_opts.profiler_runtime),
locator_triple: sess.opts.target_triple.clone(),
});
}
}
}
}

View File

@ -29,5 +29,5 @@ all:
--crate-type=rlib \
--edition=2018 \
c.rs 2>&1 | tee $(TMPDIR)/output.txt || exit 0
$(CGREP) E0519 < $(TMPDIR)/output.txt
$(CGREP) E0463 < $(TMPDIR)/output.txt
$(CGREP) -v "internal compiler error" < $(TMPDIR)/output.txt