2024-02-23 04:43:34 +00:00
|
|
|
use std::backtrace::Backtrace;
|
2022-10-12 20:55:28 +00:00
|
|
|
use std::borrow::Cow;
|
|
|
|
use std::fmt;
|
2024-06-18 10:35:56 +00:00
|
|
|
use std::num::ParseIntError;
|
|
|
|
use std::path::{Path, PathBuf};
|
2022-10-12 20:55:28 +00:00
|
|
|
use std::process::ExitStatus;
|
2024-07-28 22:13:50 +00:00
|
|
|
|
2022-10-12 20:55:28 +00:00
|
|
|
use rustc_ast_pretty::pprust;
|
2024-04-28 22:53:45 +00:00
|
|
|
use rustc_macros::Subdiagnostic;
|
2022-10-12 20:55:28 +00:00
|
|
|
use rustc_span::edition::Edition;
|
|
|
|
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent, Symbol};
|
2023-04-08 19:37:41 +00:00
|
|
|
use rustc_span::Span;
|
2022-10-14 12:25:12 +00:00
|
|
|
use rustc_target::abi::TargetDataLayoutErrors;
|
|
|
|
use rustc_target::spec::{PanicStrategy, SplitDebuginfo, StackProtector, TargetTriple};
|
2024-05-03 04:02:18 +00:00
|
|
|
use rustc_type_ir::{ClosureKind, FloatTy};
|
2022-10-12 20:55:28 +00:00
|
|
|
use {rustc_ast as ast, rustc_hir as hir};
|
2024-07-28 22:13:50 +00:00
|
|
|
|
2023-07-03 09:08:49 +00:00
|
|
|
use crate::diagnostic::DiagLocation;
|
2022-10-12 20:55:28 +00:00
|
|
|
use crate::{
|
2024-06-18 10:35:56 +00:00
|
|
|
fluent_generated as fluent, Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee,
|
2022-10-12 20:55:28 +00:00
|
|
|
ErrCode, IntoDiagArg, Level, SubdiagMessageOp, Subdiagnostic,
|
|
|
|
};
|
|
|
|
|
2024-02-23 04:34:39 +00:00
|
|
|
pub struct DiagArgFromDisplay<'a>(pub &'a dyn fmt::Display);
|
2022-10-12 20:55:28 +00:00
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
impl IntoDiagArg for DiagArgFromDisplay<'_> {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
|
|
|
self.0.to_string().into_diag_arg()
|
2022-10-12 20:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-23 04:34:39 +00:00
|
|
|
impl<'a> From<&'a dyn fmt::Display> for DiagArgFromDisplay<'a> {
|
2022-10-12 20:55:28 +00:00
|
|
|
fn from(t: &'a dyn fmt::Display) -> Self {
|
2024-02-23 04:34:39 +00:00
|
|
|
DiagArgFromDisplay(t)
|
2022-10-12 20:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-23 04:34:39 +00:00
|
|
|
impl<'a, T: fmt::Display> From<&'a T> for DiagArgFromDisplay<'a> {
|
2022-10-12 20:55:28 +00:00
|
|
|
fn from(t: &'a T) -> Self {
|
2024-02-23 04:34:39 +00:00
|
|
|
DiagArgFromDisplay(t)
|
2022-10-12 20:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
impl<'a, T: Clone + IntoDiagArg> IntoDiagArg for &'a T {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
|
|
|
self.clone().into_diag_arg()
|
2022-08-30 16:00:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-27 21:29:29 +00:00
|
|
|
#[macro_export]
|
2024-03-05 05:53:24 +00:00
|
|
|
macro_rules! into_diag_arg_using_display {
|
2022-10-12 20:55:28 +00:00
|
|
|
($( $ty:ty ),+ $(,)?) => {
|
|
|
|
$(
|
2024-03-05 05:53:24 +00:00
|
|
|
impl IntoDiagArg for $ty {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
|
|
|
self.to_string().into_diag_arg()
|
2022-10-12 20:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)+
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
macro_rules! into_diag_arg_for_number {
|
2024-01-26 19:32:55 +00:00
|
|
|
($( $ty:ty ),+ $(,)?) => {
|
|
|
|
$(
|
2024-03-05 05:53:24 +00:00
|
|
|
impl IntoDiagArg for $ty {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
2024-01-30 03:46:51 +00:00
|
|
|
// Convert to a string if it won't fit into `Number`.
|
2024-03-20 18:49:20 +00:00
|
|
|
#[allow(irrefutable_let_patterns)]
|
2024-01-30 03:46:51 +00:00
|
|
|
if let Ok(n) = TryInto::<i32>::try_into(self) {
|
2024-02-23 03:37:48 +00:00
|
|
|
DiagArgValue::Number(n)
|
2024-01-26 19:32:55 +00:00
|
|
|
} else {
|
2024-03-05 05:53:24 +00:00
|
|
|
self.to_string().into_diag_arg()
|
2024-01-26 19:32:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)+
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
into_diag_arg_using_display!(
|
2023-02-25 13:53:42 +00:00
|
|
|
ast::ParamKindOrd,
|
2022-10-12 20:55:28 +00:00
|
|
|
std::io::Error,
|
2022-08-09 00:14:43 +00:00
|
|
|
Box<dyn std::error::Error>,
|
2024-01-29 22:59:09 +00:00
|
|
|
std::num::NonZero<u32>,
|
2022-10-12 20:55:28 +00:00
|
|
|
hir::Target,
|
|
|
|
Edition,
|
|
|
|
Ident,
|
|
|
|
MacroRulesNormalizedIdent,
|
|
|
|
ParseIntError,
|
|
|
|
StackProtector,
|
|
|
|
&TargetTriple,
|
2022-10-30 19:38:37 +00:00
|
|
|
SplitDebuginfo,
|
|
|
|
ExitStatus,
|
Stop using `String` for error codes.
Error codes are integers, but `String` is used everywhere to represent
them. Gross!
This commit introduces `ErrCode`, an integral newtype for error codes,
replacing `String`. It also introduces a constant for every error code,
e.g. `E0123`, and removes the `error_code!` macro. The constants are
imported wherever used with `use rustc_errors::codes::*`.
With the old code, we have three different ways to specify an error code
at a use point:
```
error_code!(E0123) // macro call
struct_span_code_err!(dcx, span, E0123, "msg"); // bare ident arg to macro call
\#[diag(name, code = "E0123")] // string
struct Diag;
```
With the new code, they all use the `E0123` constant.
```
E0123 // constant
struct_span_code_err!(dcx, span, E0123, "msg"); // constant
\#[diag(name, code = E0123)] // constant
struct Diag;
```
The commit also changes the structure of the error code definitions:
- `rustc_error_codes` now just defines a higher-order macro listing the
used error codes and nothing else.
- Because that's now the only thing in the `rustc_error_codes` crate, I
moved it into the `lib.rs` file and removed the `error_codes.rs` file.
- `rustc_errors` uses that macro to define everything, e.g. the error
code constants and the `DIAGNOSTIC_TABLES`. This is in its new
`codes.rs` file.
2024-01-13 23:57:07 +00:00
|
|
|
ErrCode,
|
2022-10-12 20:55:28 +00:00
|
|
|
);
|
|
|
|
|
2024-05-10 18:59:56 +00:00
|
|
|
impl<I: rustc_type_ir::Interner> IntoDiagArg for rustc_type_ir::TraitRef<I> {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
|
|
|
self.to_string().into_diag_arg()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-11 16:46:11 +00:00
|
|
|
impl<I: rustc_type_ir::Interner> IntoDiagArg for rustc_type_ir::ExistentialTraitRef<I> {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
|
|
|
self.to_string().into_diag_arg()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-13 16:40:08 +00:00
|
|
|
impl<I: rustc_type_ir::Interner> IntoDiagArg for rustc_type_ir::UnevaluatedConst<I> {
|
|
|
|
fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
|
|
|
|
format!("{self:?}").into_diag_arg()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-15 17:54:37 +00:00
|
|
|
impl<I: rustc_type_ir::Interner> IntoDiagArg for rustc_type_ir::FnSig<I> {
|
|
|
|
fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
|
|
|
|
format!("{self:?}").into_diag_arg()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-20 16:57:07 +00:00
|
|
|
impl<I: rustc_type_ir::Interner, T> IntoDiagArg for rustc_type_ir::Binder<I, T>
|
|
|
|
where
|
|
|
|
T: IntoDiagArg,
|
|
|
|
{
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
|
|
|
self.skip_binder().into_diag_arg()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
into_diag_arg_for_number!(i8, u8, i16, u16, i32, u32, i64, u64, i128, u128, isize, usize);
|
2023-05-17 10:30:14 +00:00
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
impl IntoDiagArg for bool {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
2022-10-12 20:55:28 +00:00
|
|
|
if self {
|
2024-02-23 03:37:48 +00:00
|
|
|
DiagArgValue::Str(Cow::Borrowed("true"))
|
2022-10-12 20:55:28 +00:00
|
|
|
} else {
|
2024-02-23 03:37:48 +00:00
|
|
|
DiagArgValue::Str(Cow::Borrowed("false"))
|
2022-10-12 20:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
impl IntoDiagArg for char {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
2024-02-23 03:37:48 +00:00
|
|
|
DiagArgValue::Str(Cow::Owned(format!("{self:?}")))
|
2022-10-12 20:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
impl IntoDiagArg for Vec<char> {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
2024-02-23 03:37:48 +00:00
|
|
|
DiagArgValue::StrListSepByAnd(
|
2024-01-23 02:56:33 +00:00
|
|
|
self.into_iter().map(|c| Cow::Owned(format!("{c:?}"))).collect(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
impl IntoDiagArg for Symbol {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
|
|
|
self.to_ident_string().into_diag_arg()
|
2022-10-12 20:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
impl<'a> IntoDiagArg for &'a str {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
|
|
|
self.to_string().into_diag_arg()
|
2022-10-12 20:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
impl IntoDiagArg for String {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
2024-02-23 03:37:48 +00:00
|
|
|
DiagArgValue::Str(Cow::Owned(self))
|
2022-10-12 20:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
impl<'a> IntoDiagArg for Cow<'a, str> {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
2024-02-23 03:37:48 +00:00
|
|
|
DiagArgValue::Str(Cow::Owned(self.into_owned()))
|
2022-08-26 17:01:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
impl<'a> IntoDiagArg for &'a Path {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
2024-02-23 03:37:48 +00:00
|
|
|
DiagArgValue::Str(Cow::Owned(self.display().to_string()))
|
2022-10-12 20:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
impl IntoDiagArg for PathBuf {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
2024-02-23 03:37:48 +00:00
|
|
|
DiagArgValue::Str(Cow::Owned(self.display().to_string()))
|
2022-10-12 20:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
impl IntoDiagArg for PanicStrategy {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
2024-02-23 03:37:48 +00:00
|
|
|
DiagArgValue::Str(Cow::Owned(self.desc().to_string()))
|
2022-10-12 20:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
impl IntoDiagArg for hir::ConstContext {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
2024-02-23 03:37:48 +00:00
|
|
|
DiagArgValue::Str(Cow::Borrowed(match self {
|
2023-05-17 10:30:14 +00:00
|
|
|
hir::ConstContext::ConstFn => "const_fn",
|
2022-10-12 20:55:28 +00:00
|
|
|
hir::ConstContext::Static(_) => "static",
|
2023-09-18 15:30:07 +00:00
|
|
|
hir::ConstContext::Const { .. } => "const",
|
2022-10-12 20:55:28 +00:00
|
|
|
}))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
impl IntoDiagArg for ast::Expr {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
2024-02-23 03:37:48 +00:00
|
|
|
DiagArgValue::Str(Cow::Owned(pprust::expr_to_string(&self)))
|
2023-07-25 10:12:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
impl IntoDiagArg for ast::Path {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
2024-02-23 03:37:48 +00:00
|
|
|
DiagArgValue::Str(Cow::Owned(pprust::path_to_string(&self)))
|
2022-10-12 20:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
impl IntoDiagArg for ast::token::Token {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
2024-02-23 03:37:48 +00:00
|
|
|
DiagArgValue::Str(pprust::token_to_string(&self))
|
2022-10-12 20:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
impl IntoDiagArg for ast::token::TokenKind {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
2024-02-23 03:37:48 +00:00
|
|
|
DiagArgValue::Str(pprust::token_kind_to_string(&self))
|
2022-10-12 20:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
2022-10-05 00:56:05 +00:00
|
|
|
|
2024-05-03 04:02:18 +00:00
|
|
|
impl IntoDiagArg for FloatTy {
|
2024-03-05 05:53:24 +00:00
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
2024-02-23 03:37:48 +00:00
|
|
|
DiagArgValue::Str(Cow::Borrowed(self.name_str()))
|
2022-11-17 13:53:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
impl IntoDiagArg for std::ffi::CString {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
2024-02-23 03:37:48 +00:00
|
|
|
DiagArgValue::Str(Cow::Owned(self.to_string_lossy().into_owned()))
|
2022-08-19 13:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
impl IntoDiagArg for rustc_data_structures::small_c_str::SmallCStr {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
2024-02-23 03:37:48 +00:00
|
|
|
DiagArgValue::Str(Cow::Owned(self.to_string_lossy().into_owned()))
|
2022-08-19 13:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
impl IntoDiagArg for ast::Visibility {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
2022-10-05 20:05:45 +00:00
|
|
|
let s = pprust::vis_to_string(&self);
|
|
|
|
let s = s.trim_end().to_string();
|
2024-02-23 03:37:48 +00:00
|
|
|
DiagArgValue::Str(Cow::Owned(s))
|
2022-10-05 20:05:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 05:53:24 +00:00
|
|
|
impl IntoDiagArg for rustc_lint_defs::Level {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
2024-02-23 03:37:48 +00:00
|
|
|
DiagArgValue::Str(Cow::Borrowed(self.to_cmd_flag()))
|
2022-10-14 12:25:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-20 12:57:29 +00:00
|
|
|
impl<Id> IntoDiagArg for hir::def::Res<Id> {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
|
|
|
DiagArgValue::Str(Cow::Borrowed(self.descr()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IntoDiagArg for DiagLocation {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
|
|
|
DiagArgValue::Str(Cow::from(self.to_string()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IntoDiagArg for Backtrace {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
|
|
|
DiagArgValue::Str(Cow::from(self.to_string()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IntoDiagArg for Level {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
|
|
|
DiagArgValue::Str(Cow::from(self.to_string()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-03 04:02:18 +00:00
|
|
|
impl IntoDiagArg for ClosureKind {
|
2024-04-20 12:57:29 +00:00
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
|
|
|
DiagArgValue::Str(self.as_str().into())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-17 20:21:38 +00:00
|
|
|
impl IntoDiagArg for hir::def::Namespace {
|
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
|
|
|
DiagArgValue::Str(Cow::Borrowed(self.descr()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-22 10:48:20 +00:00
|
|
|
#[derive(Clone)]
|
2024-07-04 14:45:13 +00:00
|
|
|
pub struct DiagSymbolList<S = Symbol>(Vec<S>);
|
2022-10-22 10:48:20 +00:00
|
|
|
|
2024-07-04 14:45:13 +00:00
|
|
|
impl<S> From<Vec<S>> for DiagSymbolList<S> {
|
|
|
|
fn from(v: Vec<S>) -> Self {
|
2024-02-23 04:57:49 +00:00
|
|
|
DiagSymbolList(v)
|
2022-10-22 10:48:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-04 14:45:13 +00:00
|
|
|
impl<S> FromIterator<S> for DiagSymbolList<S> {
|
|
|
|
fn from_iter<T: IntoIterator<Item = S>>(iter: T) -> Self {
|
|
|
|
iter.into_iter().collect::<Vec<_>>().into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<S: std::fmt::Display> IntoDiagArg for DiagSymbolList<S> {
|
2024-03-05 05:53:24 +00:00
|
|
|
fn into_diag_arg(self) -> DiagArgValue {
|
2024-02-23 03:37:48 +00:00
|
|
|
DiagArgValue::StrListSepByAnd(
|
2022-11-06 06:43:25 +00:00
|
|
|
self.0.into_iter().map(|sym| Cow::Owned(format!("`{sym}`"))).collect(),
|
|
|
|
)
|
2022-10-22 10:48:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-06 00:02:56 +00:00
|
|
|
impl<G: EmissionGuarantee> Diagnostic<'_, G> for TargetDataLayoutErrors<'_> {
|
2024-06-18 10:35:56 +00:00
|
|
|
fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
|
2022-10-05 00:56:05 +00:00
|
|
|
match self {
|
|
|
|
TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => {
|
2024-02-22 23:20:45 +00:00
|
|
|
Diag::new(dcx, level, fluent::errors_target_invalid_address_space)
|
2024-01-08 22:08:49 +00:00
|
|
|
.with_arg("addr_space", addr_space)
|
|
|
|
.with_arg("cause", cause)
|
|
|
|
.with_arg("err", err)
|
2022-10-05 00:56:05 +00:00
|
|
|
}
|
|
|
|
TargetDataLayoutErrors::InvalidBits { kind, bit, cause, err } => {
|
2024-02-22 23:20:45 +00:00
|
|
|
Diag::new(dcx, level, fluent::errors_target_invalid_bits)
|
2024-01-08 22:08:49 +00:00
|
|
|
.with_arg("kind", kind)
|
|
|
|
.with_arg("bit", bit)
|
|
|
|
.with_arg("cause", cause)
|
|
|
|
.with_arg("err", err)
|
2022-10-05 00:56:05 +00:00
|
|
|
}
|
|
|
|
TargetDataLayoutErrors::MissingAlignment { cause } => {
|
2024-02-22 23:20:45 +00:00
|
|
|
Diag::new(dcx, level, fluent::errors_target_missing_alignment)
|
2024-01-08 22:08:49 +00:00
|
|
|
.with_arg("cause", cause)
|
2022-10-05 00:56:05 +00:00
|
|
|
}
|
|
|
|
TargetDataLayoutErrors::InvalidAlignment { cause, err } => {
|
2024-02-22 23:20:45 +00:00
|
|
|
Diag::new(dcx, level, fluent::errors_target_invalid_alignment)
|
2024-01-08 22:08:49 +00:00
|
|
|
.with_arg("cause", cause)
|
|
|
|
.with_arg("err_kind", err.diag_ident())
|
|
|
|
.with_arg("align", err.align())
|
2022-10-05 00:56:05 +00:00
|
|
|
}
|
|
|
|
TargetDataLayoutErrors::InconsistentTargetArchitecture { dl, target } => {
|
2024-02-22 23:20:45 +00:00
|
|
|
Diag::new(dcx, level, fluent::errors_target_inconsistent_architecture)
|
2024-01-08 22:08:49 +00:00
|
|
|
.with_arg("dl", dl)
|
|
|
|
.with_arg("target", target)
|
2022-10-05 00:56:05 +00:00
|
|
|
}
|
|
|
|
TargetDataLayoutErrors::InconsistentTargetPointerWidth { pointer_size, target } => {
|
2024-02-22 23:20:45 +00:00
|
|
|
Diag::new(dcx, level, fluent::errors_target_inconsistent_pointer_width)
|
2024-01-08 22:08:49 +00:00
|
|
|
.with_arg("pointer_size", pointer_size)
|
|
|
|
.with_arg("target", target)
|
2022-10-05 00:56:05 +00:00
|
|
|
}
|
|
|
|
TargetDataLayoutErrors::InvalidBitsSize { err } => {
|
2024-02-22 23:20:45 +00:00
|
|
|
Diag::new(dcx, level, fluent::errors_target_invalid_bits_size).with_arg("err", err)
|
2022-10-05 00:56:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-04-08 19:37:41 +00:00
|
|
|
|
|
|
|
/// Utility struct used to apply a single label while highlighting multiple spans
|
|
|
|
pub struct SingleLabelManySpans {
|
|
|
|
pub spans: Vec<Span>,
|
|
|
|
pub label: &'static str,
|
|
|
|
}
|
2024-03-06 03:00:16 +00:00
|
|
|
impl Subdiagnostic for SingleLabelManySpans {
|
|
|
|
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
|
Reduce capabilities of `Diagnostic`.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)
`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.
The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)
All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.
There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.
There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-06 05:44:30 +00:00
|
|
|
self,
|
2024-02-22 23:20:45 +00:00
|
|
|
diag: &mut Diag<'_, G>,
|
2024-04-18 19:18:35 +00:00
|
|
|
_: &F,
|
Reduce capabilities of `Diagnostic`.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)
`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.
The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)
All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.
There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.
There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-06 05:44:30 +00:00
|
|
|
) {
|
2023-12-20 23:42:00 +00:00
|
|
|
diag.span_labels(self.spans, self.label);
|
2023-04-08 19:37:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-03 09:08:49 +00:00
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[label(errors_expected_lifetime_parameter)]
|
|
|
|
pub struct ExpectedLifetimeParameter {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub count: usize,
|
|
|
|
}
|
|
|
|
|
2023-07-17 06:00:13 +00:00
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[suggestion(errors_indicate_anonymous_lifetime, code = "{suggestion}", style = "verbose")]
|
2023-07-03 09:08:49 +00:00
|
|
|
pub struct IndicateAnonymousLifetime {
|
2023-07-17 06:00:13 +00:00
|
|
|
#[primary_span]
|
2023-07-03 09:08:49 +00:00
|
|
|
pub span: Span,
|
|
|
|
pub count: usize,
|
|
|
|
pub suggestion: String,
|
|
|
|
}
|
2024-04-20 13:21:15 +00:00
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
pub struct ElidedLifetimeInPathSubdiag {
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub expected: ExpectedLifetimeParameter,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub indicate: Option<IndicateAnonymousLifetime>,
|
|
|
|
}
|