diff --git a/Cargo.lock b/Cargo.lock index d4c1a02c018a..4426ad75eee9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3504,6 +3504,7 @@ dependencies = [ "rand_xoshiro", "rustc_data_structures", "rustc_error_messages", + "rustc_errors", "rustc_hashes", "rustc_index", "rustc_macros", @@ -3908,7 +3909,6 @@ dependencies = [ "anstream", "anstyle", "derive_setters", - "rustc_abi", "rustc_ast", "rustc_data_structures", "rustc_error_codes", diff --git a/compiler/rustc_abi/Cargo.toml b/compiler/rustc_abi/Cargo.toml index 83d96d8d04da..13e0bd8703d9 100644 --- a/compiler/rustc_abi/Cargo.toml +++ b/compiler/rustc_abi/Cargo.toml @@ -10,6 +10,7 @@ rand = { version = "0.9.0", default-features = false, optional = true } rand_xoshiro = { version = "0.7.0", optional = true } rustc_data_structures = { path = "../rustc_data_structures", optional = true } rustc_error_messages = { path = "../rustc_error_messages", optional = true } +rustc_errors = { path = "../rustc_errors", optional = true } rustc_hashes = { path = "../rustc_hashes" } rustc_index = { path = "../rustc_index", default-features = false } rustc_macros = { path = "../rustc_macros", optional = true } @@ -21,11 +22,12 @@ tracing = "0.1" [features] # tidy-alphabetical-start default = ["nightly", "randomize"] -# rust-analyzer depends on this crate and we therefore require it to built on a stable toolchain -# without depending on rustc_data_structures, rustc_macros and rustc_serialize +# rust-analyzer depends on this crate and we therefore require it to build on a stable toolchain +# without depending on the rustc_* crates in the following list. nightly = [ "dep:rustc_data_structures", "dep:rustc_error_messages", + "dep:rustc_errors", "dep:rustc_macros", "dep:rustc_serialize", "dep:rustc_span", diff --git a/compiler/rustc_abi/src/lib.rs b/compiler/rustc_abi/src/lib.rs index 253dff6f8e75..eca49bb71dd9 100644 --- a/compiler/rustc_abi/src/lib.rs +++ b/compiler/rustc_abi/src/lib.rs @@ -46,6 +46,8 @@ use bitflags::bitflags; #[cfg(feature = "nightly")] use rustc_data_structures::stable_hasher::StableOrd; +#[cfg(feature = "nightly")] +use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, msg}; use rustc_hashes::Hash64; use rustc_index::{Idx, IndexSlice, IndexVec}; #[cfg(feature = "nightly")] @@ -349,6 +351,51 @@ pub enum TargetDataLayoutErrors<'a> { UnknownPointerSpecification { err: String }, } +#[cfg(feature = "nightly")] +impl Diagnostic<'_, G> for TargetDataLayoutErrors<'_> { + fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> { + match self { + TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => { + Diag::new(dcx, level, msg!("invalid address space `{$addr_space}` for `{$cause}` in \"data-layout\": {$err}")) + .with_arg("addr_space", addr_space) + .with_arg("cause", cause) + .with_arg("err", err) + } + TargetDataLayoutErrors::InvalidBits { kind, bit, cause, err } => { + Diag::new(dcx, level, msg!("invalid {$kind} `{$bit}` for `{$cause}` in \"data-layout\": {$err}")) + .with_arg("kind", kind) + .with_arg("bit", bit) + .with_arg("cause", cause) + .with_arg("err", err) + } + TargetDataLayoutErrors::MissingAlignment { cause } => { + Diag::new(dcx, level, msg!("missing alignment for `{$cause}` in \"data-layout\"")) + .with_arg("cause", cause) + } + TargetDataLayoutErrors::InvalidAlignment { cause, err } => { + Diag::new(dcx, level, msg!("invalid alignment for `{$cause}` in \"data-layout\": {$err}")) + .with_arg("cause", cause) + .with_arg("err", err.to_string()) + } + TargetDataLayoutErrors::InconsistentTargetArchitecture { dl, target } => { + Diag::new(dcx, level, msg!("inconsistent target specification: \"data-layout\" claims architecture is {$dl}-endian, while \"target-endian\" is `{$target}`")) + .with_arg("dl", dl).with_arg("target", target) + } + TargetDataLayoutErrors::InconsistentTargetPointerWidth { pointer_size, target } => { + Diag::new(dcx, level, msg!("inconsistent target specification: \"data-layout\" claims pointers are {$pointer_size}-bit, while \"target-pointer-width\" is `{$target}`")) + .with_arg("pointer_size", pointer_size).with_arg("target", target) + } + TargetDataLayoutErrors::InvalidBitsSize { err } => { + Diag::new(dcx, level, msg!("{$err}")).with_arg("err", err) + } + TargetDataLayoutErrors::UnknownPointerSpecification { err } => { + Diag::new(dcx, level, msg!("unknown pointer specification `{$err}` in datalayout string")) + .with_arg("err", err) + } + } + } +} + impl TargetDataLayout { /// Parse data layout from an /// [llvm data layout string](https://llvm.org/docs/LangRef.html#data-layout) diff --git a/compiler/rustc_errors/Cargo.toml b/compiler/rustc_errors/Cargo.toml index a81fc496c828..58303c83e7cd 100644 --- a/compiler/rustc_errors/Cargo.toml +++ b/compiler/rustc_errors/Cargo.toml @@ -9,7 +9,6 @@ annotate-snippets = { version = "0.12.10", features = ["simd"] } anstream = "0.6.20" anstyle = "1.0.13" derive_setters = "0.1.6" -rustc_abi = { path = "../rustc_abi" } rustc_ast = { path = "../rustc_ast" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_error_codes = { path = "../rustc_error_codes" } diff --git a/compiler/rustc_errors/src/diagnostic_impls.rs b/compiler/rustc_errors/src/diagnostic_impls.rs index e50cbbbf06e0..ba7569c51a07 100644 --- a/compiler/rustc_errors/src/diagnostic_impls.rs +++ b/compiler/rustc_errors/src/diagnostic_impls.rs @@ -1,12 +1,11 @@ use std::borrow::Cow; -use rustc_abi::TargetDataLayoutErrors; use rustc_error_messages::{DiagArgValue, IntoDiagArg}; use rustc_macros::Subdiagnostic; use rustc_span::{Span, Symbol}; use crate::diagnostic::DiagLocation; -use crate::{Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, Subdiagnostic, msg}; +use crate::{Diag, EmissionGuarantee, Subdiagnostic}; impl IntoDiagArg for DiagLocation { fn into_diag_arg(self, _: &mut Option) -> DiagArgValue { @@ -37,55 +36,6 @@ fn into_diag_arg(self, _: &mut Option) -> DiagArgValue { } } -impl Diagnostic<'_, G> for TargetDataLayoutErrors<'_> { - fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> { - match self { - TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => { - Diag::new(dcx, level, msg!("invalid address space `{$addr_space}` for `{$cause}` in \"data-layout\": {$err}")) - .with_arg("addr_space", addr_space) - .with_arg("cause", cause) - .with_arg("err", err) - } - TargetDataLayoutErrors::InvalidBits { kind, bit, cause, err } => { - Diag::new(dcx, level, msg!("invalid {$kind} `{$bit}` for `{$cause}` in \"data-layout\": {$err}")) - .with_arg("kind", kind) - .with_arg("bit", bit) - .with_arg("cause", cause) - .with_arg("err", err) - } - TargetDataLayoutErrors::MissingAlignment { cause } => { - Diag::new(dcx, level, msg!("missing alignment for `{$cause}` in \"data-layout\"")) - .with_arg("cause", cause) - } - TargetDataLayoutErrors::InvalidAlignment { cause, err } => { - Diag::new(dcx, level, msg!( - "invalid alignment for `{$cause}` in \"data-layout\": {$err}" - )) - .with_arg("cause", cause) - .with_arg("err", err.to_string()) - } - TargetDataLayoutErrors::InconsistentTargetArchitecture { dl, target } => { - Diag::new(dcx, level, msg!( - "inconsistent target specification: \"data-layout\" claims architecture is {$dl}-endian, while \"target-endian\" is `{$target}`" - )) - .with_arg("dl", dl).with_arg("target", target) - } - TargetDataLayoutErrors::InconsistentTargetPointerWidth { pointer_size, target } => { - Diag::new(dcx, level, msg!( - "inconsistent target specification: \"data-layout\" claims pointers are {$pointer_size}-bit, while \"target-pointer-width\" is `{$target}`" - )).with_arg("pointer_size", pointer_size).with_arg("target", target) - } - TargetDataLayoutErrors::InvalidBitsSize { err } => { - Diag::new(dcx, level, msg!("{$err}")).with_arg("err", err) - } - TargetDataLayoutErrors::UnknownPointerSpecification { err } => { - Diag::new(dcx, level, msg!("unknown pointer specification `{$err}` in datalayout string")) - .with_arg("err", err) - } - } - } -} - /// Utility struct used to apply a single label while highlighting multiple spans pub struct SingleLabelManySpans { pub spans: Vec,