6 use rustc_errors::{error_code, ErrorGuaranteed};
7 use rustc_macros::SessionDiagnostic;
8 use rustc_session::{config, SessionDiagnostic};
9 use rustc_span::{sym, Span, Symbol};
10 use rustc_target::spec::{PanicStrategy, TargetTriple};
12 use crate::locator::CrateFlavor;
14 #[derive(SessionDiagnostic)]
15 #[diag(metadata::rlib_required)]
16 pub struct RlibRequired {
17 pub crate_name: Symbol,
20 #[derive(SessionDiagnostic)]
21 #[diag(metadata::lib_required)]
22 pub struct LibRequired<'a> {
23 pub crate_name: Symbol,
27 #[derive(SessionDiagnostic)]
28 #[diag(metadata::crate_dep_multiple)]
30 pub struct CrateDepMultiple {
31 pub crate_name: Symbol,
34 #[derive(SessionDiagnostic)]
35 #[diag(metadata::two_panic_runtimes)]
36 pub struct TwoPanicRuntimes {
37 pub prev_name: Symbol,
41 #[derive(SessionDiagnostic)]
42 #[diag(metadata::bad_panic_strategy)]
43 pub struct BadPanicStrategy {
45 pub strategy: PanicStrategy,
48 #[derive(SessionDiagnostic)]
49 #[diag(metadata::required_panic_strategy)]
50 pub struct RequiredPanicStrategy {
51 pub crate_name: Symbol,
52 pub found_strategy: PanicStrategy,
53 pub desired_strategy: PanicStrategy,
56 #[derive(SessionDiagnostic)]
57 #[diag(metadata::incompatible_panic_in_drop_strategy)]
58 pub struct IncompatiblePanicInDropStrategy {
59 pub crate_name: Symbol,
60 pub found_strategy: PanicStrategy,
61 pub desired_strategy: PanicStrategy,
64 #[derive(SessionDiagnostic)]
65 #[diag(metadata::multiple_names_in_link)]
66 pub struct MultipleNamesInLink {
71 #[derive(SessionDiagnostic)]
72 #[diag(metadata::multiple_kinds_in_link)]
73 pub struct MultipleKindsInLink {
78 #[derive(SessionDiagnostic)]
79 #[diag(metadata::link_name_form)]
80 pub struct LinkNameForm {
85 #[derive(SessionDiagnostic)]
86 #[diag(metadata::link_kind_form)]
87 pub struct LinkKindForm {
92 #[derive(SessionDiagnostic)]
93 #[diag(metadata::link_modifiers_form)]
94 pub struct LinkModifiersForm {
99 #[derive(SessionDiagnostic)]
100 #[diag(metadata::link_cfg_form)]
101 pub struct LinkCfgForm {
106 #[derive(SessionDiagnostic)]
107 #[diag(metadata::wasm_import_form)]
108 pub struct WasmImportForm {
113 #[derive(SessionDiagnostic)]
114 #[diag(metadata::empty_link_name, code = "E0454")]
115 pub struct EmptyLinkName {
121 #[derive(SessionDiagnostic)]
122 #[diag(metadata::link_framework_apple, code = "E0455")]
123 pub struct LinkFrameworkApple {
128 #[derive(SessionDiagnostic)]
129 #[diag(metadata::framework_only_windows, code = "E0455")]
130 pub struct FrameworkOnlyWindows {
135 #[derive(SessionDiagnostic)]
136 #[diag(metadata::unknown_link_kind, code = "E0458")]
137 pub struct UnknownLinkKind<'a> {
144 #[derive(SessionDiagnostic)]
145 #[diag(metadata::multiple_link_modifiers)]
146 pub struct MultipleLinkModifiers {
151 #[derive(SessionDiagnostic)]
152 #[diag(metadata::multiple_cfgs)]
153 pub struct MultipleCfgs {
158 #[derive(SessionDiagnostic)]
159 #[diag(metadata::link_cfg_single_predicate)]
160 pub struct LinkCfgSinglePredicate {
165 #[derive(SessionDiagnostic)]
166 #[diag(metadata::multiple_wasm_import)]
167 pub struct MultipleWasmImport {
172 #[derive(SessionDiagnostic)]
173 #[diag(metadata::unexpected_link_arg)]
174 pub struct UnexpectedLinkArg {
179 #[derive(SessionDiagnostic)]
180 #[diag(metadata::invalid_link_modifier)]
181 pub struct InvalidLinkModifier {
186 #[derive(SessionDiagnostic)]
187 #[diag(metadata::multiple_modifiers)]
188 pub struct MultipleModifiers<'a> {
191 pub modifier: &'a str,
194 #[derive(SessionDiagnostic)]
195 #[diag(metadata::bundle_needs_static)]
196 pub struct BundleNeedsStatic {
201 #[derive(SessionDiagnostic)]
202 #[diag(metadata::whole_archive_needs_static)]
203 pub struct WholeArchiveNeedsStatic {
208 #[derive(SessionDiagnostic)]
209 #[diag(metadata::as_needed_compatibility)]
210 pub struct AsNeededCompatibility {
215 #[derive(SessionDiagnostic)]
216 #[diag(metadata::unknown_link_modifier)]
217 pub struct UnknownLinkModifier<'a> {
220 pub modifier: &'a str,
223 #[derive(SessionDiagnostic)]
224 #[diag(metadata::incompatible_wasm_link)]
225 pub struct IncompatibleWasmLink {
230 #[derive(SessionDiagnostic)]
231 #[diag(metadata::link_requires_name, code = "E0459")]
232 pub struct LinkRequiresName {
238 #[derive(SessionDiagnostic)]
239 #[diag(metadata::raw_dylib_no_nul)]
240 pub struct RawDylibNoNul {
245 #[derive(SessionDiagnostic)]
246 #[diag(metadata::link_ordinal_raw_dylib)]
247 pub struct LinkOrdinalRawDylib {
252 #[derive(SessionDiagnostic)]
253 #[diag(metadata::lib_framework_apple)]
254 pub struct LibFrameworkApple;
256 #[derive(SessionDiagnostic)]
257 #[diag(metadata::empty_renaming_target)]
258 pub struct EmptyRenamingTarget<'a> {
259 pub lib_name: &'a str,
262 #[derive(SessionDiagnostic)]
263 #[diag(metadata::renaming_no_link)]
264 pub struct RenamingNoLink<'a> {
265 pub lib_name: &'a str,
268 #[derive(SessionDiagnostic)]
269 #[diag(metadata::multiple_renamings)]
270 pub struct MultipleRenamings<'a> {
271 pub lib_name: &'a str,
274 #[derive(SessionDiagnostic)]
275 #[diag(metadata::no_link_mod_override)]
276 pub struct NoLinkModOverride {
278 pub span: Option<Span>,
281 #[derive(SessionDiagnostic)]
282 #[diag(metadata::unsupported_abi_i686)]
283 pub struct UnsupportedAbiI686 {
288 #[derive(SessionDiagnostic)]
289 #[diag(metadata::unsupported_abi)]
290 pub struct UnsupportedAbi {
295 #[derive(SessionDiagnostic)]
296 #[diag(metadata::fail_create_file_encoder)]
297 pub struct FailCreateFileEncoder {
301 #[derive(SessionDiagnostic)]
302 #[diag(metadata::fail_seek_file)]
303 pub struct FailSeekFile {
307 #[derive(SessionDiagnostic)]
308 #[diag(metadata::fail_write_file)]
309 pub struct FailWriteFile {
313 #[derive(SessionDiagnostic)]
314 #[diag(metadata::crate_not_panic_runtime)]
315 pub struct CrateNotPanicRuntime {
316 pub crate_name: Symbol,
319 #[derive(SessionDiagnostic)]
320 #[diag(metadata::no_panic_strategy)]
321 pub struct NoPanicStrategy {
322 pub crate_name: Symbol,
323 pub strategy: PanicStrategy,
326 #[derive(SessionDiagnostic)]
327 #[diag(metadata::profiler_builtins_needs_core)]
328 pub struct ProfilerBuiltinsNeedsCore;
330 #[derive(SessionDiagnostic)]
331 #[diag(metadata::not_profiler_runtime)]
332 pub struct NotProfilerRuntime {
333 pub crate_name: Symbol,
336 #[derive(SessionDiagnostic)]
337 #[diag(metadata::no_multiple_global_alloc)]
338 pub struct NoMultipleGlobalAlloc {
342 #[label(metadata::prev_global_alloc)]
346 #[derive(SessionDiagnostic)]
347 #[diag(metadata::conflicting_global_alloc)]
348 pub struct ConflictingGlobalAlloc {
349 pub crate_name: Symbol,
350 pub other_crate_name: Symbol,
353 #[derive(SessionDiagnostic)]
354 #[diag(metadata::global_alloc_required)]
355 pub struct GlobalAllocRequired;
357 #[derive(SessionDiagnostic)]
358 #[diag(metadata::no_transitive_needs_dep)]
359 pub struct NoTransitiveNeedsDep<'a> {
360 pub crate_name: Symbol,
361 pub needs_crate_name: &'a str,
362 pub deps_crate_name: Symbol,
365 #[derive(SessionDiagnostic)]
366 #[diag(metadata::failed_write_error)]
367 pub struct FailedWriteError {
368 pub filename: PathBuf,
372 #[derive(SessionDiagnostic)]
373 #[diag(metadata::failed_create_tempdir)]
374 pub struct FailedCreateTempdir {
378 #[derive(SessionDiagnostic)]
379 #[diag(metadata::failed_create_file)]
380 pub struct FailedCreateFile<'a> {
381 pub filename: &'a Path,
385 #[derive(SessionDiagnostic)]
386 #[diag(metadata::failed_create_encoded_metadata)]
387 pub struct FailedCreateEncodedMetadata {
391 #[derive(SessionDiagnostic)]
392 #[diag(metadata::non_ascii_name)]
393 pub struct NonAsciiName {
396 pub crate_name: Symbol,
399 #[derive(SessionDiagnostic)]
400 #[diag(metadata::extern_location_not_exist)]
401 pub struct ExternLocationNotExist<'a> {
404 pub crate_name: Symbol,
405 pub location: &'a Path,
408 #[derive(SessionDiagnostic)]
409 #[diag(metadata::extern_location_not_file)]
410 pub struct ExternLocationNotFile<'a> {
413 pub crate_name: Symbol,
414 pub location: &'a Path,
417 pub(crate) struct MultipleCandidates {
419 pub flavor: CrateFlavor,
420 pub crate_name: Symbol,
421 pub candidates: Vec<PathBuf>,
424 impl SessionDiagnostic<'_> for MultipleCandidates {
427 handler: &'_ rustc_errors::Handler,
428 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
429 let mut diag = handler.struct_err(rustc_errors::fluent::metadata::multiple_candidates);
430 diag.set_arg("crate_name", self.crate_name);
431 diag.set_arg("flavor", self.flavor);
432 diag.code(error_code!(E0465));
433 diag.set_span(self.span);
434 for (i, candidate) in self.candidates.iter().enumerate() {
435 diag.span_note(self.span, &format!("candidate #{}: {}", i + 1, candidate.display()));
441 #[derive(SessionDiagnostic)]
442 #[diag(metadata::multiple_matching_crates, code = "E0464")]
444 pub struct MultipleMatchingCrates {
447 pub crate_name: Symbol,
448 pub candidates: String,
451 #[derive(SessionDiagnostic)]
452 #[diag(metadata::symbol_conflicts_current, code = "E0519")]
453 pub struct SymbolConflictsCurrent {
456 pub crate_name: Symbol,
459 #[derive(SessionDiagnostic)]
460 #[diag(metadata::symbol_conflicts_others, code = "E0523")]
461 pub struct SymbolConflictsOthers {
464 pub crate_name: Symbol,
467 #[derive(SessionDiagnostic)]
468 #[diag(metadata::stable_crate_id_collision)]
469 pub struct StableCrateIdCollision {
472 pub crate_name0: Symbol,
473 pub crate_name1: Symbol,
476 #[derive(SessionDiagnostic)]
477 #[diag(metadata::dl_error)]
484 #[derive(SessionDiagnostic)]
485 #[diag(metadata::newer_crate_version, code = "E0460")]
487 #[note(metadata::found_crate_versions)]
488 pub struct NewerCrateVersion {
491 pub crate_name: Symbol,
492 pub add_info: String,
493 pub found_crates: String,
496 #[derive(SessionDiagnostic)]
497 #[diag(metadata::no_crate_with_triple, code = "E0461")]
498 #[note(metadata::found_crate_versions)]
499 pub struct NoCrateWithTriple<'a> {
502 pub crate_name: Symbol,
503 pub locator_triple: &'a str,
504 pub add_info: String,
505 pub found_crates: String,
508 #[derive(SessionDiagnostic)]
509 #[diag(metadata::found_staticlib, code = "E0462")]
510 #[note(metadata::found_crate_versions)]
512 pub struct FoundStaticlib {
515 pub crate_name: Symbol,
516 pub add_info: String,
517 pub found_crates: String,
520 #[derive(SessionDiagnostic)]
521 #[diag(metadata::incompatible_rustc, code = "E0514")]
522 #[note(metadata::found_crate_versions)]
524 pub struct IncompatibleRustc {
527 pub crate_name: Symbol,
528 pub add_info: String,
529 pub found_crates: String,
530 pub rustc_version: String,
533 pub struct InvalidMetadataFiles {
535 pub crate_name: Symbol,
536 pub add_info: String,
537 pub crate_rejections: Vec<String>,
540 impl SessionDiagnostic<'_> for InvalidMetadataFiles {
543 handler: &'_ rustc_errors::Handler,
544 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
545 let mut diag = handler.struct_err(rustc_errors::fluent::metadata::invalid_meta_files);
546 diag.set_arg("crate_name", self.crate_name);
547 diag.set_arg("add_info", self.add_info);
548 diag.code(error_code!(E0786));
549 diag.set_span(self.span);
550 for crate_rejection in self.crate_rejections {
551 diag.note(crate_rejection);
557 pub struct CannotFindCrate {
559 pub crate_name: Symbol,
560 pub add_info: String,
561 pub missing_core: bool,
562 pub current_crate: String,
563 pub is_nightly_build: bool,
564 pub profiler_runtime: Symbol,
565 pub locator_triple: TargetTriple,
568 impl SessionDiagnostic<'_> for CannotFindCrate {
571 handler: &'_ rustc_errors::Handler,
572 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
573 let mut diag = handler.struct_err(rustc_errors::fluent::metadata::cannot_find_crate);
574 diag.set_arg("crate_name", self.crate_name);
575 diag.set_arg("add_info", self.add_info);
576 diag.set_arg("locator_triple", self.locator_triple.triple());
577 diag.code(error_code!(E0463));
578 diag.set_span(self.span);
579 if (self.crate_name == sym::std || self.crate_name == sym::core)
580 && self.locator_triple != TargetTriple::from_triple(config::host_triple())
582 if self.missing_core {
583 diag.note(rustc_errors::fluent::metadata::target_not_installed);
585 diag.note(rustc_errors::fluent::metadata::target_no_std_support);
587 // NOTE: this suggests using rustup, even though the user may not have it installed.
588 // That's because they could choose to install it; or this may give them a hint which
589 // target they need to install from their distro.
590 if self.missing_core {
591 diag.help(rustc_errors::fluent::metadata::consider_downloading_target);
593 // Suggest using #![no_std]. #[no_core] is unstable and not really supported anyway.
594 // NOTE: this is a dummy span if `extern crate std` was injected by the compiler.
595 // If it's not a dummy, that means someone added `extern crate std` explicitly and
596 // `#![no_std]` won't help.
597 if !self.missing_core && self.span.is_dummy() {
598 diag.note(rustc_errors::fluent::metadata::std_required);
600 if self.is_nightly_build {
601 diag.help(rustc_errors::fluent::metadata::consider_building_std);
603 } else if self.crate_name == self.profiler_runtime {
604 diag.note(rustc_errors::fluent::metadata::compiler_missing_profiler);
605 } else if self.crate_name.as_str().starts_with("rustc_") {
606 diag.help(rustc_errors::fluent::metadata::install_missing_components);
608 diag.span_label(self.span, rustc_errors::fluent::metadata::cant_find_crate);
613 #[derive(SessionDiagnostic)]
614 #[diag(metadata::no_dylib_plugin, code = "E0457")]
615 pub struct NoDylibPlugin {
618 pub crate_name: Symbol,
621 #[derive(SessionDiagnostic)]
622 #[diag(metadata::crate_location_unknown_type)]
623 pub struct CrateLocationUnknownType<'a> {
629 #[derive(SessionDiagnostic)]
630 #[diag(metadata::lib_filename_form)]
631 pub struct LibFilenameForm<'a> {
634 pub dll_prefix: &'a str,
635 pub dll_suffix: &'a str,
638 #[derive(SessionDiagnostic)]
639 #[diag(metadata::multiple_import_name_type)]
640 pub struct MultipleImportNameType {
645 #[derive(SessionDiagnostic)]
646 #[diag(metadata::import_name_type_form)]
647 pub struct ImportNameTypeForm {
652 #[derive(SessionDiagnostic)]
653 #[diag(metadata::import_name_type_x86)]
654 pub struct ImportNameTypeX86 {
659 #[derive(SessionDiagnostic)]
660 #[diag(metadata::unknown_import_name_type)]
661 pub struct UnknownImportNameType<'a> {
664 pub import_name_type: &'a str,
667 #[derive(SessionDiagnostic)]
668 #[diag(metadata::import_name_type_raw)]
669 pub struct ImportNameTypeRaw {