Skip to content

Commit

Permalink
Fix symbol conflict diagnostic mistakenly being shown instead of miss…
Browse files Browse the repository at this point in the history
…ing crate diagnostic
  • Loading branch information
oli-obk committed May 23, 2023
1 parent 17a6810 commit 6d1a1cf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
10 changes: 7 additions & 3 deletions compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions compiler/rustc_metadata/src/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@ pub(crate) enum CrateError {
DlSym(String),
LocatorCombined(Box<CombinedLocatorError>),
NonDylibPlugin(Symbol),
NotFound(Symbol),
}

enum MetadataError<'a> {
Expand Down Expand Up @@ -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(),
});
}
}
}
}
2 changes: 1 addition & 1 deletion tests/run-make/issue-83045/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6d1a1cf

Please sign in to comment.