2024-02-23 04:34:39 +00:00
|
|
|
use rustc_errors::{codes::*, DiagArgFromDisplay};
|
2022-09-18 15:47:31 +00:00
|
|
|
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
2022-06-22 13:17:34 +00:00
|
|
|
use rustc_span::{Span, Symbol};
|
|
|
|
|
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(privacy_field_is_private, code = E0451)]
|
2022-06-22 13:17:34 +00:00
|
|
|
pub struct FieldIsPrivate {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub field_name: Symbol,
|
|
|
|
pub variant_descr: &'static str,
|
|
|
|
pub def_path_str: String,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub label: FieldIsPrivateLabel,
|
|
|
|
}
|
|
|
|
|
2022-09-18 15:47:31 +00:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-06-22 13:17:34 +00:00
|
|
|
pub enum FieldIsPrivateLabel {
|
2022-10-22 09:07:54 +00:00
|
|
|
#[label(privacy_field_is_private_is_update_syntax_label)]
|
2022-06-22 13:17:34 +00:00
|
|
|
IsUpdateSyntax {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
field_name: Symbol,
|
|
|
|
},
|
2022-10-22 09:07:54 +00:00
|
|
|
#[label(privacy_field_is_private_label)]
|
2022-06-22 13:17:34 +00:00
|
|
|
Other {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
},
|
|
|
|
}
|
2022-06-22 12:31:24 +00:00
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 09:07:54 +00:00
|
|
|
#[diag(privacy_item_is_private)]
|
2022-06-22 12:31:24 +00:00
|
|
|
pub struct ItemIsPrivate<'a> {
|
|
|
|
#[primary_span]
|
|
|
|
#[label]
|
|
|
|
pub span: Span,
|
|
|
|
pub kind: &'a str,
|
2024-02-23 04:34:39 +00:00
|
|
|
pub descr: DiagArgFromDisplay<'a>,
|
2022-06-22 12:31:24 +00:00
|
|
|
}
|
2022-06-22 12:42:30 +00:00
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 09:07:54 +00:00
|
|
|
#[diag(privacy_unnamed_item_is_private)]
|
2022-06-22 12:42:30 +00:00
|
|
|
pub struct UnnamedItemIsPrivate {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub kind: &'static str,
|
|
|
|
}
|
2022-06-22 13:11:39 +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(privacy_in_public_interface, code = E0446)]
|
2022-06-22 13:11:39 +00:00
|
|
|
pub struct InPublicInterface<'a> {
|
|
|
|
#[primary_span]
|
|
|
|
#[label]
|
|
|
|
pub span: Span,
|
|
|
|
pub vis_descr: &'static str,
|
|
|
|
pub kind: &'a str,
|
2024-02-23 04:34:39 +00:00
|
|
|
pub descr: DiagArgFromDisplay<'a>,
|
2022-10-13 09:13:02 +00:00
|
|
|
#[label(privacy_visibility_label)]
|
2022-06-22 13:11:39 +00:00
|
|
|
pub vis_span: Span,
|
|
|
|
}
|
2022-07-11 15:29:24 +00:00
|
|
|
|
2022-09-18 15:45:41 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 09:07:54 +00:00
|
|
|
#[diag(privacy_report_effective_visibility)]
|
2022-09-12 07:57:34 +00:00
|
|
|
pub struct ReportEffectiveVisibility {
|
2022-08-14 14:05:17 +00:00
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
pub descr: String,
|
|
|
|
}
|
|
|
|
|
2022-07-11 15:29:24 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
2022-10-22 09:07:54 +00:00
|
|
|
#[diag(privacy_from_private_dep_in_public_interface)]
|
2022-07-11 15:29:24 +00:00
|
|
|
pub struct FromPrivateDependencyInPublicInterface<'a> {
|
|
|
|
pub kind: &'a str,
|
2024-02-23 04:34:39 +00:00
|
|
|
pub descr: DiagArgFromDisplay<'a>,
|
2022-07-11 15:29:24 +00:00
|
|
|
pub krate: Symbol,
|
|
|
|
}
|
|
|
|
|
2023-05-18 11:57:45 +00:00
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(privacy_unnameable_types_lint)]
|
|
|
|
pub struct UnnameableTypesLint<'a> {
|
|
|
|
#[label]
|
|
|
|
pub span: Span,
|
|
|
|
pub kind: &'a str,
|
2024-02-23 04:34:39 +00:00
|
|
|
pub descr: DiagArgFromDisplay<'a>,
|
2023-05-18 11:57:45 +00:00
|
|
|
pub reachable_vis: &'a str,
|
|
|
|
pub reexported_vis: &'a str,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Used for `private_interfaces` and `private_bounds` lints.
|
|
|
|
// They will replace private-in-public errors and compatibility lints in future.
|
|
|
|
// See https://rust-lang.github.io/rfcs/2145-type-privacy.html for more details.
|
|
|
|
#[derive(LintDiagnostic)]
|
|
|
|
#[diag(privacy_private_interface_or_bounds_lint)]
|
|
|
|
pub struct PrivateInterfacesOrBoundsLint<'a> {
|
2023-06-29 13:24:07 +00:00
|
|
|
#[label(privacy_item_label)]
|
2023-05-18 11:57:45 +00:00
|
|
|
pub item_span: Span,
|
|
|
|
pub item_kind: &'a str,
|
2024-02-23 04:34:39 +00:00
|
|
|
pub item_descr: DiagArgFromDisplay<'a>,
|
2023-05-18 11:57:45 +00:00
|
|
|
pub item_vis_descr: &'a str,
|
|
|
|
#[note(privacy_ty_note)]
|
|
|
|
pub ty_span: Span,
|
|
|
|
pub ty_kind: &'a str,
|
2024-02-23 04:34:39 +00:00
|
|
|
pub ty_descr: DiagArgFromDisplay<'a>,
|
2023-05-18 11:57:45 +00:00
|
|
|
pub ty_vis_descr: &'a str,
|
|
|
|
}
|