Skip to content

Commit fe29fec

Browse files
committed
Add an error when full metadata was not found
1 parent ec32183 commit fe29fec

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

compiler/rustc_metadata/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ metadata_extern_location_not_exist =
6969
metadata_extern_location_not_file =
7070
extern location for {$crate_name} is not a file: {$location}
7171
72+
metadata_full_metadata_not_found =
73+
only metadata stub found for `{$flavor}` dependency `{$crate_name}`
74+
please provide path to the corresponding .rmeta file with full metadata
75+
7276
metadata_fail_create_file_encoder =
7377
failed to create file encoder: {$err}
7478

compiler/rustc_metadata/src/errors.rs

+9
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,15 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for MultipleCandidates {
525525
}
526526
}
527527

528+
#[derive(Diagnostic)]
529+
#[diag(metadata_full_metadata_not_found)]
530+
pub(crate) struct FullMetadataNotFound {
531+
#[primary_span]
532+
pub span: Span,
533+
pub flavor: CrateFlavor,
534+
pub crate_name: Symbol,
535+
}
536+
528537
#[derive(Diagnostic)]
529538
#[diag(metadata_symbol_conflicts_current, code = E0519)]
530539
pub struct SymbolConflictsCurrent {

compiler/rustc_metadata/src/locator.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,22 @@ impl<'a> CrateLocator<'a> {
654654
continue;
655655
}
656656
}
657-
*slot = Some((hash, metadata, lib.clone()));
657+
658+
// Question: maybe we shouldn't error eagerly here, because it is possible that
659+
// e.g. a rlib only contains a stub, but a (later-resolved) dylib contains the full
660+
// metadata?
661+
if metadata.get_header().is_stub {
662+
// `is_stub` should never be true for .rmeta files.
663+
assert_ne!(flavor, CrateFlavor::Rmeta);
664+
665+
// Because rmeta files are resolved before rlib/dylib files, if this is a stub and
666+
// we haven't found a slot already, it means that the full metadata is missing.
667+
if slot.is_none() {
668+
return Err(CrateError::FullMetadataNotFound(self.crate_name, flavor));
669+
}
670+
} else {
671+
*slot = Some((hash, metadata, lib.clone()));
672+
}
658673
ret = Some((lib, kind));
659674
}
660675

@@ -916,6 +931,7 @@ pub(crate) enum CrateError {
916931
ExternLocationNotExist(Symbol, PathBuf),
917932
ExternLocationNotFile(Symbol, PathBuf),
918933
MultipleCandidates(Symbol, CrateFlavor, Vec<PathBuf>),
934+
FullMetadataNotFound(Symbol, CrateFlavor),
919935
SymbolConflictsCurrent(Symbol),
920936
StableCrateIdCollision(Symbol, Symbol),
921937
DlOpen(String, String),
@@ -966,6 +982,9 @@ impl CrateError {
966982
CrateError::MultipleCandidates(crate_name, flavor, candidates) => {
967983
dcx.emit_err(errors::MultipleCandidates { span, crate_name, flavor, candidates });
968984
}
985+
CrateError::FullMetadataNotFound(crate_name, flavor) => {
986+
dcx.emit_err(errors::FullMetadataNotFound { span, crate_name, flavor });
987+
}
969988
CrateError::SymbolConflictsCurrent(root_name) => {
970989
dcx.emit_err(errors::SymbolConflictsCurrent { span, crate_name: root_name });
971990
}

0 commit comments

Comments
 (0)