Rollup merge of #152115 - GuillaumeGomez:inline-diag-rustc_metadata, r=JonathanBrouwer

Convert to inline diagnostics in `rustc_metadata`

Part of https://github.com/rust-lang/rust/issues/151366.

r? @JonathanBrouwer
This commit is contained in:
Jonathan Brouwer 2026-02-05 08:32:55 +01:00 committed by GitHub
commit 9a2c4cb064
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 182 additions and 344 deletions

View file

@ -4230,7 +4230,6 @@ dependencies = [
"rustc_errors", "rustc_errors",
"rustc_expand", "rustc_expand",
"rustc_feature", "rustc_feature",
"rustc_fluent_macro",
"rustc_fs_util", "rustc_fs_util",
"rustc_hir", "rustc_hir",
"rustc_hir_pretty", "rustc_hir_pretty",

View file

@ -122,7 +122,6 @@ pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[
rustc_errors::DEFAULT_LOCALE_RESOURCE, rustc_errors::DEFAULT_LOCALE_RESOURCE,
rustc_hir_analysis::DEFAULT_LOCALE_RESOURCE, rustc_hir_analysis::DEFAULT_LOCALE_RESOURCE,
rustc_lint::DEFAULT_LOCALE_RESOURCE, rustc_lint::DEFAULT_LOCALE_RESOURCE,
rustc_metadata::DEFAULT_LOCALE_RESOURCE,
rustc_middle::DEFAULT_LOCALE_RESOURCE, rustc_middle::DEFAULT_LOCALE_RESOURCE,
rustc_mir_build::DEFAULT_LOCALE_RESOURCE, rustc_mir_build::DEFAULT_LOCALE_RESOURCE,
rustc_parse::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE,

View file

@ -15,7 +15,6 @@ rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" } rustc_errors = { path = "../rustc_errors" }
rustc_expand = { path = "../rustc_expand" } rustc_expand = { path = "../rustc_expand" }
rustc_feature = { path = "../rustc_feature" } rustc_feature = { path = "../rustc_feature" }
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
rustc_fs_util = { path = "../rustc_fs_util" } rustc_fs_util = { path = "../rustc_fs_util" }
rustc_hir = { path = "../rustc_hir" } rustc_hir = { path = "../rustc_hir" }
rustc_hir_pretty = { path = "../rustc_hir_pretty" } rustc_hir_pretty = { path = "../rustc_hir_pretty" }

View file

@ -1,240 +0,0 @@
metadata_async_drop_types_in_dependency =
found async drop types in dependency `{$extern_crate}`, but async_drop feature is disabled for `{$local_crate}`
.help = if async drop type will be dropped in a crate without `feature(async_drop)`, sync Drop will be used
metadata_bad_panic_strategy =
the linked panic runtime `{$runtime}` is not compiled with this crate's panic strategy `{$strategy}`
metadata_binary_output_to_tty =
option `-o` or `--emit` is used to write binary output type `metadata` to stdout, but stdout is a tty
metadata_cannot_find_crate =
can't find crate for `{$crate_name}`{$add_info}
metadata_cant_find_crate =
can't find crate
metadata_compiler_missing_profiler =
the compiler may have been built without the profiler runtime
metadata_conflicting_alloc_error_handler =
the `#[alloc_error_handler]` in {$other_crate_name} conflicts with allocation error handler in: {$crate_name}
metadata_conflicting_global_alloc =
the `#[global_allocator]` in {$other_crate_name} conflicts with global allocator in: {$crate_name}
metadata_consider_adding_std =
consider adding the standard library to the sysroot with `x build library --target {$locator_triple}`
metadata_consider_building_std =
consider building the standard library from source with `cargo build -Zbuild-std`
metadata_consider_downloading_target =
consider downloading the target with `rustup target add {$locator_triple}`
metadata_crate_dep_multiple =
cannot satisfy dependencies so `{$crate_name}` only shows up once
.help = having upstream crates all available in one format will likely make this go away
metadata_crate_dep_not_static =
`{$crate_name}` was unavailable as a static crate, preventing fully static linking
metadata_crate_dep_rustc_driver =
`feature(rustc_private)` is needed to link to the compiler's `rustc_driver` library
metadata_crate_location_unknown_type =
extern location for {$crate_name} is of an unknown type: {$path}
metadata_crate_not_compiler_builtins =
the crate `{$crate_name}` resolved as `compiler_builtins` but is not `#![compiler_builtins]`
metadata_crate_not_panic_runtime =
the crate `{$crate_name}` is not a panic runtime
metadata_dl_error =
{$path}{$err}
metadata_empty_renaming_target =
an empty renaming target was specified for library `{$lib_name}`
metadata_extern_location_not_exist =
extern location for {$crate_name} does not exist: {$location}
metadata_extern_location_not_file =
extern location for {$crate_name} is not a file: {$location}
metadata_fail_create_file_encoder =
failed to create file encoder: {$err}
metadata_fail_write_file =
failed to write to `{$path}`: {$err}
metadata_failed_copy_to_stdout =
failed to copy {$filename} to stdout: {$err}
metadata_failed_create_encoded_metadata =
failed to create encoded metadata from file: {$err}
metadata_failed_create_file =
failed to create the file {$filename}: {$err}
metadata_failed_create_tempdir =
couldn't create a temp dir: {$err}
metadata_failed_write_error =
failed to write {$filename}: {$err}
metadata_found_crate_versions =
the following crate versions were found:{$found_crates}
metadata_found_staticlib =
found staticlib `{$crate_name}` instead of rlib or dylib{$add_info}
.help = please recompile that crate using --crate-type lib
metadata_full_metadata_not_found =
only metadata stub found for `{$flavor}` dependency `{$crate_name}`
please provide path to the corresponding .rmeta file with full metadata
metadata_global_alloc_required =
no global memory allocator found but one is required; link to std or add `#[global_allocator]` to a static item that implements the GlobalAlloc trait
metadata_incompatible_panic_in_drop_strategy =
the crate `{$crate_name}` is compiled with the panic-in-drop strategy `{$found_strategy}` which is incompatible with this crate's strategy of `{$desired_strategy}`
metadata_incompatible_rustc =
found crate `{$crate_name}` compiled by an incompatible version of rustc{$add_info}
.help = please recompile that crate using this compiler ({$rustc_version}) (consider running `cargo clean` first)
metadata_incompatible_target_modifiers =
mixing `{$flag_name_prefixed}` will cause an ABI mismatch in crate `{$local_crate}`
.note = `{$flag_name_prefixed}={$local_value}` in this crate is incompatible with `{$flag_name_prefixed}={$extern_value}` in dependency `{$extern_crate}`
.help = the `{$flag_name_prefixed}` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely
metadata_incompatible_target_modifiers_help_allow = if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch={$flag_name}` to silence this error
metadata_incompatible_target_modifiers_help_fix = set `{$flag_name_prefixed}={$extern_value}` in this crate or `{$flag_name_prefixed}={$local_value}` in `{$extern_crate}`
metadata_incompatible_target_modifiers_help_fix_l_missed = set `{$flag_name_prefixed}={$extern_value}` in this crate or unset `{$flag_name_prefixed}` in `{$extern_crate}`
metadata_incompatible_target_modifiers_help_fix_r_missed = unset `{$flag_name_prefixed}` in this crate or set `{$flag_name_prefixed}={$local_value}` in `{$extern_crate}`
metadata_incompatible_target_modifiers_l_missed =
mixing `{$flag_name_prefixed}` will cause an ABI mismatch in crate `{$local_crate}`
.note = unset `{$flag_name_prefixed}` in this crate is incompatible with `{$flag_name_prefixed}={$extern_value}` in dependency `{$extern_crate}`
.help = the `{$flag_name_prefixed}` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely
metadata_incompatible_target_modifiers_r_missed =
mixing `{$flag_name_prefixed}` will cause an ABI mismatch in crate `{$local_crate}`
.note = `{$flag_name_prefixed}={$local_value}` in this crate is incompatible with unset `{$flag_name_prefixed}` in dependency `{$extern_crate}`
.help = the `{$flag_name_prefixed}` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely
metadata_incompatible_with_immediate_abort =
the crate `{$crate_name}` was compiled with a panic strategy which is incompatible with `immediate-abort`
metadata_incompatible_with_immediate_abort_core =
the crate `core` was compiled with a panic strategy which is incompatible with `immediate-abort`
.help = consider building the standard library from source with `cargo build -Zbuild-std`
metadata_install_missing_components =
maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`
metadata_invalid_meta_files =
found invalid metadata files for crate `{$crate_name}`{$add_info}
metadata_lib_filename_form =
file name should be lib*.rlib or {$dll_prefix}*{$dll_suffix}
metadata_lib_framework_apple =
library kind `framework` is only supported on Apple targets
metadata_lib_required =
crate `{$crate_name}` required to be available in {$kind} format, but was not found in this form
metadata_link_ordinal_raw_dylib =
`#[link_ordinal]` is only supported if link kind is `raw-dylib`
metadata_missing_native_library =
could not find native static library `{$libname}`, perhaps an -L flag is missing?
metadata_multiple_candidates =
multiple candidates for `{$flavor}` dependency `{$crate_name}` found
metadata_multiple_renamings =
multiple renamings were specified for library `{$lib_name}`
metadata_newer_crate_version =
found possibly newer version of crate `{$crate_name}`{$add_info}
.note = perhaps that crate needs to be recompiled?
metadata_no_crate_with_triple =
couldn't find crate `{$crate_name}` with expected target triple {$locator_triple}{$add_info}
metadata_no_link_mod_override =
overriding linking modifiers from command line is not supported
metadata_no_multiple_alloc_error_handler =
cannot define multiple allocation error handlers
.label = cannot define a new allocation error handler
metadata_no_multiple_global_alloc =
cannot define multiple global allocators
.label = cannot define a new global allocator
metadata_no_panic_strategy =
the crate `{$crate_name}` does not have the panic strategy `{$strategy}`
metadata_no_transitive_needs_dep =
the crate `{$crate_name}` cannot depend on a crate that needs {$needs_crate_name}, but it depends on `{$deps_crate_name}`
metadata_non_ascii_name =
cannot load a crate with a non-ascii name `{$crate_name}`
metadata_not_profiler_runtime =
the crate `{$crate_name}` is not a profiler runtime
metadata_only_provide_library_name = only provide the library name `{$suggested_name}`, not the full filename
metadata_prev_alloc_error_handler =
previous allocation error handler defined here
metadata_prev_global_alloc =
previous global allocator defined here
metadata_raw_dylib_malformed =
link name must be well-formed if link kind is `raw-dylib`
metadata_raw_dylib_unsupported_abi =
ABI not supported by `#[link(kind = "raw-dylib")]` on this architecture
metadata_renaming_no_link =
renaming of the library `{$lib_name}` was specified, however this crate contains no `#[link(...)]` attributes referencing this library
metadata_required_panic_strategy =
the crate `{$crate_name}` requires panic strategy `{$found_strategy}` which is incompatible with this crate's strategy of `{$desired_strategy}`
metadata_rlib_required =
crate `{$crate_name}` required to be available in rlib format, but was not found in this form
metadata_rustc_lib_required =
crate `{$crate_name}` required to be available in {$kind} format, but was not found in this form
.note = only .rmeta files are distributed for `rustc_private` crates other than `rustc_driver`
.help = try adding `extern crate rustc_driver;` at the top level of this crate
metadata_stable_crate_id_collision =
found crates (`{$crate_name0}` and `{$crate_name1}`) with colliding StableCrateId values
metadata_std_required =
`std` is required by `{$current_crate}` because it does not declare `#![no_std]`
metadata_symbol_conflicts_current =
the current crate is indistinguishable from one of its dependencies: it has the same crate-name `{$crate_name}` and was compiled with the same `-C metadata` arguments, so this will result in symbol conflicts between the two
metadata_target_no_std_support =
the `{$locator_triple}` target may not support the standard library
metadata_target_not_installed =
the `{$locator_triple}` target may not be installed
metadata_two_panic_runtimes =
cannot link together two panic runtimes: {$prev_name} and {$cur_name}
metadata_unknown_target_modifier_unsafe_allowed = unknown target modifier `{$flag_name}`, requested by `-Cunsafe-allow-abi-mismatch={$flag_name}`
metadata_wasm_c_abi =
older versions of the `wasm-bindgen` crate are incompatible with current versions of Rust; please update to `wasm-bindgen` v0.2.88

View file

@ -2,38 +2,43 @@ use std::io::Error;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use rustc_errors::codes::*; use rustc_errors::codes::*;
use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level}; use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, inline_fluent};
use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{Span, Symbol, sym}; use rustc_span::{Span, Symbol, sym};
use rustc_target::spec::{PanicStrategy, TargetTuple}; use rustc_target::spec::{PanicStrategy, TargetTuple};
use crate::fluent_generated as fluent;
use crate::locator::CrateFlavor; use crate::locator::CrateFlavor;
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_rlib_required)] #[diag(
"crate `{$crate_name}` required to be available in rlib format, but was not found in this form"
)]
pub struct RlibRequired { pub struct RlibRequired {
pub crate_name: Symbol, pub crate_name: Symbol,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_lib_required)] #[diag(
"crate `{$crate_name}` required to be available in {$kind} format, but was not found in this form"
)]
pub struct LibRequired<'a> { pub struct LibRequired<'a> {
pub crate_name: Symbol, pub crate_name: Symbol,
pub kind: &'a str, pub kind: &'a str,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_rustc_lib_required)] #[diag(
#[help] "crate `{$crate_name}` required to be available in {$kind} format, but was not found in this form"
)]
#[help("try adding `extern crate rustc_driver;` at the top level of this crate")]
pub struct RustcLibRequired<'a> { pub struct RustcLibRequired<'a> {
pub crate_name: Symbol, pub crate_name: Symbol,
pub kind: &'a str, pub kind: &'a str,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_crate_dep_multiple)] #[diag("cannot satisfy dependencies so `{$crate_name}` only shows up once")]
#[help] #[help("having upstream crates all available in one format will likely make this go away")]
pub struct CrateDepMultiple { pub struct CrateDepMultiple {
pub crate_name: Symbol, pub crate_name: Symbol,
#[subdiagnostic] #[subdiagnostic]
@ -43,32 +48,36 @@ pub struct CrateDepMultiple {
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[note(metadata_crate_dep_not_static)] #[note("`{$crate_name}` was unavailable as a static crate, preventing fully static linking")]
pub struct NonStaticCrateDep { pub struct NonStaticCrateDep {
/// It's different from `crate_name` in main Diagnostic. /// It's different from `crate_name` in main Diagnostic.
pub crate_name_: Symbol, pub crate_name_: Symbol,
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[help(metadata_crate_dep_rustc_driver)] #[help("`feature(rustc_private)` is needed to link to the compiler's `rustc_driver` library")]
pub struct RustcDriverHelp; pub struct RustcDriverHelp;
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_two_panic_runtimes)] #[diag("cannot link together two panic runtimes: {$prev_name} and {$cur_name}")]
pub struct TwoPanicRuntimes { pub struct TwoPanicRuntimes {
pub prev_name: Symbol, pub prev_name: Symbol,
pub cur_name: Symbol, pub cur_name: Symbol,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_bad_panic_strategy)] #[diag(
"the linked panic runtime `{$runtime}` is not compiled with this crate's panic strategy `{$strategy}`"
)]
pub struct BadPanicStrategy { pub struct BadPanicStrategy {
pub runtime: Symbol, pub runtime: Symbol,
pub strategy: PanicStrategy, pub strategy: PanicStrategy,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_required_panic_strategy)] #[diag(
"the crate `{$crate_name}` requires panic strategy `{$found_strategy}` which is incompatible with this crate's strategy of `{$desired_strategy}`"
)]
pub struct RequiredPanicStrategy { pub struct RequiredPanicStrategy {
pub crate_name: Symbol, pub crate_name: Symbol,
pub found_strategy: PanicStrategy, pub found_strategy: PanicStrategy,
@ -76,17 +85,23 @@ pub struct RequiredPanicStrategy {
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_incompatible_with_immediate_abort)] #[diag(
"the crate `{$crate_name}` was compiled with a panic strategy which is incompatible with `immediate-abort`"
)]
pub struct IncompatibleWithImmediateAbort { pub struct IncompatibleWithImmediateAbort {
pub crate_name: Symbol, pub crate_name: Symbol,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_incompatible_with_immediate_abort_core)] #[diag(
"the crate `core` was compiled with a panic strategy which is incompatible with `immediate-abort`"
)]
pub struct IncompatibleWithImmediateAbortCore; pub struct IncompatibleWithImmediateAbortCore;
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_incompatible_panic_in_drop_strategy)] #[diag(
"the crate `{$crate_name}` is compiled with the panic-in-drop strategy `{$found_strategy}` which is incompatible with this crate's strategy of `{$desired_strategy}`"
)]
pub struct IncompatiblePanicInDropStrategy { pub struct IncompatiblePanicInDropStrategy {
pub crate_name: Symbol, pub crate_name: Symbol,
pub found_strategy: PanicStrategy, pub found_strategy: PanicStrategy,
@ -94,126 +109,138 @@ pub struct IncompatiblePanicInDropStrategy {
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_link_ordinal_raw_dylib)] #[diag("`#[link_ordinal]` is only supported if link kind is `raw-dylib`")]
pub struct LinkOrdinalRawDylib { pub struct LinkOrdinalRawDylib {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_lib_framework_apple)] #[diag("library kind `framework` is only supported on Apple targets")]
pub struct LibFrameworkApple; pub struct LibFrameworkApple;
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_empty_renaming_target)] #[diag("an empty renaming target was specified for library `{$lib_name}`")]
pub struct EmptyRenamingTarget<'a> { pub struct EmptyRenamingTarget<'a> {
pub lib_name: &'a str, pub lib_name: &'a str,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_renaming_no_link)] #[diag(
"renaming of the library `{$lib_name}` was specified, however this crate contains no `#[link(...)]` attributes referencing this library"
)]
pub struct RenamingNoLink<'a> { pub struct RenamingNoLink<'a> {
pub lib_name: &'a str, pub lib_name: &'a str,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_multiple_renamings)] #[diag("multiple renamings were specified for library `{$lib_name}`")]
pub struct MultipleRenamings<'a> { pub struct MultipleRenamings<'a> {
pub lib_name: &'a str, pub lib_name: &'a str,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_no_link_mod_override)] #[diag("overriding linking modifiers from command line is not supported")]
pub struct NoLinkModOverride { pub struct NoLinkModOverride {
#[primary_span] #[primary_span]
pub span: Option<Span>, pub span: Option<Span>,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_raw_dylib_unsupported_abi)] #[diag("ABI not supported by `#[link(kind = \"raw-dylib\")]` on this architecture")]
pub struct RawDylibUnsupportedAbi { pub struct RawDylibUnsupportedAbi {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_fail_create_file_encoder)] #[diag("failed to create file encoder: {$err}")]
pub struct FailCreateFileEncoder { pub struct FailCreateFileEncoder {
pub err: Error, pub err: Error,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_fail_write_file)] #[diag("failed to write to `{$path}`: {$err}")]
pub struct FailWriteFile<'a> { pub struct FailWriteFile<'a> {
pub path: &'a Path, pub path: &'a Path,
pub err: Error, pub err: Error,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_crate_not_panic_runtime)] #[diag("the crate `{$crate_name}` is not a panic runtime")]
pub struct CrateNotPanicRuntime { pub struct CrateNotPanicRuntime {
pub crate_name: Symbol, pub crate_name: Symbol,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_crate_not_compiler_builtins)] #[diag(
"the crate `{$crate_name}` resolved as `compiler_builtins` but is not `#![compiler_builtins]`"
)]
pub struct CrateNotCompilerBuiltins { pub struct CrateNotCompilerBuiltins {
pub crate_name: Symbol, pub crate_name: Symbol,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_no_panic_strategy)] #[diag("the crate `{$crate_name}` does not have the panic strategy `{$strategy}`")]
pub struct NoPanicStrategy { pub struct NoPanicStrategy {
pub crate_name: Symbol, pub crate_name: Symbol,
pub strategy: PanicStrategy, pub strategy: PanicStrategy,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_not_profiler_runtime)] #[diag("the crate `{$crate_name}` is not a profiler runtime")]
pub struct NotProfilerRuntime { pub struct NotProfilerRuntime {
pub crate_name: Symbol, pub crate_name: Symbol,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_no_multiple_global_alloc)] #[diag("cannot define multiple global allocators")]
pub struct NoMultipleGlobalAlloc { pub struct NoMultipleGlobalAlloc {
#[primary_span] #[primary_span]
#[label] #[label("cannot define a new global allocator")]
pub span2: Span, pub span2: Span,
#[label(metadata_prev_global_alloc)] #[label("previous global allocator defined here")]
pub span1: Span, pub span1: Span,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_no_multiple_alloc_error_handler)] #[diag("cannot define multiple allocation error handlers")]
pub struct NoMultipleAllocErrorHandler { pub struct NoMultipleAllocErrorHandler {
#[primary_span] #[primary_span]
#[label] #[label("cannot define a new allocation error handler")]
pub span2: Span, pub span2: Span,
#[label(metadata_prev_alloc_error_handler)] #[label("previous allocation error handler defined here")]
pub span1: Span, pub span1: Span,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_conflicting_global_alloc)] #[diag(
"the `#[global_allocator]` in {$other_crate_name} conflicts with global allocator in: {$crate_name}"
)]
pub struct ConflictingGlobalAlloc { pub struct ConflictingGlobalAlloc {
pub crate_name: Symbol, pub crate_name: Symbol,
pub other_crate_name: Symbol, pub other_crate_name: Symbol,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_conflicting_alloc_error_handler)] #[diag(
"the `#[alloc_error_handler]` in {$other_crate_name} conflicts with allocation error handler in: {$crate_name}"
)]
pub struct ConflictingAllocErrorHandler { pub struct ConflictingAllocErrorHandler {
pub crate_name: Symbol, pub crate_name: Symbol,
pub other_crate_name: Symbol, pub other_crate_name: Symbol,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_global_alloc_required)] #[diag(
"no global memory allocator found but one is required; link to std or add `#[global_allocator]` to a static item that implements the GlobalAlloc trait"
)]
pub struct GlobalAllocRequired; pub struct GlobalAllocRequired;
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_no_transitive_needs_dep)] #[diag(
"the crate `{$crate_name}` cannot depend on a crate that needs {$needs_crate_name}, but it depends on `{$deps_crate_name}`"
)]
pub struct NoTransitiveNeedsDep<'a> { pub struct NoTransitiveNeedsDep<'a> {
pub crate_name: Symbol, pub crate_name: Symbol,
pub needs_crate_name: &'a str, pub needs_crate_name: &'a str,
@ -221,25 +248,27 @@ pub struct NoTransitiveNeedsDep<'a> {
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_failed_write_error)] #[diag("failed to write {$filename}: {$err}")]
pub struct FailedWriteError { pub struct FailedWriteError {
pub filename: PathBuf, pub filename: PathBuf,
pub err: Error, pub err: Error,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_failed_copy_to_stdout)] #[diag("failed to copy {$filename} to stdout: {$err}")]
pub struct FailedCopyToStdout { pub struct FailedCopyToStdout {
pub filename: PathBuf, pub filename: PathBuf,
pub err: Error, pub err: Error,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_binary_output_to_tty)] #[diag(
"option `-o` or `--emit` is used to write binary output type `metadata` to stdout, but stdout is a tty"
)]
pub struct BinaryOutputToTty; pub struct BinaryOutputToTty;
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_missing_native_library)] #[diag("could not find native static library `{$libname}`, perhaps an -L flag is missing?")]
pub struct MissingNativeLibrary<'a> { pub struct MissingNativeLibrary<'a> {
libname: &'a str, libname: &'a str,
#[subdiagnostic] #[subdiagnostic]
@ -273,32 +302,32 @@ impl<'a> MissingNativeLibrary<'a> {
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[help(metadata_only_provide_library_name)] #[help("only provide the library name `{$suggested_name}`, not the full filename")]
pub struct SuggestLibraryName<'a> { pub struct SuggestLibraryName<'a> {
suggested_name: &'a str, suggested_name: &'a str,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_failed_create_tempdir)] #[diag("couldn't create a temp dir: {$err}")]
pub struct FailedCreateTempdir { pub struct FailedCreateTempdir {
pub err: Error, pub err: Error,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_failed_create_file)] #[diag("failed to create the file {$filename}: {$err}")]
pub struct FailedCreateFile<'a> { pub struct FailedCreateFile<'a> {
pub filename: &'a Path, pub filename: &'a Path,
pub err: Error, pub err: Error,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_failed_create_encoded_metadata)] #[diag("failed to create encoded metadata from file: {$err}")]
pub struct FailedCreateEncodedMetadata { pub struct FailedCreateEncodedMetadata {
pub err: Error, pub err: Error,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_non_ascii_name)] #[diag("cannot load a crate with a non-ascii name `{$crate_name}`")]
pub struct NonAsciiName { pub struct NonAsciiName {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
@ -306,7 +335,7 @@ pub struct NonAsciiName {
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_extern_location_not_exist)] #[diag("extern location for {$crate_name} does not exist: {$location}")]
pub struct ExternLocationNotExist<'a> { pub struct ExternLocationNotExist<'a> {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
@ -315,7 +344,7 @@ pub struct ExternLocationNotExist<'a> {
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_extern_location_not_file)] #[diag("extern location for {$crate_name} is not a file: {$location}")]
pub struct ExternLocationNotFile<'a> { pub struct ExternLocationNotFile<'a> {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
@ -332,7 +361,11 @@ pub(crate) struct MultipleCandidates {
impl<G: EmissionGuarantee> Diagnostic<'_, G> for MultipleCandidates { impl<G: EmissionGuarantee> Diagnostic<'_, G> for MultipleCandidates {
fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> { fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
let mut diag = Diag::new(dcx, level, fluent::metadata_multiple_candidates); let mut diag = Diag::new(
dcx,
level,
inline_fluent!("multiple candidates for `{$flavor}` dependency `{$crate_name}` found"),
);
diag.arg("crate_name", self.crate_name); diag.arg("crate_name", self.crate_name);
diag.arg("flavor", self.flavor); diag.arg("flavor", self.flavor);
diag.code(E0464); diag.code(E0464);
@ -345,7 +378,9 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for MultipleCandidates {
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_full_metadata_not_found)] #[diag(
"only metadata stub found for `{$flavor}` dependency `{$crate_name}` please provide path to the corresponding .rmeta file with full metadata"
)]
pub(crate) struct FullMetadataNotFound { pub(crate) struct FullMetadataNotFound {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
@ -354,7 +389,7 @@ pub(crate) struct FullMetadataNotFound {
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_symbol_conflicts_current, code = E0519)] #[diag("the current crate is indistinguishable from one of its dependencies: it has the same crate-name `{$crate_name}` and was compiled with the same `-C metadata` arguments, so this will result in symbol conflicts between the two", code = E0519)]
pub struct SymbolConflictsCurrent { pub struct SymbolConflictsCurrent {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
@ -362,7 +397,7 @@ pub struct SymbolConflictsCurrent {
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_stable_crate_id_collision)] #[diag("found crates (`{$crate_name0}` and `{$crate_name1}`) with colliding StableCrateId values")]
pub struct StableCrateIdCollision { pub struct StableCrateIdCollision {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
@ -371,7 +406,7 @@ pub struct StableCrateIdCollision {
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_dl_error)] #[diag("{$path}{$err}")]
pub struct DlError { pub struct DlError {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
@ -380,9 +415,9 @@ pub struct DlError {
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_newer_crate_version, code = E0460)] #[diag("found possibly newer version of crate `{$crate_name}`{$add_info}", code = E0460)]
#[note] #[note("perhaps that crate needs to be recompiled?")]
#[note(metadata_found_crate_versions)] #[note("the following crate versions were found:{$found_crates}")]
pub struct NewerCrateVersion { pub struct NewerCrateVersion {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
@ -392,8 +427,8 @@ pub struct NewerCrateVersion {
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_no_crate_with_triple, code = E0461)] #[diag("couldn't find crate `{$crate_name}` with expected target triple {$locator_triple}{$add_info}", code = E0461)]
#[note(metadata_found_crate_versions)] #[note("the following crate versions were found:{$found_crates}")]
pub struct NoCrateWithTriple<'a> { pub struct NoCrateWithTriple<'a> {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
@ -404,9 +439,9 @@ pub struct NoCrateWithTriple<'a> {
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_found_staticlib, code = E0462)] #[diag("found staticlib `{$crate_name}` instead of rlib or dylib{$add_info}", code = E0462)]
#[note(metadata_found_crate_versions)] #[note("the following crate versions were found:{$found_crates}")]
#[help] #[help("please recompile that crate using --crate-type lib")]
pub struct FoundStaticlib { pub struct FoundStaticlib {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
@ -416,9 +451,11 @@ pub struct FoundStaticlib {
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_incompatible_rustc, code = E0514)] #[diag("found crate `{$crate_name}` compiled by an incompatible version of rustc{$add_info}", code = E0514)]
#[note(metadata_found_crate_versions)] #[note("the following crate versions were found:{$found_crates}")]
#[help] #[help(
"please recompile that crate using this compiler ({$rustc_version}) (consider running `cargo clean` first)"
)]
pub struct IncompatibleRustc { pub struct IncompatibleRustc {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
@ -438,7 +475,11 @@ pub struct InvalidMetadataFiles {
impl<G: EmissionGuarantee> Diagnostic<'_, G> for InvalidMetadataFiles { impl<G: EmissionGuarantee> Diagnostic<'_, G> for InvalidMetadataFiles {
#[track_caller] #[track_caller]
fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> { fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
let mut diag = Diag::new(dcx, level, fluent::metadata_invalid_meta_files); let mut diag = Diag::new(
dcx,
level,
inline_fluent!("found invalid metadata files for crate `{$crate_name}`{$add_info}"),
);
diag.arg("crate_name", self.crate_name); diag.arg("crate_name", self.crate_name);
diag.arg("add_info", self.add_info); diag.arg("add_info", self.add_info);
diag.code(E0786); diag.code(E0786);
@ -466,7 +507,11 @@ pub struct CannotFindCrate {
impl<G: EmissionGuarantee> Diagnostic<'_, G> for CannotFindCrate { impl<G: EmissionGuarantee> Diagnostic<'_, G> for CannotFindCrate {
#[track_caller] #[track_caller]
fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> { fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
let mut diag = Diag::new(dcx, level, fluent::metadata_cannot_find_crate); let mut diag = Diag::new(
dcx,
level,
inline_fluent!("can't find crate for `{$crate_name}`{$add_info}"),
);
diag.arg("crate_name", self.crate_name); diag.arg("crate_name", self.crate_name);
diag.arg("current_crate", self.current_crate); diag.arg("current_crate", self.current_crate);
diag.arg("add_info", self.add_info); diag.arg("add_info", self.add_info);
@ -475,9 +520,11 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for CannotFindCrate {
diag.span(self.span); diag.span(self.span);
if self.crate_name == sym::std || self.crate_name == sym::core { if self.crate_name == sym::std || self.crate_name == sym::core {
if self.missing_core { if self.missing_core {
diag.note(fluent::metadata_target_not_installed); diag.note(inline_fluent!("the `{$locator_triple}` target may not be installed"));
} else { } else {
diag.note(fluent::metadata_target_no_std_support); diag.note(inline_fluent!(
"the `{$locator_triple}` target may not support the standard library"
));
} }
let has_precompiled_std = !self.is_tier_3; let has_precompiled_std = !self.is_tier_3;
@ -485,12 +532,14 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for CannotFindCrate {
if self.missing_core { if self.missing_core {
if env!("CFG_RELEASE_CHANNEL") == "dev" && !self.is_ui_testing { if env!("CFG_RELEASE_CHANNEL") == "dev" && !self.is_ui_testing {
// Note: Emits the nicer suggestion only for the dev channel. // Note: Emits the nicer suggestion only for the dev channel.
diag.help(fluent::metadata_consider_adding_std); diag.help(inline_fluent!("consider adding the standard library to the sysroot with `x build library --target {$locator_triple}`"));
} else if has_precompiled_std { } else if has_precompiled_std {
// NOTE: this suggests using rustup, even though the user may not have it installed. // NOTE: this suggests using rustup, even though the user may not have it installed.
// That's because they could choose to install it; or this may give them a hint which // That's because they could choose to install it; or this may give them a hint which
// target they need to install from their distro. // target they need to install from their distro.
diag.help(fluent::metadata_consider_downloading_target); diag.help(inline_fluent!(
"consider downloading the target with `rustup target add {$locator_triple}`"
));
} }
} }
@ -499,25 +548,27 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for CannotFindCrate {
// If it's not a dummy, that means someone added `extern crate std` explicitly and // If it's not a dummy, that means someone added `extern crate std` explicitly and
// `#![no_std]` won't help. // `#![no_std]` won't help.
if !self.missing_core && self.span.is_dummy() { if !self.missing_core && self.span.is_dummy() {
diag.note(fluent::metadata_std_required); diag.note(inline_fluent!("`std` is required by `{$current_crate}` because it does not declare `#![no_std]`"));
} }
// Recommend -Zbuild-std even on stable builds for Tier 3 targets because // Recommend -Zbuild-std even on stable builds for Tier 3 targets because
// it's the recommended way to use the target, the user should switch to nightly. // it's the recommended way to use the target, the user should switch to nightly.
if self.is_nightly_build || !has_precompiled_std { if self.is_nightly_build || !has_precompiled_std {
diag.help(fluent::metadata_consider_building_std); diag.help(inline_fluent!("consider building the standard library from source with `cargo build -Zbuild-std`"));
} }
} else if self.crate_name == self.profiler_runtime { } else if self.crate_name == self.profiler_runtime {
diag.note(fluent::metadata_compiler_missing_profiler); diag.note(inline_fluent!(
"the compiler may have been built without the profiler runtime"
));
} else if self.crate_name.as_str().starts_with("rustc_") { } else if self.crate_name.as_str().starts_with("rustc_") {
diag.help(fluent::metadata_install_missing_components); diag.help(inline_fluent!("maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`"));
} }
diag.span_label(self.span, fluent::metadata_cant_find_crate); diag.span_label(self.span, inline_fluent!("can't find crate"));
diag diag
} }
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_crate_location_unknown_type)] #[diag("extern location for {$crate_name} is of an unknown type: {$path}")]
pub struct CrateLocationUnknownType<'a> { pub struct CrateLocationUnknownType<'a> {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
@ -526,7 +577,7 @@ pub struct CrateLocationUnknownType<'a> {
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_lib_filename_form)] #[diag("file name should be lib*.rlib or {$dll_prefix}*{$dll_suffix}")]
pub struct LibFilenameForm<'a> { pub struct LibFilenameForm<'a> {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
@ -535,18 +586,28 @@ pub struct LibFilenameForm<'a> {
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_wasm_c_abi)] #[diag(
"older versions of the `wasm-bindgen` crate are incompatible with current versions of Rust; please update to `wasm-bindgen` v0.2.88"
)]
pub(crate) struct WasmCAbi { pub(crate) struct WasmCAbi {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_incompatible_target_modifiers)] #[diag("mixing `{$flag_name_prefixed}` will cause an ABI mismatch in crate `{$local_crate}`")]
#[help] #[help(
#[note] "the `{$flag_name_prefixed}` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely"
#[help(metadata_incompatible_target_modifiers_help_fix)] )]
#[help(metadata_incompatible_target_modifiers_help_allow)] #[note(
"`{$flag_name_prefixed}={$local_value}` in this crate is incompatible with `{$flag_name_prefixed}={$extern_value}` in dependency `{$extern_crate}`"
)]
#[help(
"set `{$flag_name_prefixed}={$extern_value}` in this crate or `{$flag_name_prefixed}={$local_value}` in `{$extern_crate}`"
)]
#[help(
"if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch={$flag_name}` to silence this error"
)]
pub struct IncompatibleTargetModifiers { pub struct IncompatibleTargetModifiers {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
@ -559,11 +620,19 @@ pub struct IncompatibleTargetModifiers {
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_incompatible_target_modifiers_l_missed)] #[diag("mixing `{$flag_name_prefixed}` will cause an ABI mismatch in crate `{$local_crate}`")]
#[help] #[help(
#[note] "the `{$flag_name_prefixed}` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely"
#[help(metadata_incompatible_target_modifiers_help_fix_l_missed)] )]
#[help(metadata_incompatible_target_modifiers_help_allow)] #[note(
"unset `{$flag_name_prefixed}` in this crate is incompatible with `{$flag_name_prefixed}={$extern_value}` in dependency `{$extern_crate}`"
)]
#[help(
"set `{$flag_name_prefixed}={$extern_value}` in this crate or unset `{$flag_name_prefixed}` in `{$extern_crate}`"
)]
#[help(
"if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch={$flag_name}` to silence this error"
)]
pub struct IncompatibleTargetModifiersLMissed { pub struct IncompatibleTargetModifiersLMissed {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
@ -575,11 +644,19 @@ pub struct IncompatibleTargetModifiersLMissed {
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_incompatible_target_modifiers_r_missed)] #[diag("mixing `{$flag_name_prefixed}` will cause an ABI mismatch in crate `{$local_crate}`")]
#[help] #[help(
#[note] "the `{$flag_name_prefixed}` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely"
#[help(metadata_incompatible_target_modifiers_help_fix_r_missed)] )]
#[help(metadata_incompatible_target_modifiers_help_allow)] #[note(
"`{$flag_name_prefixed}={$local_value}` in this crate is incompatible with unset `{$flag_name_prefixed}` in dependency `{$extern_crate}`"
)]
#[help(
"unset `{$flag_name_prefixed}` in this crate or set `{$flag_name_prefixed}={$local_value}` in `{$extern_crate}`"
)]
#[help(
"if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch={$flag_name}` to silence this error"
)]
pub struct IncompatibleTargetModifiersRMissed { pub struct IncompatibleTargetModifiersRMissed {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
@ -591,7 +668,9 @@ pub struct IncompatibleTargetModifiersRMissed {
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_unknown_target_modifier_unsafe_allowed)] #[diag(
"unknown target modifier `{$flag_name}`, requested by `-Cunsafe-allow-abi-mismatch={$flag_name}`"
)]
pub struct UnknownTargetModifierUnsafeAllowed { pub struct UnknownTargetModifierUnsafeAllowed {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
@ -599,8 +678,12 @@ pub struct UnknownTargetModifierUnsafeAllowed {
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_async_drop_types_in_dependency)] #[diag(
#[help] "found async drop types in dependency `{$extern_crate}`, but async_drop feature is disabled for `{$local_crate}`"
)]
#[help(
"if async drop type will be dropped in a crate without `feature(async_drop)`, sync Drop will be used"
)]
pub struct AsyncDropTypesInDependency { pub struct AsyncDropTypesInDependency {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
@ -609,7 +692,7 @@ pub struct AsyncDropTypesInDependency {
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(metadata_raw_dylib_malformed)] #[diag("link name must be well-formed if link kind is `raw-dylib`")]
pub struct RawDylibMalformed { pub struct RawDylibMalformed {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,

View file

@ -34,5 +34,3 @@ pub use native_libs::{
try_find_native_static_library, walk_native_lib_search_dirs, try_find_native_static_library, walk_native_lib_search_dirs,
}; };
pub use rmeta::{EncodedMetadata, METADATA_HEADER, encode_metadata, rendered_const}; pub use rmeta::{EncodedMetadata, METADATA_HEADER, encode_metadata, rendered_const};
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }