2022-10-13 09:13:02 +00:00
|
|
|
use crate::fluent_generated as fluent;
|
2023-06-28 18:08:21 +00:00
|
|
|
use rustc_errors::{
|
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
|
|
|
codes::*, AddToDiagnostic, Applicability, DiagCtxt, Diagnostic, DiagnosticBuilder,
|
|
|
|
EmissionGuarantee, IntoDiagnostic, Level, SubdiagnosticMessage,
|
2023-06-28 18:08:21 +00:00
|
|
|
};
|
2022-09-18 15:46:56 +00:00
|
|
|
use rustc_macros::Diagnostic;
|
2023-08-06 14:00:12 +00:00
|
|
|
use rustc_middle::ty::{self, ClosureKind, PolyTraitRef, Ty};
|
2022-08-26 18:08:58 +00:00
|
|
|
use rustc_span::{Span, Symbol};
|
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 09:07:54 +00:00
|
|
|
#[diag(trait_selection_dump_vtable_entries)]
|
2022-08-26 18:08:58 +00:00
|
|
|
pub struct DumpVTableEntries<'a> {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub trait_ref: PolyTraitRef<'a>,
|
|
|
|
pub entries: String,
|
|
|
|
}
|
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 09:07:54 +00:00
|
|
|
#[diag(trait_selection_unable_to_construct_constant_value)]
|
2022-08-26 18:08:58 +00:00
|
|
|
pub struct UnableToConstructConstantValue<'a> {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
2022-09-22 10:34:23 +00:00
|
|
|
pub unevaluated: ty::UnevaluatedConst<'a>,
|
2022-08-26 18:08:58 +00:00
|
|
|
}
|
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
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
|
|
|
#[diag(trait_selection_empty_on_clause_in_rustc_on_unimplemented, code = E0232)]
|
2022-08-26 18:08:58 +00:00
|
|
|
pub struct EmptyOnClauseInOnUnimplemented {
|
|
|
|
#[primary_span]
|
|
|
|
#[label]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
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
|
|
|
#[diag(trait_selection_invalid_on_clause_in_rustc_on_unimplemented, code = E0232)]
|
2022-08-26 18:08:58 +00:00
|
|
|
pub struct InvalidOnClauseInOnUnimplemented {
|
|
|
|
#[primary_span]
|
|
|
|
#[label]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
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
|
|
|
#[diag(trait_selection_no_value_in_rustc_on_unimplemented, code = E0232)]
|
2022-08-26 18:08:58 +00:00
|
|
|
#[note]
|
|
|
|
pub struct NoValueInOnUnimplemented {
|
|
|
|
#[primary_span]
|
|
|
|
#[label]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
2022-11-10 04:21:11 +00:00
|
|
|
pub struct NegativePositiveConflict<'tcx> {
|
2022-08-26 18:08:58 +00:00
|
|
|
pub impl_span: Span,
|
2022-11-10 04:21:11 +00:00
|
|
|
pub trait_desc: ty::TraitRef<'tcx>,
|
|
|
|
pub self_ty: Option<Ty<'tcx>>,
|
2022-08-26 18:08:58 +00:00
|
|
|
pub negative_impl_span: Result<Span, Symbol>,
|
|
|
|
pub positive_impl_span: Result<Span, Symbol>,
|
|
|
|
}
|
|
|
|
|
2023-12-18 03:12:39 +00:00
|
|
|
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for NegativePositiveConflict<'_> {
|
2022-10-31 15:14:29 +00:00
|
|
|
#[track_caller]
|
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
|
|
|
fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
|
2023-12-18 03:12:39 +00:00
|
|
|
let mut diag =
|
|
|
|
DiagnosticBuilder::new(dcx, level, fluent::trait_selection_negative_positive_conflict);
|
2023-12-23 22:08:41 +00:00
|
|
|
diag.arg("trait_desc", self.trait_desc.print_only_trait_path().to_string());
|
|
|
|
diag.arg("self_desc", self.self_ty.map_or_else(|| "none".to_string(), |ty| ty.to_string()));
|
|
|
|
diag.span(self.impl_span);
|
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
|
|
|
diag.code(E0751);
|
2022-08-26 18:08:58 +00:00
|
|
|
match self.negative_impl_span {
|
|
|
|
Ok(span) => {
|
2022-10-13 09:13:02 +00:00
|
|
|
diag.span_label(span, fluent::trait_selection_negative_implementation_here);
|
2022-08-26 18:08:58 +00:00
|
|
|
}
|
|
|
|
Err(cname) => {
|
2022-10-13 09:13:02 +00:00
|
|
|
diag.note(fluent::trait_selection_negative_implementation_in_crate);
|
2023-12-23 22:08:41 +00:00
|
|
|
diag.arg("negative_impl_cname", cname.to_string());
|
2022-08-26 18:08:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
match self.positive_impl_span {
|
|
|
|
Ok(span) => {
|
2022-10-13 09:13:02 +00:00
|
|
|
diag.span_label(span, fluent::trait_selection_positive_implementation_here);
|
2022-08-26 18:08:58 +00:00
|
|
|
}
|
|
|
|
Err(cname) => {
|
2022-10-13 09:13:02 +00:00
|
|
|
diag.note(fluent::trait_selection_positive_implementation_in_crate);
|
2023-12-23 22:08:41 +00:00
|
|
|
diag.arg("positive_impl_cname", cname.to_string());
|
2022-08-26 18:08:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
}
|
2023-03-21 00:46:52 +00:00
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(trait_selection_inherent_projection_normalization_overflow)]
|
|
|
|
pub struct InherentProjectionNormalizationOverflow {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub ty: String,
|
|
|
|
}
|
2023-06-28 18:08:21 +00:00
|
|
|
|
|
|
|
pub enum AdjustSignatureBorrow {
|
|
|
|
Borrow { to_borrow: Vec<(Span, String)> },
|
|
|
|
RemoveBorrow { remove_borrow: Vec<(Span, String)> },
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AddToDiagnostic for AdjustSignatureBorrow {
|
|
|
|
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
|
|
|
|
where
|
|
|
|
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
|
|
|
|
{
|
|
|
|
match self {
|
|
|
|
AdjustSignatureBorrow::Borrow { to_borrow } => {
|
2023-12-23 22:08:41 +00:00
|
|
|
diag.arg("len", to_borrow.len());
|
2023-06-28 18:08:21 +00:00
|
|
|
diag.multipart_suggestion_verbose(
|
|
|
|
fluent::trait_selection_adjust_signature_borrow,
|
|
|
|
to_borrow,
|
|
|
|
Applicability::MaybeIncorrect,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
AdjustSignatureBorrow::RemoveBorrow { remove_borrow } => {
|
2023-12-23 22:08:41 +00:00
|
|
|
diag.arg("len", remove_borrow.len());
|
2023-06-28 18:08:21 +00:00
|
|
|
diag.multipart_suggestion_verbose(
|
|
|
|
fluent::trait_selection_adjust_signature_remove_borrow,
|
|
|
|
remove_borrow,
|
|
|
|
Applicability::MaybeIncorrect,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-08-06 14:00:12 +00:00
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
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
|
|
|
#[diag(trait_selection_closure_kind_mismatch, code = E0525)]
|
2023-08-06 14:00:12 +00:00
|
|
|
pub struct ClosureKindMismatch {
|
|
|
|
#[primary_span]
|
|
|
|
#[label]
|
|
|
|
pub closure_span: Span,
|
|
|
|
pub expected: ClosureKind,
|
|
|
|
pub found: ClosureKind,
|
|
|
|
#[label(trait_selection_closure_kind_requirement)]
|
|
|
|
pub cause_span: Span,
|
|
|
|
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub fn_once_label: Option<ClosureFnOnceLabel>,
|
|
|
|
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub fn_mut_label: Option<ClosureFnMutLabel>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[label(trait_selection_closure_fn_once_label)]
|
|
|
|
pub struct ClosureFnOnceLabel {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub place: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
|
|
|
#[label(trait_selection_closure_fn_mut_label)]
|
|
|
|
pub struct ClosureFnMutLabel {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub place: String,
|
|
|
|
}
|