Rollup merge of #111461 - oli-obk:crate_collision, r=petrochenkov

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

This was a refactoring mistake in https://github.com/rust-lang/rust/pull/109213

fixes #111284
This commit is contained in:
Dylan DPC 2023-05-23 16:44:26 +05:30 committed by GitHub
commit 731c1a5592
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 4 deletions

View File

@ -148,11 +148,15 @@ impl CStore {
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 @@ impl CrateError {
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