Auto merge of #101558 - JhonnyBillM:session-diagnostic-to-diagnostic-handler-refactor, r=davidtwco

Move and rename `SessionDiagnostic` & `SessionSubdiagnostic` traits and macros

After PR #101434, we want to:
- [x] Move `SessionDiagnostic` to `rustc_errors`.
- [x] Add `emit_` methods that accept `impl SessionDiagnostic` to `Handler`.
- [x] _(optional)_ Rename trait `SessionDiagnostic` to `DiagnosticHandler`.
- [x] _(optional)_ Rename macro `SessionDiagnostic` to `DiagnosticHandler`.
- [x] Update Rustc Dev Guide and Docs to reflect these changes. https://github.com/rust-lang/rustc-dev-guide/pull/1460

Now I am having build issues getting the compiler to build when trying to rename the macro.

<details>
  <summary>See diagnostics errors and context when building.</summary>

```
error: diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
  --> compiler/rustc_attr/src/session_diagnostics.rs:13:10
   |
13 |   #[derive(DiagnosticHandler)]
   |            ^^^^^^^^^^^^^^^^^ in this derive macro expansion
   |
  ::: /Users/jhonny/.cargo/registry/src/github.com-1ecc6299db9ec823/synstructure-0.12.6/src/macros.rs:94:9
   |
94 | /         pub fn $derives(
95 | |             i: $crate::macros::TokenStream
96 | |         ) -> $crate::macros::TokenStream {
   | |________________________________________- in this expansion of `#[derive(DiagnosticHandler)]`
   |
note: the lint level is defined here
  --> compiler/rustc_attr/src/lib.rs:10:9
   |
10 | #![deny(rustc::diagnostic_outside_of_impl)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

```

And also this one:

```
error: diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
   --> compiler/rustc_attr/src/session_diagnostics.rs:213:32
    |
213 |         let mut diag = handler.struct_span_err_with_code(
    |                                ^^^^^^^^^^^^^^^^^^^^^^^^^
```

> **Note**
> Can't find where this message is coming from, because you can see in [this experimental branch](https://github.com/JhonnyBillM/rust/tree/experimental/trying-to-rename-session-diagnostic-macro)  that I updated all errors and diags to say:
> error: diagnostics should only be created in **`DiagnosticHandler`**/`AddSubdiagnostic` impls
> and not:
> error: diagnostics should only be created in **`SessionDiagnostic`**/`AddSubdiagnostic` impls

</details>

I tried building the compiler in different ways (playing with the stages etc), but nothing worked.

## Question

**Do we need to build or do something different when renaming a macro and identifiers?**

For context, see experimental commit f2193a98b4 where the macro and symbols are renamed, but it doesn't compile.
This commit is contained in:
bors 2022-09-21 19:58:39 +00:00
commit 9062b780b3
56 changed files with 833 additions and 792 deletions

View file

@ -1,8 +1,8 @@
use rustc_errors::{fluent, AddSubdiagnostic, Applicability, Diagnostic, DiagnosticArgFromDisplay}; use rustc_errors::{fluent, AddToDiagnostic, Applicability, Diagnostic, DiagnosticArgFromDisplay};
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic}; use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{symbol::Ident, Span, Symbol}; use rustc_span::{symbol::Ident, Span, Symbol};
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::generic_type_with_parentheses, code = "E0214")] #[diag(ast_lowering::generic_type_with_parentheses, code = "E0214")]
pub struct GenericTypeWithParentheses { pub struct GenericTypeWithParentheses {
#[primary_span] #[primary_span]
@ -18,7 +18,7 @@ pub struct UseAngleBrackets {
pub close_param: Span, pub close_param: Span,
} }
impl AddSubdiagnostic for UseAngleBrackets { impl AddToDiagnostic for UseAngleBrackets {
fn add_to_diagnostic(self, diag: &mut Diagnostic) { fn add_to_diagnostic(self, diag: &mut Diagnostic) {
diag.multipart_suggestion( diag.multipart_suggestion(
fluent::ast_lowering::use_angle_brackets, fluent::ast_lowering::use_angle_brackets,
@ -28,7 +28,7 @@ impl AddSubdiagnostic for UseAngleBrackets {
} }
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[help] #[help]
#[diag(ast_lowering::invalid_abi, code = "E0703")] #[diag(ast_lowering::invalid_abi, code = "E0703")]
pub struct InvalidAbi { pub struct InvalidAbi {
@ -39,7 +39,7 @@ pub struct InvalidAbi {
pub valid_abis: String, pub valid_abis: String,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::assoc_ty_parentheses)] #[diag(ast_lowering::assoc_ty_parentheses)]
pub struct AssocTyParentheses { pub struct AssocTyParentheses {
#[primary_span] #[primary_span]
@ -54,7 +54,7 @@ pub enum AssocTyParenthesesSub {
NotEmpty { open_param: Span, close_param: Span }, NotEmpty { open_param: Span, close_param: Span },
} }
impl AddSubdiagnostic for AssocTyParenthesesSub { impl AddToDiagnostic for AssocTyParenthesesSub {
fn add_to_diagnostic(self, diag: &mut Diagnostic) { fn add_to_diagnostic(self, diag: &mut Diagnostic) {
match self { match self {
Self::Empty { parentheses_span } => diag.multipart_suggestion( Self::Empty { parentheses_span } => diag.multipart_suggestion(
@ -71,7 +71,7 @@ impl AddSubdiagnostic for AssocTyParenthesesSub {
} }
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_lowering::misplaced_impl_trait, code = "E0562")] #[diag(ast_lowering::misplaced_impl_trait, code = "E0562")]
pub struct MisplacedImplTrait<'a> { pub struct MisplacedImplTrait<'a> {
#[primary_span] #[primary_span]
@ -79,14 +79,14 @@ pub struct MisplacedImplTrait<'a> {
pub position: DiagnosticArgFromDisplay<'a>, pub position: DiagnosticArgFromDisplay<'a>,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::rustc_box_attribute_error)] #[diag(ast_lowering::rustc_box_attribute_error)]
pub struct RustcBoxAttributeError { pub struct RustcBoxAttributeError {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::underscore_expr_lhs_assign)] #[diag(ast_lowering::underscore_expr_lhs_assign)]
pub struct UnderscoreExprLhsAssign { pub struct UnderscoreExprLhsAssign {
#[primary_span] #[primary_span]
@ -94,7 +94,7 @@ pub struct UnderscoreExprLhsAssign {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::base_expression_double_dot)] #[diag(ast_lowering::base_expression_double_dot)]
pub struct BaseExpressionDoubleDot { pub struct BaseExpressionDoubleDot {
#[primary_span] #[primary_span]
@ -102,7 +102,7 @@ pub struct BaseExpressionDoubleDot {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::await_only_in_async_fn_and_blocks, code = "E0728")] #[diag(ast_lowering::await_only_in_async_fn_and_blocks, code = "E0728")]
pub struct AwaitOnlyInAsyncFnAndBlocks { pub struct AwaitOnlyInAsyncFnAndBlocks {
#[primary_span] #[primary_span]
@ -112,21 +112,21 @@ pub struct AwaitOnlyInAsyncFnAndBlocks {
pub item_span: Option<Span>, pub item_span: Option<Span>,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::generator_too_many_parameters, code = "E0628")] #[diag(ast_lowering::generator_too_many_parameters, code = "E0628")]
pub struct GeneratorTooManyParameters { pub struct GeneratorTooManyParameters {
#[primary_span] #[primary_span]
pub fn_decl_span: Span, pub fn_decl_span: Span,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::closure_cannot_be_static, code = "E0697")] #[diag(ast_lowering::closure_cannot_be_static, code = "E0697")]
pub struct ClosureCannotBeStatic { pub struct ClosureCannotBeStatic {
#[primary_span] #[primary_span]
pub fn_decl_span: Span, pub fn_decl_span: Span,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[help] #[help]
#[diag(ast_lowering::async_non_move_closure_not_supported, code = "E0708")] #[diag(ast_lowering::async_non_move_closure_not_supported, code = "E0708")]
pub struct AsyncNonMoveClosureNotSupported { pub struct AsyncNonMoveClosureNotSupported {
@ -134,7 +134,7 @@ pub struct AsyncNonMoveClosureNotSupported {
pub fn_decl_span: Span, pub fn_decl_span: Span,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::functional_record_update_destructuring_assignment)] #[diag(ast_lowering::functional_record_update_destructuring_assignment)]
pub struct FunctionalRecordUpdateDestructuringAssignemnt { pub struct FunctionalRecordUpdateDestructuringAssignemnt {
#[primary_span] #[primary_span]
@ -142,28 +142,28 @@ pub struct FunctionalRecordUpdateDestructuringAssignemnt {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::async_generators_not_supported, code = "E0727")] #[diag(ast_lowering::async_generators_not_supported, code = "E0727")]
pub struct AsyncGeneratorsNotSupported { pub struct AsyncGeneratorsNotSupported {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::inline_asm_unsupported_target, code = "E0472")] #[diag(ast_lowering::inline_asm_unsupported_target, code = "E0472")]
pub struct InlineAsmUnsupportedTarget { pub struct InlineAsmUnsupportedTarget {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::att_syntax_only_x86)] #[diag(ast_lowering::att_syntax_only_x86)]
pub struct AttSyntaxOnlyX86 { pub struct AttSyntaxOnlyX86 {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::abi_specified_multiple_times)] #[diag(ast_lowering::abi_specified_multiple_times)]
pub struct AbiSpecifiedMultipleTimes { pub struct AbiSpecifiedMultipleTimes {
#[primary_span] #[primary_span]
@ -175,14 +175,14 @@ pub struct AbiSpecifiedMultipleTimes {
pub equivalent: Option<()>, pub equivalent: Option<()>,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::clobber_abi_not_supported)] #[diag(ast_lowering::clobber_abi_not_supported)]
pub struct ClobberAbiNotSupported { pub struct ClobberAbiNotSupported {
#[primary_span] #[primary_span]
pub abi_span: Span, pub abi_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[note] #[note]
#[diag(ast_lowering::invalid_abi_clobber_abi)] #[diag(ast_lowering::invalid_abi_clobber_abi)]
pub struct InvalidAbiClobberAbi { pub struct InvalidAbiClobberAbi {
@ -191,7 +191,7 @@ pub struct InvalidAbiClobberAbi {
pub supported_abis: String, pub supported_abis: String,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::invalid_register)] #[diag(ast_lowering::invalid_register)]
pub struct InvalidRegister<'a> { pub struct InvalidRegister<'a> {
#[primary_span] #[primary_span]
@ -200,7 +200,7 @@ pub struct InvalidRegister<'a> {
pub error: &'a str, pub error: &'a str,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::invalid_register_class)] #[diag(ast_lowering::invalid_register_class)]
pub struct InvalidRegisterClass<'a> { pub struct InvalidRegisterClass<'a> {
#[primary_span] #[primary_span]
@ -209,7 +209,7 @@ pub struct InvalidRegisterClass<'a> {
pub error: &'a str, pub error: &'a str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_lowering::invalid_asm_template_modifier_reg_class)] #[diag(ast_lowering::invalid_asm_template_modifier_reg_class)]
pub struct InvalidAsmTemplateModifierRegClass { pub struct InvalidAsmTemplateModifierRegClass {
#[primary_span] #[primary_span]
@ -221,7 +221,7 @@ pub struct InvalidAsmTemplateModifierRegClass {
pub sub: InvalidAsmTemplateModifierRegClassSub, pub sub: InvalidAsmTemplateModifierRegClassSub,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub enum InvalidAsmTemplateModifierRegClassSub { pub enum InvalidAsmTemplateModifierRegClassSub {
#[note(ast_lowering::support_modifiers)] #[note(ast_lowering::support_modifiers)]
SupportModifier { class_name: Symbol, modifiers: String }, SupportModifier { class_name: Symbol, modifiers: String },
@ -229,7 +229,7 @@ pub enum InvalidAsmTemplateModifierRegClassSub {
DoesNotSupportModifier { class_name: Symbol }, DoesNotSupportModifier { class_name: Symbol },
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::invalid_asm_template_modifier_const)] #[diag(ast_lowering::invalid_asm_template_modifier_const)]
pub struct InvalidAsmTemplateModifierConst { pub struct InvalidAsmTemplateModifierConst {
#[primary_span] #[primary_span]
@ -239,7 +239,7 @@ pub struct InvalidAsmTemplateModifierConst {
pub op_span: Span, pub op_span: Span,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::invalid_asm_template_modifier_sym)] #[diag(ast_lowering::invalid_asm_template_modifier_sym)]
pub struct InvalidAsmTemplateModifierSym { pub struct InvalidAsmTemplateModifierSym {
#[primary_span] #[primary_span]
@ -249,7 +249,7 @@ pub struct InvalidAsmTemplateModifierSym {
pub op_span: Span, pub op_span: Span,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::register_class_only_clobber)] #[diag(ast_lowering::register_class_only_clobber)]
pub struct RegisterClassOnlyClobber { pub struct RegisterClassOnlyClobber {
#[primary_span] #[primary_span]
@ -257,7 +257,7 @@ pub struct RegisterClassOnlyClobber {
pub reg_class_name: Symbol, pub reg_class_name: Symbol,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::register_conflict)] #[diag(ast_lowering::register_conflict)]
pub struct RegisterConflict<'a> { pub struct RegisterConflict<'a> {
#[primary_span] #[primary_span]
@ -271,7 +271,7 @@ pub struct RegisterConflict<'a> {
pub in_out: Option<Span>, pub in_out: Option<Span>,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[help] #[help]
#[diag(ast_lowering::sub_tuple_binding)] #[diag(ast_lowering::sub_tuple_binding)]
pub struct SubTupleBinding<'a> { pub struct SubTupleBinding<'a> {
@ -288,7 +288,7 @@ pub struct SubTupleBinding<'a> {
pub ctx: &'a str, pub ctx: &'a str,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::extra_double_dot)] #[diag(ast_lowering::extra_double_dot)]
pub struct ExtraDoubleDot<'a> { pub struct ExtraDoubleDot<'a> {
#[primary_span] #[primary_span]
@ -299,7 +299,7 @@ pub struct ExtraDoubleDot<'a> {
pub ctx: &'a str, pub ctx: &'a str,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[note] #[note]
#[diag(ast_lowering::misplaced_double_dot)] #[diag(ast_lowering::misplaced_double_dot)]
pub struct MisplacedDoubleDot { pub struct MisplacedDoubleDot {
@ -307,35 +307,35 @@ pub struct MisplacedDoubleDot {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::misplaced_relax_trait_bound)] #[diag(ast_lowering::misplaced_relax_trait_bound)]
pub struct MisplacedRelaxTraitBound { pub struct MisplacedRelaxTraitBound {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::not_supported_for_lifetime_binder_async_closure)] #[diag(ast_lowering::not_supported_for_lifetime_binder_async_closure)]
pub struct NotSupportedForLifetimeBinderAsyncClosure { pub struct NotSupportedForLifetimeBinderAsyncClosure {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::arbitrary_expression_in_pattern)] #[diag(ast_lowering::arbitrary_expression_in_pattern)]
pub struct ArbitraryExpressionInPattern { pub struct ArbitraryExpressionInPattern {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::inclusive_range_with_no_end)] #[diag(ast_lowering::inclusive_range_with_no_end)]
pub struct InclusiveRangeWithNoEnd { pub struct InclusiveRangeWithNoEnd {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic, Clone, Copy)] #[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering::trait_fn_async, code = "E0706")] #[diag(ast_lowering::trait_fn_async, code = "E0706")]
#[note] #[note]
#[note(ast_lowering::note2)] #[note(ast_lowering::note2)]

View file

@ -1,12 +1,12 @@
//! Errors emitted by ast_passes. //! Errors emitted by ast_passes.
use rustc_errors::{fluent, AddSubdiagnostic, Applicability, Diagnostic}; use rustc_errors::{fluent, AddToDiagnostic, Applicability, Diagnostic};
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic}; use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
use crate::ast_validation::ForbiddenLetReason; use crate::ast_validation::ForbiddenLetReason;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_passes::forbidden_let)] #[diag(ast_passes::forbidden_let)]
#[note] #[note]
pub struct ForbiddenLet { pub struct ForbiddenLet {
@ -16,7 +16,7 @@ pub struct ForbiddenLet {
pub(crate) reason: ForbiddenLetReason, pub(crate) reason: ForbiddenLetReason,
} }
impl AddSubdiagnostic for ForbiddenLetReason { impl AddToDiagnostic for ForbiddenLetReason {
fn add_to_diagnostic(self, diag: &mut Diagnostic) { fn add_to_diagnostic(self, diag: &mut Diagnostic) {
match self { match self {
Self::GenericForbidden => {} Self::GenericForbidden => {}
@ -30,7 +30,7 @@ impl AddSubdiagnostic for ForbiddenLetReason {
} }
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_passes::forbidden_let_stable)] #[diag(ast_passes::forbidden_let_stable)]
#[note] #[note]
pub struct ForbiddenLetStable { pub struct ForbiddenLetStable {
@ -38,21 +38,21 @@ pub struct ForbiddenLetStable {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_passes::forbidden_assoc_constraint)] #[diag(ast_passes::forbidden_assoc_constraint)]
pub struct ForbiddenAssocConstraint { pub struct ForbiddenAssocConstraint {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_passes::keyword_lifetime)] #[diag(ast_passes::keyword_lifetime)]
pub struct KeywordLifetime { pub struct KeywordLifetime {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_passes::invalid_label)] #[diag(ast_passes::invalid_label)]
pub struct InvalidLabel { pub struct InvalidLabel {
#[primary_span] #[primary_span]
@ -60,7 +60,7 @@ pub struct InvalidLabel {
pub name: Symbol, pub name: Symbol,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_passes::invalid_visibility, code = "E0449")] #[diag(ast_passes::invalid_visibility, code = "E0449")]
pub struct InvalidVisibility { pub struct InvalidVisibility {
#[primary_span] #[primary_span]
@ -71,7 +71,7 @@ pub struct InvalidVisibility {
pub note: Option<InvalidVisibilityNote>, pub note: Option<InvalidVisibilityNote>,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub enum InvalidVisibilityNote { pub enum InvalidVisibilityNote {
#[note(ast_passes::individual_impl_items)] #[note(ast_passes::individual_impl_items)]
IndividualImplItems, IndividualImplItems,
@ -79,7 +79,7 @@ pub enum InvalidVisibilityNote {
IndividualForeignItems, IndividualForeignItems,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_passes::trait_fn_const, code = "E0379")] #[diag(ast_passes::trait_fn_const, code = "E0379")]
pub struct TraitFnConst { pub struct TraitFnConst {
#[primary_span] #[primary_span]
@ -87,21 +87,21 @@ pub struct TraitFnConst {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_passes::forbidden_lifetime_bound)] #[diag(ast_passes::forbidden_lifetime_bound)]
pub struct ForbiddenLifetimeBound { pub struct ForbiddenLifetimeBound {
#[primary_span] #[primary_span]
pub spans: Vec<Span>, pub spans: Vec<Span>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_passes::forbidden_non_lifetime_param)] #[diag(ast_passes::forbidden_non_lifetime_param)]
pub struct ForbiddenNonLifetimeParam { pub struct ForbiddenNonLifetimeParam {
#[primary_span] #[primary_span]
pub spans: Vec<Span>, pub spans: Vec<Span>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_passes::fn_param_too_many)] #[diag(ast_passes::fn_param_too_many)]
pub struct FnParamTooMany { pub struct FnParamTooMany {
#[primary_span] #[primary_span]
@ -109,21 +109,21 @@ pub struct FnParamTooMany {
pub max_num_args: usize, pub max_num_args: usize,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_passes::fn_param_c_var_args_only)] #[diag(ast_passes::fn_param_c_var_args_only)]
pub struct FnParamCVarArgsOnly { pub struct FnParamCVarArgsOnly {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_passes::fn_param_c_var_args_not_last)] #[diag(ast_passes::fn_param_c_var_args_not_last)]
pub struct FnParamCVarArgsNotLast { pub struct FnParamCVarArgsNotLast {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_passes::fn_param_doc_comment)] #[diag(ast_passes::fn_param_doc_comment)]
pub struct FnParamDocComment { pub struct FnParamDocComment {
#[primary_span] #[primary_span]
@ -131,14 +131,14 @@ pub struct FnParamDocComment {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_passes::fn_param_forbidden_attr)] #[diag(ast_passes::fn_param_forbidden_attr)]
pub struct FnParamForbiddenAttr { pub struct FnParamForbiddenAttr {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_passes::fn_param_forbidden_self)] #[diag(ast_passes::fn_param_forbidden_self)]
#[note] #[note]
pub struct FnParamForbiddenSelf { pub struct FnParamForbiddenSelf {
@ -147,7 +147,7 @@ pub struct FnParamForbiddenSelf {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_passes::forbidden_default)] #[diag(ast_passes::forbidden_default)]
pub struct ForbiddenDefault { pub struct ForbiddenDefault {
#[primary_span] #[primary_span]
@ -156,7 +156,7 @@ pub struct ForbiddenDefault {
pub def_span: Span, pub def_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_passes::assoc_const_without_body)] #[diag(ast_passes::assoc_const_without_body)]
pub struct AssocConstWithoutBody { pub struct AssocConstWithoutBody {
#[primary_span] #[primary_span]
@ -165,7 +165,7 @@ pub struct AssocConstWithoutBody {
pub replace_span: Span, pub replace_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_passes::assoc_fn_without_body)] #[diag(ast_passes::assoc_fn_without_body)]
pub struct AssocFnWithoutBody { pub struct AssocFnWithoutBody {
#[primary_span] #[primary_span]
@ -174,7 +174,7 @@ pub struct AssocFnWithoutBody {
pub replace_span: Span, pub replace_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_passes::assoc_type_without_body)] #[diag(ast_passes::assoc_type_without_body)]
pub struct AssocTypeWithoutBody { pub struct AssocTypeWithoutBody {
#[primary_span] #[primary_span]
@ -183,7 +183,7 @@ pub struct AssocTypeWithoutBody {
pub replace_span: Span, pub replace_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_passes::const_without_body)] #[diag(ast_passes::const_without_body)]
pub struct ConstWithoutBody { pub struct ConstWithoutBody {
#[primary_span] #[primary_span]
@ -192,7 +192,7 @@ pub struct ConstWithoutBody {
pub replace_span: Span, pub replace_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_passes::static_without_body)] #[diag(ast_passes::static_without_body)]
pub struct StaticWithoutBody { pub struct StaticWithoutBody {
#[primary_span] #[primary_span]
@ -201,7 +201,7 @@ pub struct StaticWithoutBody {
pub replace_span: Span, pub replace_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_passes::ty_alias_without_body)] #[diag(ast_passes::ty_alias_without_body)]
pub struct TyAliasWithoutBody { pub struct TyAliasWithoutBody {
#[primary_span] #[primary_span]
@ -210,7 +210,7 @@ pub struct TyAliasWithoutBody {
pub replace_span: Span, pub replace_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ast_passes::fn_without_body)] #[diag(ast_passes::fn_without_body)]
pub struct FnWithoutBody { pub struct FnWithoutBody {
#[primary_span] #[primary_span]
@ -227,7 +227,7 @@ pub struct ExternBlockSuggestion {
pub abi: Option<Symbol>, pub abi: Option<Symbol>,
} }
impl AddSubdiagnostic for ExternBlockSuggestion { impl AddToDiagnostic for ExternBlockSuggestion {
fn add_to_diagnostic(self, diag: &mut Diagnostic) { fn add_to_diagnostic(self, diag: &mut Diagnostic) {
let start_suggestion = if let Some(abi) = self.abi { let start_suggestion = if let Some(abi) = self.abi {
format!("extern \"{}\" {{", abi) format!("extern \"{}\" {{", abi)

View file

@ -2,22 +2,21 @@ use std::num::IntErrorKind;
use rustc_ast as ast; use rustc_ast as ast;
use rustc_errors::{ use rustc_errors::{
error_code, fluent, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler, error_code, fluent, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic,
}; };
use rustc_macros::SessionDiagnostic; use rustc_macros::Diagnostic;
use rustc_session::SessionDiagnostic;
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
use crate::UnsupportedLiteralReason; use crate::UnsupportedLiteralReason;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::expected_one_cfg_pattern, code = "E0536")] #[diag(attr::expected_one_cfg_pattern, code = "E0536")]
pub(crate) struct ExpectedOneCfgPattern { pub(crate) struct ExpectedOneCfgPattern {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::invalid_predicate, code = "E0537")] #[diag(attr::invalid_predicate, code = "E0537")]
pub(crate) struct InvalidPredicate { pub(crate) struct InvalidPredicate {
#[primary_span] #[primary_span]
@ -26,7 +25,7 @@ pub(crate) struct InvalidPredicate {
pub predicate: String, pub predicate: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::multiple_item, code = "E0538")] #[diag(attr::multiple_item, code = "E0538")]
pub(crate) struct MultipleItem { pub(crate) struct MultipleItem {
#[primary_span] #[primary_span]
@ -35,7 +34,7 @@ pub(crate) struct MultipleItem {
pub item: String, pub item: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::incorrect_meta_item, code = "E0539")] #[diag(attr::incorrect_meta_item, code = "E0539")]
pub(crate) struct IncorrectMetaItem { pub(crate) struct IncorrectMetaItem {
#[primary_span] #[primary_span]
@ -50,7 +49,7 @@ pub(crate) struct UnknownMetaItem<'a> {
} }
// Manual implementation to be able to format `expected` items correctly. // Manual implementation to be able to format `expected` items correctly.
impl<'a> SessionDiagnostic<'a> for UnknownMetaItem<'_> { impl<'a> IntoDiagnostic<'a> for UnknownMetaItem<'_> {
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> { fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
let expected = self.expected.iter().map(|name| format!("`{}`", name)).collect::<Vec<_>>(); let expected = self.expected.iter().map(|name| format!("`{}`", name)).collect::<Vec<_>>();
let mut diag = handler.struct_span_err_with_code( let mut diag = handler.struct_span_err_with_code(
@ -65,28 +64,28 @@ impl<'a> SessionDiagnostic<'a> for UnknownMetaItem<'_> {
} }
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::missing_since, code = "E0542")] #[diag(attr::missing_since, code = "E0542")]
pub(crate) struct MissingSince { pub(crate) struct MissingSince {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::missing_note, code = "E0543")] #[diag(attr::missing_note, code = "E0543")]
pub(crate) struct MissingNote { pub(crate) struct MissingNote {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::multiple_stability_levels, code = "E0544")] #[diag(attr::multiple_stability_levels, code = "E0544")]
pub(crate) struct MultipleStabilityLevels { pub(crate) struct MultipleStabilityLevels {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::invalid_issue_string, code = "E0545")] #[diag(attr::invalid_issue_string, code = "E0545")]
pub(crate) struct InvalidIssueString { pub(crate) struct InvalidIssueString {
#[primary_span] #[primary_span]
@ -98,7 +97,7 @@ pub(crate) struct InvalidIssueString {
// The error kinds of `IntErrorKind` are duplicated here in order to allow the messages to be // The error kinds of `IntErrorKind` are duplicated here in order to allow the messages to be
// translatable. // translatable.
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub(crate) enum InvalidIssueStringCause { pub(crate) enum InvalidIssueStringCause {
#[label(attr::must_not_be_zero)] #[label(attr::must_not_be_zero)]
MustNotBeZero { MustNotBeZero {
@ -144,21 +143,21 @@ impl InvalidIssueStringCause {
} }
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::missing_feature, code = "E0546")] #[diag(attr::missing_feature, code = "E0546")]
pub(crate) struct MissingFeature { pub(crate) struct MissingFeature {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::non_ident_feature, code = "E0546")] #[diag(attr::non_ident_feature, code = "E0546")]
pub(crate) struct NonIdentFeature { pub(crate) struct NonIdentFeature {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::missing_issue, code = "E0547")] #[diag(attr::missing_issue, code = "E0547")]
pub(crate) struct MissingIssue { pub(crate) struct MissingIssue {
#[primary_span] #[primary_span]
@ -167,7 +166,7 @@ pub(crate) struct MissingIssue {
// FIXME: This diagnostic is identical to `IncorrectMetaItem`, barring the error code. Consider // FIXME: This diagnostic is identical to `IncorrectMetaItem`, barring the error code. Consider
// changing this to `IncorrectMetaItem`. See #51489. // changing this to `IncorrectMetaItem`. See #51489.
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::incorrect_meta_item, code = "E0551")] #[diag(attr::incorrect_meta_item, code = "E0551")]
pub(crate) struct IncorrectMetaItem2 { pub(crate) struct IncorrectMetaItem2 {
#[primary_span] #[primary_span]
@ -176,14 +175,14 @@ pub(crate) struct IncorrectMetaItem2 {
// FIXME: Why is this the same error code as `InvalidReprHintNoParen` and `InvalidReprHintNoValue`? // FIXME: Why is this the same error code as `InvalidReprHintNoParen` and `InvalidReprHintNoValue`?
// It is more similar to `IncorrectReprFormatGeneric`. // It is more similar to `IncorrectReprFormatGeneric`.
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::incorrect_repr_format_packed_one_or_zero_arg, code = "E0552")] #[diag(attr::incorrect_repr_format_packed_one_or_zero_arg, code = "E0552")]
pub(crate) struct IncorrectReprFormatPackedOneOrZeroArg { pub(crate) struct IncorrectReprFormatPackedOneOrZeroArg {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::invalid_repr_hint_no_paren, code = "E0552")] #[diag(attr::invalid_repr_hint_no_paren, code = "E0552")]
pub(crate) struct InvalidReprHintNoParen { pub(crate) struct InvalidReprHintNoParen {
#[primary_span] #[primary_span]
@ -192,7 +191,7 @@ pub(crate) struct InvalidReprHintNoParen {
pub name: String, pub name: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::invalid_repr_hint_no_value, code = "E0552")] #[diag(attr::invalid_repr_hint_no_value, code = "E0552")]
pub(crate) struct InvalidReprHintNoValue { pub(crate) struct InvalidReprHintNoValue {
#[primary_span] #[primary_span]
@ -209,7 +208,7 @@ pub(crate) struct UnsupportedLiteral {
pub start_point_span: Span, pub start_point_span: Span,
} }
impl<'a> SessionDiagnostic<'a> for UnsupportedLiteral { impl<'a> IntoDiagnostic<'a> for UnsupportedLiteral {
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> { fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
let mut diag = handler.struct_span_err_with_code( let mut diag = handler.struct_span_err_with_code(
self.span, self.span,
@ -237,7 +236,7 @@ impl<'a> SessionDiagnostic<'a> for UnsupportedLiteral {
} }
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::invalid_repr_align_need_arg, code = "E0589")] #[diag(attr::invalid_repr_align_need_arg, code = "E0589")]
pub(crate) struct InvalidReprAlignNeedArg { pub(crate) struct InvalidReprAlignNeedArg {
#[primary_span] #[primary_span]
@ -245,7 +244,7 @@ pub(crate) struct InvalidReprAlignNeedArg {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::invalid_repr_generic, code = "E0589")] #[diag(attr::invalid_repr_generic, code = "E0589")]
pub(crate) struct InvalidReprGeneric<'a> { pub(crate) struct InvalidReprGeneric<'a> {
#[primary_span] #[primary_span]
@ -255,14 +254,14 @@ pub(crate) struct InvalidReprGeneric<'a> {
pub error_part: &'a str, pub error_part: &'a str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::incorrect_repr_format_align_one_arg, code = "E0693")] #[diag(attr::incorrect_repr_format_align_one_arg, code = "E0693")]
pub(crate) struct IncorrectReprFormatAlignOneArg { pub(crate) struct IncorrectReprFormatAlignOneArg {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::incorrect_repr_format_generic, code = "E0693")] #[diag(attr::incorrect_repr_format_generic, code = "E0693")]
pub(crate) struct IncorrectReprFormatGeneric<'a> { pub(crate) struct IncorrectReprFormatGeneric<'a> {
#[primary_span] #[primary_span]
@ -274,7 +273,7 @@ pub(crate) struct IncorrectReprFormatGeneric<'a> {
pub cause: Option<IncorrectReprFormatGenericCause<'a>>, pub cause: Option<IncorrectReprFormatGenericCause<'a>>,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub(crate) enum IncorrectReprFormatGenericCause<'a> { pub(crate) enum IncorrectReprFormatGenericCause<'a> {
#[suggestion(attr::suggestion, code = "{name}({int})", applicability = "machine-applicable")] #[suggestion(attr::suggestion, code = "{name}({int})", applicability = "machine-applicable")]
Int { Int {
@ -317,28 +316,28 @@ impl<'a> IncorrectReprFormatGenericCause<'a> {
} }
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::rustc_promotable_pairing, code = "E0717")] #[diag(attr::rustc_promotable_pairing, code = "E0717")]
pub(crate) struct RustcPromotablePairing { pub(crate) struct RustcPromotablePairing {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::rustc_allowed_unstable_pairing, code = "E0789")] #[diag(attr::rustc_allowed_unstable_pairing, code = "E0789")]
pub(crate) struct RustcAllowedUnstablePairing { pub(crate) struct RustcAllowedUnstablePairing {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::cfg_predicate_identifier)] #[diag(attr::cfg_predicate_identifier)]
pub(crate) struct CfgPredicateIdentifier { pub(crate) struct CfgPredicateIdentifier {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::deprecated_item_suggestion)] #[diag(attr::deprecated_item_suggestion)]
pub(crate) struct DeprecatedItemSuggestion { pub(crate) struct DeprecatedItemSuggestion {
#[primary_span] #[primary_span]
@ -351,21 +350,21 @@ pub(crate) struct DeprecatedItemSuggestion {
pub details: (), pub details: (),
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::expected_single_version_literal)] #[diag(attr::expected_single_version_literal)]
pub(crate) struct ExpectedSingleVersionLiteral { pub(crate) struct ExpectedSingleVersionLiteral {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::expected_version_literal)] #[diag(attr::expected_version_literal)]
pub(crate) struct ExpectedVersionLiteral { pub(crate) struct ExpectedVersionLiteral {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::expects_feature_list)] #[diag(attr::expects_feature_list)]
pub(crate) struct ExpectsFeatureList { pub(crate) struct ExpectsFeatureList {
#[primary_span] #[primary_span]
@ -374,7 +373,7 @@ pub(crate) struct ExpectsFeatureList {
pub name: String, pub name: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::expects_features)] #[diag(attr::expects_features)]
pub(crate) struct ExpectsFeatures { pub(crate) struct ExpectsFeatures {
#[primary_span] #[primary_span]
@ -383,14 +382,14 @@ pub(crate) struct ExpectsFeatures {
pub name: String, pub name: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::soft_no_args)] #[diag(attr::soft_no_args)]
pub(crate) struct SoftNoArgs { pub(crate) struct SoftNoArgs {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(attr::unknown_version_literal)] #[diag(attr::unknown_version_literal)]
pub(crate) struct UnknownVersionLiteral { pub(crate) struct UnknownVersionLiteral {
#[primary_span] #[primary_span]

View file

@ -1,11 +1,11 @@
use rustc_errors::{IntoDiagnosticArg, MultiSpan}; use rustc_errors::{IntoDiagnosticArg, MultiSpan};
use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic}; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;
use rustc_span::Span; use rustc_span::Span;
use crate::diagnostics::RegionName; use crate::diagnostics::RegionName;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(borrowck::move_unsized, code = "E0161")] #[diag(borrowck::move_unsized, code = "E0161")]
pub(crate) struct MoveUnsized<'tcx> { pub(crate) struct MoveUnsized<'tcx> {
pub ty: Ty<'tcx>, pub ty: Ty<'tcx>,
@ -14,7 +14,7 @@ pub(crate) struct MoveUnsized<'tcx> {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(borrowck::higher_ranked_lifetime_error)] #[diag(borrowck::higher_ranked_lifetime_error)]
pub(crate) struct HigherRankedLifetimeError { pub(crate) struct HigherRankedLifetimeError {
#[subdiagnostic] #[subdiagnostic]
@ -23,7 +23,7 @@ pub(crate) struct HigherRankedLifetimeError {
pub span: Span, pub span: Span,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub(crate) enum HigherRankedErrorCause { pub(crate) enum HigherRankedErrorCause {
#[note(borrowck::could_not_prove)] #[note(borrowck::could_not_prove)]
CouldNotProve { predicate: String }, CouldNotProve { predicate: String },
@ -31,14 +31,14 @@ pub(crate) enum HigherRankedErrorCause {
CouldNotNormalize { value: String }, CouldNotNormalize { value: String },
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(borrowck::higher_ranked_subtype_error)] #[diag(borrowck::higher_ranked_subtype_error)]
pub(crate) struct HigherRankedSubtypeError { pub(crate) struct HigherRankedSubtypeError {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(borrowck::generic_does_not_live_long_enough)] #[diag(borrowck::generic_does_not_live_long_enough)]
pub(crate) struct GenericDoesNotLiveLongEnough { pub(crate) struct GenericDoesNotLiveLongEnough {
pub kind: String, pub kind: String,
@ -53,7 +53,7 @@ pub(crate) struct VarNeedNotMut {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(borrowck::const_not_used_in_type_alias)] #[diag(borrowck::const_not_used_in_type_alias)]
pub(crate) struct ConstNotUsedTraitAlias { pub(crate) struct ConstNotUsedTraitAlias {
pub ct: String, pub ct: String,
@ -61,7 +61,7 @@ pub(crate) struct ConstNotUsedTraitAlias {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(borrowck::var_cannot_escape_closure)] #[diag(borrowck::var_cannot_escape_closure)]
#[note] #[note]
#[note(borrowck::cannot_escape)] #[note(borrowck::cannot_escape)]
@ -72,7 +72,7 @@ pub(crate) struct FnMutError {
pub ty_err: FnMutReturnTypeErr, pub ty_err: FnMutReturnTypeErr,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub(crate) enum VarHereDenote { pub(crate) enum VarHereDenote {
#[label(borrowck::var_here_captured)] #[label(borrowck::var_here_captured)]
Captured { Captured {
@ -91,7 +91,7 @@ pub(crate) enum VarHereDenote {
}, },
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub(crate) enum FnMutReturnTypeErr { pub(crate) enum FnMutReturnTypeErr {
#[label(borrowck::returned_closure_escaped)] #[label(borrowck::returned_closure_escaped)]
ReturnClosure { ReturnClosure {
@ -110,14 +110,14 @@ pub(crate) enum FnMutReturnTypeErr {
}, },
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(borrowck::lifetime_constraints_error)] #[diag(borrowck::lifetime_constraints_error)]
pub(crate) struct LifetimeOutliveErr { pub(crate) struct LifetimeOutliveErr {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub(crate) enum LifetimeReturnCategoryErr<'a> { pub(crate) enum LifetimeReturnCategoryErr<'a> {
#[label(borrowck::returned_lifetime_wrong)] #[label(borrowck::returned_lifetime_wrong)]
WrongReturn { WrongReturn {
@ -149,7 +149,7 @@ impl IntoDiagnosticArg for RegionName {
} }
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub(crate) enum RequireStaticErr { pub(crate) enum RequireStaticErr {
#[note(borrowck::used_impl_require_static)] #[note(borrowck::used_impl_require_static)]
UsedImpl { UsedImpl {

View file

@ -8,7 +8,7 @@ use rustc_ast::tokenstream::TokenStream;
use rustc_attr as attr; use rustc_attr as attr;
use rustc_errors::PResult; use rustc_errors::PResult;
use rustc_expand::base::{self, *}; use rustc_expand::base::{self, *};
use rustc_macros::SessionDiagnostic; use rustc_macros::Diagnostic;
use rustc_span::Span; use rustc_span::Span;
pub fn expand_cfg( pub fn expand_cfg(
@ -35,7 +35,7 @@ pub fn expand_cfg(
} }
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(builtin_macros::requires_cfg_pattern)] #[diag(builtin_macros::requires_cfg_pattern)]
struct RequiresCfgPattern { struct RequiresCfgPattern {
#[primary_span] #[primary_span]
@ -43,7 +43,7 @@ struct RequiresCfgPattern {
span: Span, span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(builtin_macros::expected_one_cfg_pattern)] #[diag(builtin_macros::expected_one_cfg_pattern)]
struct OneCfgPattern { struct OneCfgPattern {
#[primary_span] #[primary_span]

View file

@ -1,8 +1,8 @@
use rustc_hir::ConstContext; use rustc_hir::ConstContext;
use rustc_macros::SessionDiagnostic; use rustc_macros::Diagnostic;
use rustc_span::Span; use rustc_span::Span;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(const_eval::unstable_in_stable)] #[diag(const_eval::unstable_in_stable)]
pub(crate) struct UnstableInStable { pub(crate) struct UnstableInStable {
pub gate: String, pub gate: String,
@ -21,14 +21,14 @@ pub(crate) struct UnstableInStable {
pub attr_span: Span, pub attr_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(const_eval::thread_local_access, code = "E0625")] #[diag(const_eval::thread_local_access, code = "E0625")]
pub(crate) struct NonConstOpErr { pub(crate) struct NonConstOpErr {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(const_eval::static_access, code = "E0013")] #[diag(const_eval::static_access, code = "E0013")]
#[help] #[help]
pub(crate) struct StaticAccessErr { pub(crate) struct StaticAccessErr {
@ -40,7 +40,7 @@ pub(crate) struct StaticAccessErr {
pub teach: Option<()>, pub teach: Option<()>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(const_eval::raw_ptr_to_int)] #[diag(const_eval::raw_ptr_to_int)]
#[note] #[note]
#[note(const_eval::note2)] #[note(const_eval::note2)]
@ -49,7 +49,7 @@ pub(crate) struct RawPtrToIntErr {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(const_eval::raw_ptr_comparison)] #[diag(const_eval::raw_ptr_comparison)]
#[note] #[note]
pub(crate) struct RawPtrComparisonErr { pub(crate) struct RawPtrComparisonErr {
@ -57,14 +57,14 @@ pub(crate) struct RawPtrComparisonErr {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(const_eval::panic_non_str)] #[diag(const_eval::panic_non_str)]
pub(crate) struct PanicNonStrErr { pub(crate) struct PanicNonStrErr {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(const_eval::mut_deref, code = "E0658")] #[diag(const_eval::mut_deref, code = "E0658")]
pub(crate) struct MutDerefErr { pub(crate) struct MutDerefErr {
#[primary_span] #[primary_span]
@ -72,7 +72,7 @@ pub(crate) struct MutDerefErr {
pub kind: ConstContext, pub kind: ConstContext,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(const_eval::transient_mut_borrow, code = "E0658")] #[diag(const_eval::transient_mut_borrow, code = "E0658")]
pub(crate) struct TransientMutBorrowErr { pub(crate) struct TransientMutBorrowErr {
#[primary_span] #[primary_span]
@ -80,7 +80,7 @@ pub(crate) struct TransientMutBorrowErr {
pub kind: ConstContext, pub kind: ConstContext,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(const_eval::transient_mut_borrow_raw, code = "E0658")] #[diag(const_eval::transient_mut_borrow_raw, code = "E0658")]
pub(crate) struct TransientMutBorrowErrRaw { pub(crate) struct TransientMutBorrowErrRaw {
#[primary_span] #[primary_span]
@ -88,7 +88,7 @@ pub(crate) struct TransientMutBorrowErrRaw {
pub kind: ConstContext, pub kind: ConstContext,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(const_eval::max_num_nodes_in_const)] #[diag(const_eval::max_num_nodes_in_const)]
pub(crate) struct MaxNumNodesInConstErr { pub(crate) struct MaxNumNodesInConstErr {
#[primary_span] #[primary_span]
@ -96,7 +96,7 @@ pub(crate) struct MaxNumNodesInConstErr {
pub global_const_id: String, pub global_const_id: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(const_eval::unallowed_fn_pointer_call)] #[diag(const_eval::unallowed_fn_pointer_call)]
pub(crate) struct UnallowedFnPointerCall { pub(crate) struct UnallowedFnPointerCall {
#[primary_span] #[primary_span]
@ -104,7 +104,7 @@ pub(crate) struct UnallowedFnPointerCall {
pub kind: ConstContext, pub kind: ConstContext,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(const_eval::unstable_const_fn)] #[diag(const_eval::unstable_const_fn)]
pub(crate) struct UnstableConstFn { pub(crate) struct UnstableConstFn {
#[primary_span] #[primary_span]
@ -112,7 +112,7 @@ pub(crate) struct UnstableConstFn {
pub def_path: String, pub def_path: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(const_eval::unallowed_mutable_refs, code = "E0764")] #[diag(const_eval::unallowed_mutable_refs, code = "E0764")]
pub(crate) struct UnallowedMutableRefs { pub(crate) struct UnallowedMutableRefs {
#[primary_span] #[primary_span]
@ -122,7 +122,7 @@ pub(crate) struct UnallowedMutableRefs {
pub teach: Option<()>, pub teach: Option<()>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(const_eval::unallowed_mutable_refs_raw, code = "E0764")] #[diag(const_eval::unallowed_mutable_refs_raw, code = "E0764")]
pub(crate) struct UnallowedMutableRefsRaw { pub(crate) struct UnallowedMutableRefsRaw {
#[primary_span] #[primary_span]
@ -131,7 +131,7 @@ pub(crate) struct UnallowedMutableRefsRaw {
#[note(const_eval::teach_note)] #[note(const_eval::teach_note)]
pub teach: Option<()>, pub teach: Option<()>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(const_eval::non_const_fmt_macro_call, code = "E0015")] #[diag(const_eval::non_const_fmt_macro_call, code = "E0015")]
pub(crate) struct NonConstFmtMacroCall { pub(crate) struct NonConstFmtMacroCall {
#[primary_span] #[primary_span]
@ -139,7 +139,7 @@ pub(crate) struct NonConstFmtMacroCall {
pub kind: ConstContext, pub kind: ConstContext,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(const_eval::non_const_fn_call, code = "E0015")] #[diag(const_eval::non_const_fn_call, code = "E0015")]
pub(crate) struct NonConstFnCall { pub(crate) struct NonConstFnCall {
#[primary_span] #[primary_span]
@ -148,7 +148,7 @@ pub(crate) struct NonConstFnCall {
pub kind: ConstContext, pub kind: ConstContext,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(const_eval::unallowed_op_in_const_context)] #[diag(const_eval::unallowed_op_in_const_context)]
pub(crate) struct UnallowedOpInConstContext { pub(crate) struct UnallowedOpInConstContext {
#[primary_span] #[primary_span]
@ -156,7 +156,7 @@ pub(crate) struct UnallowedOpInConstContext {
pub msg: String, pub msg: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(const_eval::unallowed_heap_allocations, code = "E0010")] #[diag(const_eval::unallowed_heap_allocations, code = "E0010")]
pub(crate) struct UnallowedHeapAllocations { pub(crate) struct UnallowedHeapAllocations {
#[primary_span] #[primary_span]
@ -167,7 +167,7 @@ pub(crate) struct UnallowedHeapAllocations {
pub teach: Option<()>, pub teach: Option<()>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(const_eval::unallowed_inline_asm, code = "E0015")] #[diag(const_eval::unallowed_inline_asm, code = "E0015")]
pub(crate) struct UnallowedInlineAsm { pub(crate) struct UnallowedInlineAsm {
#[primary_span] #[primary_span]
@ -175,7 +175,7 @@ pub(crate) struct UnallowedInlineAsm {
pub kind: ConstContext, pub kind: ConstContext,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(const_eval::interior_mutable_data_refer, code = "E0492")] #[diag(const_eval::interior_mutable_data_refer, code = "E0492")]
pub(crate) struct InteriorMutableDataRefer { pub(crate) struct InteriorMutableDataRefer {
#[primary_span] #[primary_span]
@ -188,7 +188,7 @@ pub(crate) struct InteriorMutableDataRefer {
pub teach: Option<()>, pub teach: Option<()>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(const_eval::interior_mutability_borrow)] #[diag(const_eval::interior_mutability_borrow)]
pub(crate) struct InteriorMutabilityBorrow { pub(crate) struct InteriorMutabilityBorrow {
#[primary_span] #[primary_span]

View file

@ -1,38 +1,38 @@
use rustc_macros::SessionDiagnostic; use rustc_macros::Diagnostic;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(driver::rlink_unable_to_read)] #[diag(driver::rlink_unable_to_read)]
pub(crate) struct RlinkUnableToRead { pub(crate) struct RlinkUnableToRead {
pub err: std::io::Error, pub err: std::io::Error,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(driver::rlink_wrong_file_type)] #[diag(driver::rlink_wrong_file_type)]
pub(crate) struct RLinkWrongFileType; pub(crate) struct RLinkWrongFileType;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(driver::rlink_empty_version_number)] #[diag(driver::rlink_empty_version_number)]
pub(crate) struct RLinkEmptyVersionNumber; pub(crate) struct RLinkEmptyVersionNumber;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(driver::rlink_encoding_version_mismatch)] #[diag(driver::rlink_encoding_version_mismatch)]
pub(crate) struct RLinkEncodingVersionMismatch { pub(crate) struct RLinkEncodingVersionMismatch {
pub version_array: String, pub version_array: String,
pub rlink_version: u32, pub rlink_version: u32,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(driver::rlink_rustc_version_mismatch)] #[diag(driver::rlink_rustc_version_mismatch)]
pub(crate) struct RLinkRustcVersionMismatch<'a> { pub(crate) struct RLinkRustcVersionMismatch<'a> {
pub rustc_version: String, pub rustc_version: String,
pub current_version: &'a str, pub current_version: &'a str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(driver::rlink_no_a_file)] #[diag(driver::rlink_no_a_file)]
pub(crate) struct RlinkNotAFile; pub(crate) struct RlinkNotAFile;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(driver::unpretty_dump_fail)] #[diag(driver::unpretty_dump_fail)]
pub(crate) struct UnprettyDumpFail { pub(crate) struct UnprettyDumpFail {
pub path: String, pub path: String,

View file

@ -51,7 +51,7 @@ lint_non_existant_doc_keyword = found non-existing keyword `{$keyword}` used in
.help = only existing keywords are allowed in core/std .help = only existing keywords are allowed in core/std
lint_diag_out_of_impl = lint_diag_out_of_impl =
diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls
lint_untranslatable_diag = diagnostics should be created using translatable messages lint_untranslatable_diag = diagnostics should be created using translatable messages

View file

@ -268,14 +268,14 @@ type FluentId = Cow<'static, str>;
/// Translatable messages for subdiagnostics are typically attributes attached to a larger Fluent /// Translatable messages for subdiagnostics are typically attributes attached to a larger Fluent
/// message so messages of this type must be combined with a `DiagnosticMessage` (using /// message so messages of this type must be combined with a `DiagnosticMessage` (using
/// `DiagnosticMessage::with_subdiagnostic_message`) before rendering. However, subdiagnostics from /// `DiagnosticMessage::with_subdiagnostic_message`) before rendering. However, subdiagnostics from
/// the `SessionSubdiagnostic` derive refer to Fluent identifiers directly. /// the `Subdiagnostic` derive refer to Fluent identifiers directly.
#[rustc_diagnostic_item = "SubdiagnosticMessage"] #[rustc_diagnostic_item = "SubdiagnosticMessage"]
pub enum SubdiagnosticMessage { pub enum SubdiagnosticMessage {
/// Non-translatable diagnostic message. /// Non-translatable diagnostic message.
// FIXME(davidtwco): can a `Cow<'static, str>` be used here? // FIXME(davidtwco): can a `Cow<'static, str>` be used here?
Str(String), Str(String),
/// Identifier of a Fluent message. Instances of this variant are generated by the /// Identifier of a Fluent message. Instances of this variant are generated by the
/// `SessionSubdiagnostic` derive. /// `Subdiagnostic` derive.
FluentIdentifier(FluentId), FluentIdentifier(FluentId),
/// Attribute of a Fluent message. Needs to be combined with a Fluent identifier to produce an /// Attribute of a Fluent message. Needs to be combined with a Fluent identifier to produce an
/// actual translated message. Instances of this variant are generated by the `fluent_messages` /// actual translated message. Instances of this variant are generated by the `fluent_messages`

View file

@ -35,7 +35,7 @@ pub enum DiagnosticArgValue<'source> {
Number(usize), Number(usize),
} }
/// Converts a value of a type into a `DiagnosticArg` (typically a field of a `SessionDiagnostic` /// Converts a value of a type into a `DiagnosticArg` (typically a field of an `IntoDiagnostic`
/// struct). Implemented as a custom trait rather than `From` so that it is implemented on the type /// struct). Implemented as a custom trait rather than `From` so that it is implemented on the type
/// being converted rather than on `DiagnosticArgValue`, which enables types from other `rustc_*` /// being converted rather than on `DiagnosticArgValue`, which enables types from other `rustc_*`
/// crates to implement this. /// crates to implement this.
@ -176,9 +176,10 @@ impl IntoDiagnosticArg for hir::ConstContext {
} }
/// Trait implemented by error types. This should not be implemented manually. Instead, use /// Trait implemented by error types. This should not be implemented manually. Instead, use
/// `#[derive(SessionSubdiagnostic)]` -- see [rustc_macros::SessionSubdiagnostic]. /// `#[derive(Subdiagnostic)]` -- see [rustc_macros::Subdiagnostic].
#[rustc_diagnostic_item = "AddSubdiagnostic"] #[cfg_attr(bootstrap, rustc_diagnostic_item = "AddSubdiagnostic")]
pub trait AddSubdiagnostic { #[cfg_attr(not(bootstrap), rustc_diagnostic_item = "AddToDiagnostic")]
pub trait AddToDiagnostic {
/// Add a subdiagnostic to an existing diagnostic. /// Add a subdiagnostic to an existing diagnostic.
fn add_to_diagnostic(self, diag: &mut Diagnostic); fn add_to_diagnostic(self, diag: &mut Diagnostic);
} }
@ -891,9 +892,9 @@ impl Diagnostic {
self self
} }
/// Add a subdiagnostic from a type that implements `SessionSubdiagnostic` - see /// Add a subdiagnostic from a type that implements `Subdiagnostic` - see
/// [rustc_macros::SessionSubdiagnostic]. /// [rustc_macros::Subdiagnostic].
pub fn subdiagnostic(&mut self, subdiagnostic: impl AddSubdiagnostic) -> &mut Self { pub fn subdiagnostic(&mut self, subdiagnostic: impl AddToDiagnostic) -> &mut Self {
subdiagnostic.add_to_diagnostic(self); subdiagnostic.add_to_diagnostic(self);
self self
} }

View file

@ -13,6 +13,16 @@ use std::marker::PhantomData;
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use std::thread::panicking; use std::thread::panicking;
/// Trait implemented by error types. This should not be implemented manually. Instead, use
/// `#[derive(Diagnostic)]` -- see [rustc_macros::Diagnostic].
#[cfg_attr(bootstrap, rustc_diagnostic_item = "SessionDiagnostic")]
#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "IntoDiagnostic")]
pub trait IntoDiagnostic<'a, T: EmissionGuarantee = ErrorGuaranteed> {
/// Write out as a diagnostic out of `Handler`.
#[must_use]
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, T>;
}
/// Used for emitting structured error messages and other diagnostic information. /// Used for emitting structured error messages and other diagnostic information.
/// ///
/// If there is some state in a downstream crate you would like to /// If there is some state in a downstream crate you would like to
@ -570,7 +580,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
forward!(pub fn subdiagnostic( forward!(pub fn subdiagnostic(
&mut self, &mut self,
subdiagnostic: impl crate::AddSubdiagnostic subdiagnostic: impl crate::AddToDiagnostic
) -> &mut Self); ) -> &mut Self);
} }

View file

@ -60,6 +60,7 @@ mod snippet;
mod styled_buffer; mod styled_buffer;
pub mod translation; pub mod translation;
pub use diagnostic_builder::IntoDiagnostic;
pub use snippet::Style; pub use snippet::Style;
pub type PResult<'a, T> = Result<T, DiagnosticBuilder<'a, ErrorGuaranteed>>; pub type PResult<'a, T> = Result<T, DiagnosticBuilder<'a, ErrorGuaranteed>>;
@ -370,7 +371,7 @@ impl fmt::Display for ExplicitBug {
impl error::Error for ExplicitBug {} impl error::Error for ExplicitBug {}
pub use diagnostic::{ pub use diagnostic::{
AddSubdiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgFromDisplay, AddToDiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgFromDisplay,
DiagnosticArgValue, DiagnosticId, DiagnosticStyledString, IntoDiagnosticArg, SubDiagnostic, DiagnosticArgValue, DiagnosticId, DiagnosticStyledString, IntoDiagnosticArg, SubDiagnostic,
}; };
pub use diagnostic_builder::{DiagnosticBuilder, EmissionGuarantee, LintDiagnosticBuilder}; pub use diagnostic_builder::{DiagnosticBuilder, EmissionGuarantee, LintDiagnosticBuilder};
@ -436,11 +437,11 @@ struct HandlerInner {
/// have been converted. /// have been converted.
check_unstable_expect_diagnostics: bool, check_unstable_expect_diagnostics: bool,
/// Expected [`Diagnostic`]s store a [`LintExpectationId`] as part of /// Expected [`Diagnostic`][diagnostic::Diagnostic]s store a [`LintExpectationId`] as part of
/// the lint level. [`LintExpectationId`]s created early during the compilation /// the lint level. [`LintExpectationId`]s created early during the compilation
/// (before `HirId`s have been defined) are not stable and can therefore not be /// (before `HirId`s have been defined) are not stable and can therefore not be
/// stored on disk. This buffer stores these diagnostics until the ID has been /// stored on disk. This buffer stores these diagnostics until the ID has been
/// replaced by a stable [`LintExpectationId`]. The [`Diagnostic`]s are the /// replaced by a stable [`LintExpectationId`]. The [`Diagnostic`][diagnostic::Diagnostic]s are the
/// submitted for storage and added to the list of fulfilled expectations. /// submitted for storage and added to the list of fulfilled expectations.
unstable_expect_diagnostics: Vec<Diagnostic>, unstable_expect_diagnostics: Vec<Diagnostic>,
@ -1028,6 +1029,39 @@ impl Handler {
self.inner.borrow_mut().emit_diagnostic(diagnostic) self.inner.borrow_mut().emit_diagnostic(diagnostic)
} }
pub fn emit_err<'a>(&'a self, err: impl IntoDiagnostic<'a>) -> ErrorGuaranteed {
self.create_err(err).emit()
}
pub fn create_err<'a>(
&'a self,
err: impl IntoDiagnostic<'a>,
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
err.into_diagnostic(self)
}
pub fn create_warning<'a>(
&'a self,
warning: impl IntoDiagnostic<'a, ()>,
) -> DiagnosticBuilder<'a, ()> {
warning.into_diagnostic(self)
}
pub fn emit_warning<'a>(&'a self, warning: impl IntoDiagnostic<'a, ()>) {
self.create_warning(warning).emit()
}
pub fn create_fatal<'a>(
&'a self,
fatal: impl IntoDiagnostic<'a, !>,
) -> DiagnosticBuilder<'a, !> {
fatal.into_diagnostic(self)
}
pub fn emit_fatal<'a>(&'a self, fatal: impl IntoDiagnostic<'a, !>) -> ! {
self.create_fatal(fatal).emit()
}
fn emit_diag_at_span( fn emit_diag_at_span(
&self, &self,
mut diag: Diagnostic, mut diag: Diagnostic,

View file

@ -10,11 +10,13 @@ use rustc_ast::{self as ast, AttrVec, Attribute, HasAttrs, Item, NodeId, PatKind
use rustc_attr::{self as attr, Deprecation, Stability}; use rustc_attr::{self as attr, Deprecation, Stability};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_data_structures::sync::{self, Lrc}; use rustc_data_structures::sync::{self, Lrc};
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan, PResult}; use rustc_errors::{
Applicability, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic, MultiSpan, PResult,
};
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT; use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics}; use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics};
use rustc_parse::{self, parser, MACRO_ARGUMENTS}; use rustc_parse::{self, parser, MACRO_ARGUMENTS};
use rustc_session::{parse::ParseSess, Limit, Session, SessionDiagnostic}; use rustc_session::{parse::ParseSess, Limit, Session};
use rustc_span::def_id::{CrateNum, DefId, LocalDefId}; use rustc_span::def_id::{CrateNum, DefId, LocalDefId};
use rustc_span::edition::Edition; use rustc_span::edition::Edition;
use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId}; use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId};
@ -1109,12 +1111,12 @@ impl<'a> ExtCtxt<'a> {
pub fn create_err( pub fn create_err(
&self, &self,
err: impl SessionDiagnostic<'a>, err: impl IntoDiagnostic<'a>,
) -> DiagnosticBuilder<'a, ErrorGuaranteed> { ) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
self.sess.create_err(err) self.sess.create_err(err)
} }
pub fn emit_err(&self, err: impl SessionDiagnostic<'a>) -> ErrorGuaranteed { pub fn emit_err(&self, err: impl IntoDiagnostic<'a>) -> ErrorGuaranteed {
self.sess.emit_err(err) self.sess.emit_err(err)
} }

View file

@ -1,29 +1,29 @@
use rustc_macros::SessionDiagnostic; use rustc_macros::Diagnostic;
use rustc_span::symbol::MacroRulesNormalizedIdent; use rustc_span::symbol::MacroRulesNormalizedIdent;
use rustc_span::Span; use rustc_span::Span;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(expand::expr_repeat_no_syntax_vars)] #[diag(expand::expr_repeat_no_syntax_vars)]
pub(crate) struct NoSyntaxVarsExprRepeat { pub(crate) struct NoSyntaxVarsExprRepeat {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(expand::must_repeat_once)] #[diag(expand::must_repeat_once)]
pub(crate) struct MustRepeatOnce { pub(crate) struct MustRepeatOnce {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(expand::count_repetition_misplaced)] #[diag(expand::count_repetition_misplaced)]
pub(crate) struct CountRepetitionMisplaced { pub(crate) struct CountRepetitionMisplaced {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(expand::meta_var_expr_unrecognized_var)] #[diag(expand::meta_var_expr_unrecognized_var)]
pub(crate) struct MetaVarExprUnrecognizedVar { pub(crate) struct MetaVarExprUnrecognizedVar {
#[primary_span] #[primary_span]
@ -31,7 +31,7 @@ pub(crate) struct MetaVarExprUnrecognizedVar {
pub key: MacroRulesNormalizedIdent, pub key: MacroRulesNormalizedIdent,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(expand::var_still_repeating)] #[diag(expand::var_still_repeating)]
pub(crate) struct VarStillRepeating { pub(crate) struct VarStillRepeating {
#[primary_span] #[primary_span]
@ -39,7 +39,7 @@ pub(crate) struct VarStillRepeating {
pub ident: MacroRulesNormalizedIdent, pub ident: MacroRulesNormalizedIdent,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(expand::meta_var_dif_seq_matchers)] #[diag(expand::meta_var_dif_seq_matchers)]
pub(crate) struct MetaVarsDifSeqMatchers { pub(crate) struct MetaVarsDifSeqMatchers {
#[primary_span] #[primary_span]

View file

@ -593,7 +593,7 @@ pub fn compile_declarative_macro(
(mk_syn_ext(expander), rule_spans) (mk_syn_ext(expander), rule_spans)
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
enum ExplainDocComment { enum ExplainDocComment {
#[label(expand::explain_doc_comment_inner)] #[label(expand::explain_doc_comment_inner)]
Inner { Inner {

View file

@ -1,10 +1,10 @@
use hir::GenericParamKind; use hir::GenericParamKind;
use rustc_errors::{ use rustc_errors::{
fluent, AddSubdiagnostic, Applicability, DiagnosticMessage, DiagnosticStyledString, MultiSpan, fluent, AddToDiagnostic, Applicability, DiagnosticMessage, DiagnosticStyledString, MultiSpan,
}; };
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::{FnRetTy, Ty}; use rustc_hir::{FnRetTy, Ty};
use rustc_macros::SessionDiagnostic; use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_middle::ty::{Region, TyCtxt}; use rustc_middle::ty::{Region, TyCtxt};
use rustc_span::symbol::kw; use rustc_span::symbol::kw;
use rustc_span::{symbol::Ident, BytePos, Span}; use rustc_span::{symbol::Ident, BytePos, Span};
@ -16,7 +16,7 @@ use crate::infer::error_reporting::{
pub mod note_and_explain; pub mod note_and_explain;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(infer::opaque_hidden_type)] #[diag(infer::opaque_hidden_type)]
pub struct OpaqueHiddenTypeDiag { pub struct OpaqueHiddenTypeDiag {
#[primary_span] #[primary_span]
@ -28,7 +28,7 @@ pub struct OpaqueHiddenTypeDiag {
pub hidden_type: Span, pub hidden_type: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(infer::type_annotations_needed, code = "E0282")] #[diag(infer::type_annotations_needed, code = "E0282")]
pub struct AnnotationRequired<'a> { pub struct AnnotationRequired<'a> {
#[primary_span] #[primary_span]
@ -46,7 +46,7 @@ pub struct AnnotationRequired<'a> {
} }
// Copy of `AnnotationRequired` for E0283 // Copy of `AnnotationRequired` for E0283
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(infer::type_annotations_needed, code = "E0283")] #[diag(infer::type_annotations_needed, code = "E0283")]
pub struct AmbigousImpl<'a> { pub struct AmbigousImpl<'a> {
#[primary_span] #[primary_span]
@ -64,7 +64,7 @@ pub struct AmbigousImpl<'a> {
} }
// Copy of `AnnotationRequired` for E0284 // Copy of `AnnotationRequired` for E0284
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(infer::type_annotations_needed, code = "E0284")] #[diag(infer::type_annotations_needed, code = "E0284")]
pub struct AmbigousReturn<'a> { pub struct AmbigousReturn<'a> {
#[primary_span] #[primary_span]
@ -81,7 +81,7 @@ pub struct AmbigousReturn<'a> {
pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>, pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(infer::need_type_info_in_generator, code = "E0698")] #[diag(infer::need_type_info_in_generator, code = "E0698")]
pub struct NeedTypeInfoInGenerator<'a> { pub struct NeedTypeInfoInGenerator<'a> {
#[primary_span] #[primary_span]
@ -92,7 +92,7 @@ pub struct NeedTypeInfoInGenerator<'a> {
} }
// Used when a better one isn't available // Used when a better one isn't available
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[label(infer::label_bad)] #[label(infer::label_bad)]
pub struct InferenceBadError<'a> { pub struct InferenceBadError<'a> {
#[primary_span] #[primary_span]
@ -106,7 +106,7 @@ pub struct InferenceBadError<'a> {
pub name: String, pub name: String,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub enum SourceKindSubdiag<'a> { pub enum SourceKindSubdiag<'a> {
#[suggestion_verbose( #[suggestion_verbose(
infer::source_kind_subdiag_let, infer::source_kind_subdiag_let,
@ -147,7 +147,7 @@ pub enum SourceKindSubdiag<'a> {
}, },
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub enum SourceKindMultiSuggestion<'a> { pub enum SourceKindMultiSuggestion<'a> {
#[multipart_suggestion_verbose( #[multipart_suggestion_verbose(
infer::source_kind_fully_qualified, infer::source_kind_fully_qualified,
@ -228,7 +228,7 @@ pub enum RegionOriginNote<'a> {
}, },
} }
impl AddSubdiagnostic for RegionOriginNote<'_> { impl AddToDiagnostic for RegionOriginNote<'_> {
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
let mut label_or_note = |span, msg: DiagnosticMessage| { let mut label_or_note = |span, msg: DiagnosticMessage| {
let sub_count = diag.children.iter().filter(|d| d.span.is_dummy()).count(); let sub_count = diag.children.iter().filter(|d| d.span.is_dummy()).count();
@ -289,7 +289,7 @@ pub enum LifetimeMismatchLabels {
}, },
} }
impl AddSubdiagnostic for LifetimeMismatchLabels { impl AddToDiagnostic for LifetimeMismatchLabels {
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
match self { match self {
LifetimeMismatchLabels::InRet { param_span, ret_span, span, label_var1 } => { LifetimeMismatchLabels::InRet { param_span, ret_span, span, label_var1 } => {
@ -339,7 +339,7 @@ pub struct AddLifetimeParamsSuggestion<'a> {
pub add_note: bool, pub add_note: bool,
} }
impl AddSubdiagnostic for AddLifetimeParamsSuggestion<'_> { impl AddToDiagnostic for AddLifetimeParamsSuggestion<'_> {
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
let mut mk_suggestion = || { let mut mk_suggestion = || {
let ( let (
@ -422,7 +422,7 @@ impl AddSubdiagnostic for AddLifetimeParamsSuggestion<'_> {
} }
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(infer::lifetime_mismatch, code = "E0623")] #[diag(infer::lifetime_mismatch, code = "E0623")]
pub struct LifetimeMismatch<'a> { pub struct LifetimeMismatch<'a> {
#[primary_span] #[primary_span]
@ -438,7 +438,7 @@ pub struct IntroducesStaticBecauseUnmetLifetimeReq {
pub binding_span: Span, pub binding_span: Span,
} }
impl AddSubdiagnostic for IntroducesStaticBecauseUnmetLifetimeReq { impl AddToDiagnostic for IntroducesStaticBecauseUnmetLifetimeReq {
fn add_to_diagnostic(mut self, diag: &mut rustc_errors::Diagnostic) { fn add_to_diagnostic(mut self, diag: &mut rustc_errors::Diagnostic) {
self.unmet_requirements self.unmet_requirements
.push_span_label(self.binding_span, fluent::infer::msl_introduces_static); .push_span_label(self.binding_span, fluent::infer::msl_introduces_static);
@ -450,7 +450,7 @@ pub struct ImplNote {
pub impl_span: Option<Span>, pub impl_span: Option<Span>,
} }
impl AddSubdiagnostic for ImplNote { impl AddToDiagnostic for ImplNote {
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
match self.impl_span { match self.impl_span {
Some(span) => diag.span_note(span, fluent::infer::msl_impl_note), Some(span) => diag.span_note(span, fluent::infer::msl_impl_note),
@ -465,7 +465,7 @@ pub enum TraitSubdiag {
} }
// FIXME(#100717) used in `Vec<TraitSubdiag>` so requires eager translation/list support // FIXME(#100717) used in `Vec<TraitSubdiag>` so requires eager translation/list support
impl AddSubdiagnostic for TraitSubdiag { impl AddToDiagnostic for TraitSubdiag {
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
match self { match self {
TraitSubdiag::Note { span } => { TraitSubdiag::Note { span } => {
@ -483,7 +483,7 @@ impl AddSubdiagnostic for TraitSubdiag {
} }
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(infer::mismatched_static_lifetime)] #[diag(infer::mismatched_static_lifetime)]
pub struct MismatchedStaticLifetime<'a> { pub struct MismatchedStaticLifetime<'a> {
#[primary_span] #[primary_span]

View file

@ -1,5 +1,5 @@
use crate::infer::error_reporting::nice_region_error::find_anon_type; use crate::infer::error_reporting::nice_region_error::find_anon_type;
use rustc_errors::{self, fluent, AddSubdiagnostic, IntoDiagnosticArg}; use rustc_errors::{self, fluent, AddToDiagnostic, IntoDiagnosticArg};
use rustc_middle::ty::{self, TyCtxt}; use rustc_middle::ty::{self, TyCtxt};
use rustc_span::{symbol::kw, Span}; use rustc_span::{symbol::kw, Span};
@ -158,7 +158,7 @@ impl RegionExplanation<'_> {
} }
} }
impl AddSubdiagnostic for RegionExplanation<'_> { impl AddToDiagnostic for RegionExplanation<'_> {
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
if let Some(span) = self.desc.span { if let Some(span) = self.desc.span {
diag.span_note(span, fluent::infer::region_explanation); diag.span_note(span, fluent::infer::region_explanation);

View file

@ -4,6 +4,7 @@ use crate::errors::{
}; };
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use crate::infer::InferCtxt; use crate::infer::InferCtxt;
use rustc_errors::IntoDiagnostic;
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed, IntoDiagnosticArg}; use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed, IntoDiagnosticArg};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::Res; use rustc_hir::def::Res;
@ -18,7 +19,6 @@ use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Print, Printer};
use rustc_middle::ty::{self, DefIdTree, InferConst}; use rustc_middle::ty::{self, DefIdTree, InferConst};
use rustc_middle::ty::{GenericArg, GenericArgKind, SubstsRef}; use rustc_middle::ty::{GenericArg, GenericArgKind, SubstsRef};
use rustc_middle::ty::{IsSuggestable, Ty, TyCtxt, TypeckResults}; use rustc_middle::ty::{IsSuggestable, Ty, TyCtxt, TypeckResults};
use rustc_session::SessionDiagnostic;
use rustc_span::symbol::{kw, Ident}; use rustc_span::symbol::{kw, Ident};
use rustc_span::{BytePos, Span}; use rustc_span::{BytePos, Span};
use std::borrow::Cow; use std::borrow::Cow;

View file

@ -11,7 +11,7 @@ use crate::infer::lexical_region_resolve::RegionResolutionError;
use crate::infer::SubregionOrigin; use crate::infer::SubregionOrigin;
use crate::infer::TyCtxt; use crate::infer::TyCtxt;
use rustc_errors::AddSubdiagnostic; use rustc_errors::AddToDiagnostic;
use rustc_errors::{Diagnostic, ErrorGuaranteed}; use rustc_errors::{Diagnostic, ErrorGuaranteed};
use rustc_hir::Ty; use rustc_hir::Ty;
use rustc_middle::ty::Region; use rustc_middle::ty::Region;

View file

@ -2,7 +2,7 @@ use crate::errors::RegionOriginNote;
use crate::infer::error_reporting::note_and_explain_region; use crate::infer::error_reporting::note_and_explain_region;
use crate::infer::{self, InferCtxt, SubregionOrigin}; use crate::infer::{self, InferCtxt, SubregionOrigin};
use rustc_errors::{ use rustc_errors::{
fluent, struct_span_err, AddSubdiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, fluent, struct_span_err, AddToDiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed,
}; };
use rustc_middle::traits::ObligationCauseCode; use rustc_middle::traits::ObligationCauseCode;
use rustc_middle::ty::error::TypeError; use rustc_middle::ty::error::TypeError;

View file

@ -1,10 +1,10 @@
use rustc_macros::SessionDiagnostic; use rustc_macros::Diagnostic;
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
use std::io; use std::io;
use std::path::Path; use std::path::Path;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(interface::ferris_identifier)] #[diag(interface::ferris_identifier)]
pub struct FerrisIdentifier { pub struct FerrisIdentifier {
#[primary_span] #[primary_span]
@ -13,7 +13,7 @@ pub struct FerrisIdentifier {
pub first_span: Span, pub first_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(interface::emoji_identifier)] #[diag(interface::emoji_identifier)]
pub struct EmojiIdentifier { pub struct EmojiIdentifier {
#[primary_span] #[primary_span]
@ -21,67 +21,67 @@ pub struct EmojiIdentifier {
pub ident: Symbol, pub ident: Symbol,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(interface::mixed_bin_crate)] #[diag(interface::mixed_bin_crate)]
pub struct MixedBinCrate; pub struct MixedBinCrate;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(interface::mixed_proc_macro_crate)] #[diag(interface::mixed_proc_macro_crate)]
pub struct MixedProcMacroCrate; pub struct MixedProcMacroCrate;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(interface::proc_macro_doc_without_arg)] #[diag(interface::proc_macro_doc_without_arg)]
pub struct ProcMacroDocWithoutArg; pub struct ProcMacroDocWithoutArg;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(interface::error_writing_dependencies)] #[diag(interface::error_writing_dependencies)]
pub struct ErrorWritingDependencies<'a> { pub struct ErrorWritingDependencies<'a> {
pub path: &'a Path, pub path: &'a Path,
pub error: io::Error, pub error: io::Error,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(interface::input_file_would_be_overwritten)] #[diag(interface::input_file_would_be_overwritten)]
pub struct InputFileWouldBeOverWritten<'a> { pub struct InputFileWouldBeOverWritten<'a> {
pub path: &'a Path, pub path: &'a Path,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(interface::generated_file_conflicts_with_directory)] #[diag(interface::generated_file_conflicts_with_directory)]
pub struct GeneratedFileConflictsWithDirectory<'a> { pub struct GeneratedFileConflictsWithDirectory<'a> {
pub input_path: &'a Path, pub input_path: &'a Path,
pub dir_path: &'a Path, pub dir_path: &'a Path,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(interface::temps_dir_error)] #[diag(interface::temps_dir_error)]
pub struct TempsDirError; pub struct TempsDirError;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(interface::out_dir_error)] #[diag(interface::out_dir_error)]
pub struct OutDirError; pub struct OutDirError;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(interface::cant_emit_mir)] #[diag(interface::cant_emit_mir)]
pub struct CantEmitMIR { pub struct CantEmitMIR {
pub error: io::Error, pub error: io::Error,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(interface::rustc_error_fatal)] #[diag(interface::rustc_error_fatal)]
pub struct RustcErrorFatal { pub struct RustcErrorFatal {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(interface::rustc_error_unexpected_annotation)] #[diag(interface::rustc_error_unexpected_annotation)]
pub struct RustcErrorUnexpectedAnnotation { pub struct RustcErrorUnexpectedAnnotation {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(interface::failed_writing_file)] #[diag(interface::failed_writing_file)]
pub struct FailedWritingFile<'a> { pub struct FailedWritingFile<'a> {
pub path: &'a Path, pub path: &'a Path,

View file

@ -1,9 +1,9 @@
use rustc_errors::{fluent, AddSubdiagnostic, ErrorGuaranteed, Handler}; use rustc_errors::{fluent, AddToDiagnostic, ErrorGuaranteed, Handler, IntoDiagnostic};
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic}; use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_session::{lint::Level, SessionDiagnostic}; use rustc_session::lint::Level;
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(lint::overruled_attribute, code = "E0453")] #[diag(lint::overruled_attribute, code = "E0453")]
pub struct OverruledAttribute { pub struct OverruledAttribute {
#[primary_span] #[primary_span]
@ -22,7 +22,7 @@ pub enum OverruledAttributeSub {
CommandLineSource, CommandLineSource,
} }
impl AddSubdiagnostic for OverruledAttributeSub { impl AddToDiagnostic for OverruledAttributeSub {
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
match self { match self {
OverruledAttributeSub::DefaultSource { id } => { OverruledAttributeSub::DefaultSource { id } => {
@ -42,7 +42,7 @@ impl AddSubdiagnostic for OverruledAttributeSub {
} }
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(lint::malformed_attribute, code = "E0452")] #[diag(lint::malformed_attribute, code = "E0452")]
pub struct MalformedAttribute { pub struct MalformedAttribute {
#[primary_span] #[primary_span]
@ -51,7 +51,7 @@ pub struct MalformedAttribute {
pub sub: MalformedAttributeSub, pub sub: MalformedAttributeSub,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub enum MalformedAttributeSub { pub enum MalformedAttributeSub {
#[label(lint::bad_attribute_argument)] #[label(lint::bad_attribute_argument)]
BadAttributeArgument(#[primary_span] Span), BadAttributeArgument(#[primary_span] Span),
@ -61,7 +61,7 @@ pub enum MalformedAttributeSub {
ReasonMustComeLast(#[primary_span] Span), ReasonMustComeLast(#[primary_span] Span),
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(lint::unknown_tool_in_scoped_lint, code = "E0710")] #[diag(lint::unknown_tool_in_scoped_lint, code = "E0710")]
pub struct UnknownToolInScopedLint { pub struct UnknownToolInScopedLint {
#[primary_span] #[primary_span]
@ -72,7 +72,7 @@ pub struct UnknownToolInScopedLint {
pub is_nightly_build: Option<()>, pub is_nightly_build: Option<()>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(lint::builtin_ellipsis_inclusive_range_patterns, code = "E0783")] #[diag(lint::builtin_ellipsis_inclusive_range_patterns, code = "E0783")]
pub struct BuiltinEllpisisInclusiveRangePatterns { pub struct BuiltinEllpisisInclusiveRangePatterns {
#[primary_span] #[primary_span]
@ -87,7 +87,7 @@ pub struct RequestedLevel {
pub lint_name: String, pub lint_name: String,
} }
impl AddSubdiagnostic for RequestedLevel { impl AddToDiagnostic for RequestedLevel {
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
diag.note(fluent::lint::requested_level); diag.note(fluent::lint::requested_level);
diag.set_arg( diag.set_arg(
@ -107,7 +107,7 @@ impl AddSubdiagnostic for RequestedLevel {
} }
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(lint::unsupported_group, code = "E0602")] #[diag(lint::unsupported_group, code = "E0602")]
pub struct UnsupportedGroup { pub struct UnsupportedGroup {
pub lint_group: String, pub lint_group: String,
@ -119,7 +119,7 @@ pub struct CheckNameUnknown {
pub sub: RequestedLevel, pub sub: RequestedLevel,
} }
impl SessionDiagnostic<'_> for CheckNameUnknown { impl IntoDiagnostic<'_> for CheckNameUnknown {
fn into_diagnostic( fn into_diagnostic(
self, self,
handler: &Handler, handler: &Handler,
@ -136,7 +136,7 @@ impl SessionDiagnostic<'_> for CheckNameUnknown {
} }
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(lint::check_name_unknown_tool, code = "E0602")] #[diag(lint::check_name_unknown_tool, code = "E0602")]
pub struct CheckNameUnknownTool { pub struct CheckNameUnknownTool {
pub tool_name: Symbol, pub tool_name: Symbol,
@ -144,7 +144,7 @@ pub struct CheckNameUnknownTool {
pub sub: RequestedLevel, pub sub: RequestedLevel,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(lint::check_name_warning)] #[diag(lint::check_name_warning)]
pub struct CheckNameWarning { pub struct CheckNameWarning {
pub msg: String, pub msg: String,
@ -152,7 +152,7 @@ pub struct CheckNameWarning {
pub sub: RequestedLevel, pub sub: RequestedLevel,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(lint::check_name_deprecated)] #[diag(lint::check_name_deprecated)]
pub struct CheckNameDeprecated { pub struct CheckNameDeprecated {
pub lint_name: String, pub lint_name: String,

View file

@ -372,7 +372,7 @@ declare_tool_lint! {
declare_tool_lint! { declare_tool_lint! {
pub rustc::DIAGNOSTIC_OUTSIDE_OF_IMPL, pub rustc::DIAGNOSTIC_OUTSIDE_OF_IMPL,
Allow, Allow,
"prevent creation of diagnostics outside of `SessionDiagnostic`/`AddSubdiagnostic` impls", "prevent creation of diagnostics outside of `IntoDiagnostic`/`AddToDiagnostic` impls",
report_in_external_macro: true report_in_external_macro: true
} }
@ -404,7 +404,7 @@ impl LateLintPass<'_> for Diagnostics {
let Impl { of_trait: Some(of_trait), .. } = impl_ && let Impl { of_trait: Some(of_trait), .. } = impl_ &&
let Some(def_id) = of_trait.trait_def_id() && let Some(def_id) = of_trait.trait_def_id() &&
let Some(name) = cx.tcx.get_diagnostic_name(def_id) && let Some(name) = cx.tcx.get_diagnostic_name(def_id) &&
matches!(name, sym::SessionDiagnostic | sym::AddSubdiagnostic | sym::DecorateLint) matches!(name, sym::IntoDiagnostic | sym::AddToDiagnostic | sym::DecorateLint)
{ {
found_impl = true; found_impl = true;
break; break;

View file

@ -9,29 +9,29 @@ use syn::spanned::Spanned;
use synstructure::Structure; use synstructure::Structure;
/// The central struct for constructing the `into_diagnostic` method from an annotated struct. /// The central struct for constructing the `into_diagnostic` method from an annotated struct.
pub(crate) struct SessionDiagnosticDerive<'a> { pub(crate) struct DiagnosticDerive<'a> {
structure: Structure<'a>, structure: Structure<'a>,
sess: syn::Ident, handler: syn::Ident,
builder: DiagnosticDeriveBuilder, builder: DiagnosticDeriveBuilder,
} }
impl<'a> SessionDiagnosticDerive<'a> { impl<'a> DiagnosticDerive<'a> {
pub(crate) fn new(diag: syn::Ident, sess: syn::Ident, structure: Structure<'a>) -> Self { pub(crate) fn new(diag: syn::Ident, handler: syn::Ident, structure: Structure<'a>) -> Self {
Self { Self {
builder: DiagnosticDeriveBuilder { builder: DiagnosticDeriveBuilder {
diag, diag,
fields: build_field_mapping(&structure), fields: build_field_mapping(&structure),
kind: DiagnosticDeriveKind::SessionDiagnostic, kind: DiagnosticDeriveKind::Diagnostic,
code: None, code: None,
slug: None, slug: None,
}, },
sess, handler,
structure, structure,
} }
} }
pub(crate) fn into_tokens(self) -> TokenStream { pub(crate) fn into_tokens(self) -> TokenStream {
let SessionDiagnosticDerive { mut structure, sess, mut builder } = self; let DiagnosticDerive { mut structure, handler, mut builder } = self;
let ast = structure.ast(); let ast = structure.ast();
let implementation = { let implementation = {
@ -53,7 +53,7 @@ impl<'a> SessionDiagnosticDerive<'a> {
} }
Some(slug) => { Some(slug) => {
quote! { quote! {
let mut #diag = #sess.struct_diagnostic(rustc_errors::fluent::#slug); let mut #diag = #handler.struct_diagnostic(rustc_errors::fluent::#slug);
} }
} }
}; };
@ -72,7 +72,7 @@ impl<'a> SessionDiagnosticDerive<'a> {
} else { } else {
span_err( span_err(
ast.span().unwrap(), ast.span().unwrap(),
"`#[derive(SessionDiagnostic)]` can only be used on structs", "`#[derive(Diagnostic)]` can only be used on structs",
) )
.emit(); .emit();
@ -81,15 +81,15 @@ impl<'a> SessionDiagnosticDerive<'a> {
}; };
structure.gen_impl(quote! { structure.gen_impl(quote! {
gen impl<'__session_diagnostic_sess, G> gen impl<'__diagnostic_handler_sess, G>
rustc_session::SessionDiagnostic<'__session_diagnostic_sess, G> rustc_errors::IntoDiagnostic<'__diagnostic_handler_sess, G>
for @Self for @Self
where G: rustc_errors::EmissionGuarantee where G: rustc_errors::EmissionGuarantee
{ {
fn into_diagnostic( fn into_diagnostic(
self, self,
#sess: &'__session_diagnostic_sess rustc_errors::Handler #handler: &'__diagnostic_handler_sess rustc_errors::Handler
) -> rustc_errors::DiagnosticBuilder<'__session_diagnostic_sess, G> { ) -> rustc_errors::DiagnosticBuilder<'__diagnostic_handler_sess, G> {
use rustc_errors::IntoDiagnosticArg; use rustc_errors::IntoDiagnosticArg;
#implementation #implementation
} }

View file

@ -21,12 +21,12 @@ use synstructure::{BindingInfo, Structure};
/// What kind of diagnostic is being derived - a fatal/error/warning or a lint? /// What kind of diagnostic is being derived - a fatal/error/warning or a lint?
#[derive(Copy, Clone, PartialEq, Eq)] #[derive(Copy, Clone, PartialEq, Eq)]
pub(crate) enum DiagnosticDeriveKind { pub(crate) enum DiagnosticDeriveKind {
SessionDiagnostic, Diagnostic,
LintDiagnostic, LintDiagnostic,
} }
/// Tracks persistent information required for building up individual calls to diagnostic methods /// Tracks persistent information required for building up individual calls to diagnostic methods
/// for generated diagnostic derives - both `SessionDiagnostic` for fatal/errors/warnings and /// for generated diagnostic derives - both `Diagnostic` for fatal/errors/warnings and
/// `LintDiagnostic` for lints. /// `LintDiagnostic` for lints.
pub(crate) struct DiagnosticDeriveBuilder { pub(crate) struct DiagnosticDeriveBuilder {
/// The identifier to use for the generated `DiagnosticBuilder` instance. /// The identifier to use for the generated `DiagnosticBuilder` instance.
@ -333,7 +333,7 @@ impl DiagnosticDeriveBuilder {
} }
"primary_span" => { "primary_span" => {
match self.kind { match self.kind {
DiagnosticDeriveKind::SessionDiagnostic => { DiagnosticDeriveKind::Diagnostic => {
report_error_if_not_applied_to_span(attr, &info)?; report_error_if_not_applied_to_span(attr, &info)?;
Ok(quote! { Ok(quote! {

View file

@ -5,14 +5,14 @@ mod fluent;
mod subdiagnostic; mod subdiagnostic;
mod utils; mod utils;
use diagnostic::{LintDiagnosticDerive, SessionDiagnosticDerive}; use diagnostic::{DiagnosticDerive, LintDiagnosticDerive};
pub(crate) use fluent::fluent_messages; pub(crate) use fluent::fluent_messages;
use proc_macro2::TokenStream; use proc_macro2::TokenStream;
use quote::format_ident; use quote::format_ident;
use subdiagnostic::SessionSubdiagnosticDerive; use subdiagnostic::SubdiagnosticDerive;
use synstructure::Structure; use synstructure::Structure;
/// Implements `#[derive(SessionDiagnostic)]`, which allows for errors to be specified as a struct, /// Implements `#[derive(Diagnostic)]`, which allows for errors to be specified as a struct,
/// independent from the actual diagnostics emitting code. /// independent from the actual diagnostics emitting code.
/// ///
/// ```ignore (rust) /// ```ignore (rust)
@ -22,7 +22,7 @@ use synstructure::Structure;
/// # use rustc_span::{symbol::Ident, Span}; /// # use rustc_span::{symbol::Ident, Span};
/// # extern crate rust_middle; /// # extern crate rust_middle;
/// # use rustc_middle::ty::Ty; /// # use rustc_middle::ty::Ty;
/// #[derive(SessionDiagnostic)] /// #[derive(Diagnostic)]
/// #[diag(borrowck::move_out_of_borrow, code = "E0505")] /// #[diag(borrowck::move_out_of_borrow, code = "E0505")]
/// pub struct MoveOutOfBorrowError<'tcx> { /// pub struct MoveOutOfBorrowError<'tcx> {
/// pub name: Ident, /// pub name: Ident,
@ -56,10 +56,10 @@ use synstructure::Structure;
/// }); /// });
/// ``` /// ```
/// ///
/// See rustc dev guide for more examples on using the `#[derive(SessionDiagnostic)]`: /// See rustc dev guide for more examples on using the `#[derive(Diagnostic)]`:
/// <https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html> /// <https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html>
pub fn session_diagnostic_derive(s: Structure<'_>) -> TokenStream { pub fn session_diagnostic_derive(s: Structure<'_>) -> TokenStream {
SessionDiagnosticDerive::new(format_ident!("diag"), format_ident!("sess"), s).into_tokens() DiagnosticDerive::new(format_ident!("diag"), format_ident!("handler"), s).into_tokens()
} }
/// Implements `#[derive(LintDiagnostic)]`, which allows for lints to be specified as a struct, /// Implements `#[derive(LintDiagnostic)]`, which allows for lints to be specified as a struct,
@ -103,17 +103,17 @@ pub fn session_diagnostic_derive(s: Structure<'_>) -> TokenStream {
/// ``` /// ```
/// ///
/// See rustc dev guide for more examples on using the `#[derive(LintDiagnostic)]`: /// See rustc dev guide for more examples on using the `#[derive(LintDiagnostic)]`:
/// <https://rustc-dev-guide.rust-lang.org/diagnostics/sessiondiagnostic.html> /// <https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html#reference>
pub fn lint_diagnostic_derive(s: Structure<'_>) -> TokenStream { pub fn lint_diagnostic_derive(s: Structure<'_>) -> TokenStream {
LintDiagnosticDerive::new(format_ident!("diag"), s).into_tokens() LintDiagnosticDerive::new(format_ident!("diag"), s).into_tokens()
} }
/// Implements `#[derive(SessionSubdiagnostic)]`, which allows for labels, notes, helps and /// Implements `#[derive(Subdiagnostic)]`, which allows for labels, notes, helps and
/// suggestions to be specified as a structs or enums, independent from the actual diagnostics /// suggestions to be specified as a structs or enums, independent from the actual diagnostics
/// emitting code or diagnostic derives. /// emitting code or diagnostic derives.
/// ///
/// ```ignore (rust) /// ```ignore (rust)
/// #[derive(SessionSubdiagnostic)] /// #[derive(Subdiagnostic)]
/// pub enum ExpectedIdentifierLabel<'tcx> { /// pub enum ExpectedIdentifierLabel<'tcx> {
/// #[label(parser::expected_identifier)] /// #[label(parser::expected_identifier)]
/// WithoutFound { /// WithoutFound {
@ -128,7 +128,7 @@ pub fn lint_diagnostic_derive(s: Structure<'_>) -> TokenStream {
/// } /// }
/// } /// }
/// ///
/// #[derive(SessionSubdiagnostic)] /// #[derive(Subdiagnostic)]
/// #[suggestion_verbose(parser::raw_identifier)] /// #[suggestion_verbose(parser::raw_identifier)]
/// pub struct RawIdentifierSuggestion<'tcx> { /// pub struct RawIdentifierSuggestion<'tcx> {
/// #[primary_span] /// #[primary_span]
@ -155,5 +155,5 @@ pub fn lint_diagnostic_derive(s: Structure<'_>) -> TokenStream {
/// diag.subdiagnostic(RawIdentifierSuggestion { span, applicability, ident }); /// diag.subdiagnostic(RawIdentifierSuggestion { span, applicability, ident });
/// ``` /// ```
pub fn session_subdiagnostic_derive(s: Structure<'_>) -> TokenStream { pub fn session_subdiagnostic_derive(s: Structure<'_>) -> TokenStream {
SessionSubdiagnosticDerive::new(s).into_tokens() SubdiagnosticDerive::new(s).into_tokens()
} }

View file

@ -98,19 +98,19 @@ impl quote::IdentFragment for SubdiagnosticKind {
} }
/// The central struct for constructing the `add_to_diagnostic` method from an annotated struct. /// The central struct for constructing the `add_to_diagnostic` method from an annotated struct.
pub(crate) struct SessionSubdiagnosticDerive<'a> { pub(crate) struct SubdiagnosticDerive<'a> {
structure: Structure<'a>, structure: Structure<'a>,
diag: syn::Ident, diag: syn::Ident,
} }
impl<'a> SessionSubdiagnosticDerive<'a> { impl<'a> SubdiagnosticDerive<'a> {
pub(crate) fn new(structure: Structure<'a>) -> Self { pub(crate) fn new(structure: Structure<'a>) -> Self {
let diag = format_ident!("diag"); let diag = format_ident!("diag");
Self { structure, diag } Self { structure, diag }
} }
pub(crate) fn into_tokens(self) -> TokenStream { pub(crate) fn into_tokens(self) -> TokenStream {
let SessionSubdiagnosticDerive { mut structure, diag } = self; let SubdiagnosticDerive { mut structure, diag } = self;
let implementation = { let implementation = {
let ast = structure.ast(); let ast = structure.ast();
let span = ast.span().unwrap(); let span = ast.span().unwrap();
@ -119,7 +119,7 @@ impl<'a> SessionSubdiagnosticDerive<'a> {
syn::Data::Union(..) => { syn::Data::Union(..) => {
span_err( span_err(
span, span,
"`#[derive(SessionSubdiagnostic)]` can only be used on structs and enums", "`#[derive(Subdiagnostic)]` can only be used on structs and enums",
); );
} }
} }
@ -146,7 +146,7 @@ impl<'a> SessionSubdiagnosticDerive<'a> {
} }
} }
let mut builder = SessionSubdiagnosticDeriveBuilder { let mut builder = SubdiagnosticDeriveBuilder {
diag: &diag, diag: &diag,
variant, variant,
span, span,
@ -166,7 +166,7 @@ impl<'a> SessionSubdiagnosticDerive<'a> {
}; };
let ret = structure.gen_impl(quote! { let ret = structure.gen_impl(quote! {
gen impl rustc_errors::AddSubdiagnostic for @Self { gen impl rustc_errors::AddToDiagnostic for @Self {
fn add_to_diagnostic(self, #diag: &mut rustc_errors::Diagnostic) { fn add_to_diagnostic(self, #diag: &mut rustc_errors::Diagnostic) {
use rustc_errors::{Applicability, IntoDiagnosticArg}; use rustc_errors::{Applicability, IntoDiagnosticArg};
#implementation #implementation
@ -178,10 +178,10 @@ impl<'a> SessionSubdiagnosticDerive<'a> {
} }
/// Tracks persistent information required for building up the call to add to the diagnostic /// Tracks persistent information required for building up the call to add to the diagnostic
/// for the final generated method. This is a separate struct to `SessionSubdiagnosticDerive` /// for the final generated method. This is a separate struct to `SubdiagnosticDerive`
/// only to be able to destructure and split `self.builder` and the `self.structure` up to avoid a /// only to be able to destructure and split `self.builder` and the `self.structure` up to avoid a
/// double mut borrow later on. /// double mut borrow later on.
struct SessionSubdiagnosticDeriveBuilder<'a> { struct SubdiagnosticDeriveBuilder<'a> {
/// The identifier to use for the generated `DiagnosticBuilder` instance. /// The identifier to use for the generated `DiagnosticBuilder` instance.
diag: &'a syn::Ident, diag: &'a syn::Ident,
@ -205,7 +205,7 @@ struct SessionSubdiagnosticDeriveBuilder<'a> {
has_suggestion_parts: bool, has_suggestion_parts: bool,
} }
impl<'a> HasFieldMap for SessionSubdiagnosticDeriveBuilder<'a> { impl<'a> HasFieldMap for SubdiagnosticDeriveBuilder<'a> {
fn get_field_binding(&self, field: &String) -> Option<&TokenStream> { fn get_field_binding(&self, field: &String) -> Option<&TokenStream> {
self.fields.get(field) self.fields.get(field)
} }
@ -241,7 +241,7 @@ impl<'a> FromIterator<&'a SubdiagnosticKind> for KindsStatistics {
} }
} }
impl<'a> SessionSubdiagnosticDeriveBuilder<'a> { impl<'a> SubdiagnosticDeriveBuilder<'a> {
fn identify_kind(&mut self) -> Result<Vec<(SubdiagnosticKind, Path)>, DiagnosticDeriveError> { fn identify_kind(&mut self) -> Result<Vec<(SubdiagnosticKind, Path)>, DiagnosticDeriveError> {
let mut kind_slugs = vec![]; let mut kind_slugs = vec![];

View file

@ -127,7 +127,7 @@ decl_derive!([TypeFoldable, attributes(type_foldable)] => type_foldable::type_fo
decl_derive!([TypeVisitable, attributes(type_visitable)] => type_visitable::type_visitable_derive); decl_derive!([TypeVisitable, attributes(type_visitable)] => type_visitable::type_visitable_derive);
decl_derive!([Lift, attributes(lift)] => lift::lift_derive); decl_derive!([Lift, attributes(lift)] => lift::lift_derive);
decl_derive!( decl_derive!(
[SessionDiagnostic, attributes( [Diagnostic, attributes(
// struct attributes // struct attributes
diag, diag,
help, help,
@ -161,7 +161,7 @@ decl_derive!(
suggestion_verbose)] => diagnostics::lint_diagnostic_derive suggestion_verbose)] => diagnostics::lint_diagnostic_derive
); );
decl_derive!( decl_derive!(
[SessionSubdiagnostic, attributes( [Subdiagnostic, attributes(
// struct/variant attributes // struct/variant attributes
label, label,
help, help,

View file

@ -3,49 +3,49 @@ use std::{
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
use rustc_errors::{error_code, ErrorGuaranteed}; use rustc_errors::{error_code, ErrorGuaranteed, IntoDiagnostic};
use rustc_macros::SessionDiagnostic; use rustc_macros::Diagnostic;
use rustc_session::{config, SessionDiagnostic}; use rustc_session::config;
use rustc_span::{sym, Span, Symbol}; use rustc_span::{sym, Span, Symbol};
use rustc_target::spec::{PanicStrategy, TargetTriple}; use rustc_target::spec::{PanicStrategy, TargetTriple};
use crate::locator::CrateFlavor; use crate::locator::CrateFlavor;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::rlib_required)] #[diag(metadata::rlib_required)]
pub struct RlibRequired { pub struct RlibRequired {
pub crate_name: Symbol, pub crate_name: Symbol,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::lib_required)] #[diag(metadata::lib_required)]
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(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::crate_dep_multiple)] #[diag(metadata::crate_dep_multiple)]
#[help] #[help]
pub struct CrateDepMultiple { pub struct CrateDepMultiple {
pub crate_name: Symbol, pub crate_name: Symbol,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::two_panic_runtimes)] #[diag(metadata::two_panic_runtimes)]
pub struct TwoPanicRuntimes { pub struct TwoPanicRuntimes {
pub prev_name: Symbol, pub prev_name: Symbol,
pub cur_name: Symbol, pub cur_name: Symbol,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::bad_panic_strategy)] #[diag(metadata::bad_panic_strategy)]
pub struct BadPanicStrategy { pub struct BadPanicStrategy {
pub runtime: Symbol, pub runtime: Symbol,
pub strategy: PanicStrategy, pub strategy: PanicStrategy,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::required_panic_strategy)] #[diag(metadata::required_panic_strategy)]
pub struct RequiredPanicStrategy { pub struct RequiredPanicStrategy {
pub crate_name: Symbol, pub crate_name: Symbol,
@ -53,7 +53,7 @@ pub struct RequiredPanicStrategy {
pub desired_strategy: PanicStrategy, pub desired_strategy: PanicStrategy,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::incompatible_panic_in_drop_strategy)] #[diag(metadata::incompatible_panic_in_drop_strategy)]
pub struct IncompatiblePanicInDropStrategy { pub struct IncompatiblePanicInDropStrategy {
pub crate_name: Symbol, pub crate_name: Symbol,
@ -61,56 +61,56 @@ pub struct IncompatiblePanicInDropStrategy {
pub desired_strategy: PanicStrategy, pub desired_strategy: PanicStrategy,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::multiple_names_in_link)] #[diag(metadata::multiple_names_in_link)]
pub struct MultipleNamesInLink { pub struct MultipleNamesInLink {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::multiple_kinds_in_link)] #[diag(metadata::multiple_kinds_in_link)]
pub struct MultipleKindsInLink { pub struct MultipleKindsInLink {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::link_name_form)] #[diag(metadata::link_name_form)]
pub struct LinkNameForm { pub struct LinkNameForm {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::link_kind_form)] #[diag(metadata::link_kind_form)]
pub struct LinkKindForm { pub struct LinkKindForm {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::link_modifiers_form)] #[diag(metadata::link_modifiers_form)]
pub struct LinkModifiersForm { pub struct LinkModifiersForm {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::link_cfg_form)] #[diag(metadata::link_cfg_form)]
pub struct LinkCfgForm { pub struct LinkCfgForm {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::wasm_import_form)] #[diag(metadata::wasm_import_form)]
pub struct WasmImportForm { pub struct WasmImportForm {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::empty_link_name, code = "E0454")] #[diag(metadata::empty_link_name, code = "E0454")]
pub struct EmptyLinkName { pub struct EmptyLinkName {
#[primary_span] #[primary_span]
@ -118,21 +118,21 @@ pub struct EmptyLinkName {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::link_framework_apple, code = "E0455")] #[diag(metadata::link_framework_apple, code = "E0455")]
pub struct LinkFrameworkApple { pub struct LinkFrameworkApple {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::framework_only_windows, code = "E0455")] #[diag(metadata::framework_only_windows, code = "E0455")]
pub struct FrameworkOnlyWindows { pub struct FrameworkOnlyWindows {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::unknown_link_kind, code = "E0458")] #[diag(metadata::unknown_link_kind, code = "E0458")]
pub struct UnknownLinkKind<'a> { pub struct UnknownLinkKind<'a> {
#[primary_span] #[primary_span]
@ -141,49 +141,49 @@ pub struct UnknownLinkKind<'a> {
pub kind: &'a str, pub kind: &'a str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::multiple_link_modifiers)] #[diag(metadata::multiple_link_modifiers)]
pub struct MultipleLinkModifiers { pub struct MultipleLinkModifiers {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::multiple_cfgs)] #[diag(metadata::multiple_cfgs)]
pub struct MultipleCfgs { pub struct MultipleCfgs {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::link_cfg_single_predicate)] #[diag(metadata::link_cfg_single_predicate)]
pub struct LinkCfgSinglePredicate { pub struct LinkCfgSinglePredicate {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::multiple_wasm_import)] #[diag(metadata::multiple_wasm_import)]
pub struct MultipleWasmImport { pub struct MultipleWasmImport {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::unexpected_link_arg)] #[diag(metadata::unexpected_link_arg)]
pub struct UnexpectedLinkArg { pub struct UnexpectedLinkArg {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::invalid_link_modifier)] #[diag(metadata::invalid_link_modifier)]
pub struct InvalidLinkModifier { pub struct InvalidLinkModifier {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::multiple_modifiers)] #[diag(metadata::multiple_modifiers)]
pub struct MultipleModifiers<'a> { pub struct MultipleModifiers<'a> {
#[primary_span] #[primary_span]
@ -191,28 +191,28 @@ pub struct MultipleModifiers<'a> {
pub modifier: &'a str, pub modifier: &'a str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::bundle_needs_static)] #[diag(metadata::bundle_needs_static)]
pub struct BundleNeedsStatic { pub struct BundleNeedsStatic {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::whole_archive_needs_static)] #[diag(metadata::whole_archive_needs_static)]
pub struct WholeArchiveNeedsStatic { pub struct WholeArchiveNeedsStatic {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::as_needed_compatibility)] #[diag(metadata::as_needed_compatibility)]
pub struct AsNeededCompatibility { pub struct AsNeededCompatibility {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::unknown_link_modifier)] #[diag(metadata::unknown_link_modifier)]
pub struct UnknownLinkModifier<'a> { pub struct UnknownLinkModifier<'a> {
#[primary_span] #[primary_span]
@ -220,14 +220,14 @@ pub struct UnknownLinkModifier<'a> {
pub modifier: &'a str, pub modifier: &'a str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::incompatible_wasm_link)] #[diag(metadata::incompatible_wasm_link)]
pub struct IncompatibleWasmLink { pub struct IncompatibleWasmLink {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::link_requires_name, code = "E0459")] #[diag(metadata::link_requires_name, code = "E0459")]
pub struct LinkRequiresName { pub struct LinkRequiresName {
#[primary_span] #[primary_span]
@ -235,105 +235,105 @@ pub struct LinkRequiresName {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::raw_dylib_no_nul)] #[diag(metadata::raw_dylib_no_nul)]
pub struct RawDylibNoNul { pub struct RawDylibNoNul {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::link_ordinal_raw_dylib)] #[diag(metadata::link_ordinal_raw_dylib)]
pub struct LinkOrdinalRawDylib { pub struct LinkOrdinalRawDylib {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::lib_framework_apple)] #[diag(metadata::lib_framework_apple)]
pub struct LibFrameworkApple; pub struct LibFrameworkApple;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::empty_renaming_target)] #[diag(metadata::empty_renaming_target)]
pub struct EmptyRenamingTarget<'a> { pub struct EmptyRenamingTarget<'a> {
pub lib_name: &'a str, pub lib_name: &'a str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::renaming_no_link)] #[diag(metadata::renaming_no_link)]
pub struct RenamingNoLink<'a> { pub struct RenamingNoLink<'a> {
pub lib_name: &'a str, pub lib_name: &'a str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::multiple_renamings)] #[diag(metadata::multiple_renamings)]
pub struct MultipleRenamings<'a> { pub struct MultipleRenamings<'a> {
pub lib_name: &'a str, pub lib_name: &'a str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::no_link_mod_override)] #[diag(metadata::no_link_mod_override)]
pub struct NoLinkModOverride { pub struct NoLinkModOverride {
#[primary_span] #[primary_span]
pub span: Option<Span>, pub span: Option<Span>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::unsupported_abi_i686)] #[diag(metadata::unsupported_abi_i686)]
pub struct UnsupportedAbiI686 { pub struct UnsupportedAbiI686 {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::unsupported_abi)] #[diag(metadata::unsupported_abi)]
pub struct UnsupportedAbi { pub struct UnsupportedAbi {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::fail_create_file_encoder)] #[diag(metadata::fail_create_file_encoder)]
pub struct FailCreateFileEncoder { pub struct FailCreateFileEncoder {
pub err: Error, pub err: Error,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::fail_seek_file)] #[diag(metadata::fail_seek_file)]
pub struct FailSeekFile { pub struct FailSeekFile {
pub err: Error, pub err: Error,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::fail_write_file)] #[diag(metadata::fail_write_file)]
pub struct FailWriteFile { pub struct FailWriteFile {
pub err: Error, pub err: Error,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::crate_not_panic_runtime)] #[diag(metadata::crate_not_panic_runtime)]
pub struct CrateNotPanicRuntime { pub struct CrateNotPanicRuntime {
pub crate_name: Symbol, pub crate_name: Symbol,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::no_panic_strategy)] #[diag(metadata::no_panic_strategy)]
pub struct NoPanicStrategy { pub struct NoPanicStrategy {
pub crate_name: Symbol, pub crate_name: Symbol,
pub strategy: PanicStrategy, pub strategy: PanicStrategy,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::profiler_builtins_needs_core)] #[diag(metadata::profiler_builtins_needs_core)]
pub struct ProfilerBuiltinsNeedsCore; pub struct ProfilerBuiltinsNeedsCore;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::not_profiler_runtime)] #[diag(metadata::not_profiler_runtime)]
pub struct NotProfilerRuntime { pub struct NotProfilerRuntime {
pub crate_name: Symbol, pub crate_name: Symbol,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::no_multiple_global_alloc)] #[diag(metadata::no_multiple_global_alloc)]
pub struct NoMultipleGlobalAlloc { pub struct NoMultipleGlobalAlloc {
#[primary_span] #[primary_span]
@ -343,18 +343,18 @@ pub struct NoMultipleGlobalAlloc {
pub span1: Span, pub span1: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::conflicting_global_alloc)] #[diag(metadata::conflicting_global_alloc)]
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(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::global_alloc_required)] #[diag(metadata::global_alloc_required)]
pub struct GlobalAllocRequired; pub struct GlobalAllocRequired;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::no_transitive_needs_dep)] #[diag(metadata::no_transitive_needs_dep)]
pub struct NoTransitiveNeedsDep<'a> { pub struct NoTransitiveNeedsDep<'a> {
pub crate_name: Symbol, pub crate_name: Symbol,
@ -362,39 +362,39 @@ pub struct NoTransitiveNeedsDep<'a> {
pub deps_crate_name: Symbol, pub deps_crate_name: Symbol,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::failed_write_error)] #[diag(metadata::failed_write_error)]
pub struct FailedWriteError { pub struct FailedWriteError {
pub filename: PathBuf, pub filename: PathBuf,
pub err: Error, pub err: Error,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::missing_native_library)] #[diag(metadata::missing_native_library)]
pub struct MissingNativeLibrary<'a> { pub struct MissingNativeLibrary<'a> {
pub libname: &'a str, pub libname: &'a str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::failed_create_tempdir)] #[diag(metadata::failed_create_tempdir)]
pub struct FailedCreateTempdir { pub struct FailedCreateTempdir {
pub err: Error, pub err: Error,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::failed_create_file)] #[diag(metadata::failed_create_file)]
pub struct FailedCreateFile<'a> { pub struct FailedCreateFile<'a> {
pub filename: &'a Path, pub filename: &'a Path,
pub err: Error, pub err: Error,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::failed_create_encoded_metadata)] #[diag(metadata::failed_create_encoded_metadata)]
pub struct FailedCreateEncodedMetadata { pub struct FailedCreateEncodedMetadata {
pub err: Error, pub err: Error,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::non_ascii_name)] #[diag(metadata::non_ascii_name)]
pub struct NonAsciiName { pub struct NonAsciiName {
#[primary_span] #[primary_span]
@ -402,7 +402,7 @@ pub struct NonAsciiName {
pub crate_name: Symbol, pub crate_name: Symbol,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::extern_location_not_exist)] #[diag(metadata::extern_location_not_exist)]
pub struct ExternLocationNotExist<'a> { pub struct ExternLocationNotExist<'a> {
#[primary_span] #[primary_span]
@ -411,7 +411,7 @@ pub struct ExternLocationNotExist<'a> {
pub location: &'a Path, pub location: &'a Path,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::extern_location_not_file)] #[diag(metadata::extern_location_not_file)]
pub struct ExternLocationNotFile<'a> { pub struct ExternLocationNotFile<'a> {
#[primary_span] #[primary_span]
@ -427,7 +427,7 @@ pub(crate) struct MultipleCandidates {
pub candidates: Vec<PathBuf>, pub candidates: Vec<PathBuf>,
} }
impl SessionDiagnostic<'_> for MultipleCandidates { impl IntoDiagnostic<'_> for MultipleCandidates {
fn into_diagnostic( fn into_diagnostic(
self, self,
handler: &'_ rustc_errors::Handler, handler: &'_ rustc_errors::Handler,
@ -444,7 +444,7 @@ impl SessionDiagnostic<'_> for MultipleCandidates {
} }
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::multiple_matching_crates, code = "E0464")] #[diag(metadata::multiple_matching_crates, code = "E0464")]
#[note] #[note]
pub struct MultipleMatchingCrates { pub struct MultipleMatchingCrates {
@ -454,7 +454,7 @@ pub struct MultipleMatchingCrates {
pub candidates: String, pub candidates: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::symbol_conflicts_current, code = "E0519")] #[diag(metadata::symbol_conflicts_current, code = "E0519")]
pub struct SymbolConflictsCurrent { pub struct SymbolConflictsCurrent {
#[primary_span] #[primary_span]
@ -462,7 +462,7 @@ pub struct SymbolConflictsCurrent {
pub crate_name: Symbol, pub crate_name: Symbol,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::symbol_conflicts_others, code = "E0523")] #[diag(metadata::symbol_conflicts_others, code = "E0523")]
pub struct SymbolConflictsOthers { pub struct SymbolConflictsOthers {
#[primary_span] #[primary_span]
@ -470,7 +470,7 @@ pub struct SymbolConflictsOthers {
pub crate_name: Symbol, pub crate_name: Symbol,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::stable_crate_id_collision)] #[diag(metadata::stable_crate_id_collision)]
pub struct StableCrateIdCollision { pub struct StableCrateIdCollision {
#[primary_span] #[primary_span]
@ -479,7 +479,7 @@ pub struct StableCrateIdCollision {
pub crate_name1: Symbol, pub crate_name1: Symbol,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::dl_error)] #[diag(metadata::dl_error)]
pub struct DlError { pub struct DlError {
#[primary_span] #[primary_span]
@ -487,7 +487,7 @@ pub struct DlError {
pub err: String, pub err: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::newer_crate_version, code = "E0460")] #[diag(metadata::newer_crate_version, code = "E0460")]
#[note] #[note]
#[note(metadata::found_crate_versions)] #[note(metadata::found_crate_versions)]
@ -499,7 +499,7 @@ pub struct NewerCrateVersion {
pub found_crates: String, pub found_crates: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::no_crate_with_triple, code = "E0461")] #[diag(metadata::no_crate_with_triple, code = "E0461")]
#[note(metadata::found_crate_versions)] #[note(metadata::found_crate_versions)]
pub struct NoCrateWithTriple<'a> { pub struct NoCrateWithTriple<'a> {
@ -511,7 +511,7 @@ pub struct NoCrateWithTriple<'a> {
pub found_crates: String, pub found_crates: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::found_staticlib, code = "E0462")] #[diag(metadata::found_staticlib, code = "E0462")]
#[note(metadata::found_crate_versions)] #[note(metadata::found_crate_versions)]
#[help] #[help]
@ -523,7 +523,7 @@ pub struct FoundStaticlib {
pub found_crates: String, pub found_crates: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::incompatible_rustc, code = "E0514")] #[diag(metadata::incompatible_rustc, code = "E0514")]
#[note(metadata::found_crate_versions)] #[note(metadata::found_crate_versions)]
#[help] #[help]
@ -543,7 +543,7 @@ pub struct InvalidMetadataFiles {
pub crate_rejections: Vec<String>, pub crate_rejections: Vec<String>,
} }
impl SessionDiagnostic<'_> for InvalidMetadataFiles { impl IntoDiagnostic<'_> for InvalidMetadataFiles {
fn into_diagnostic( fn into_diagnostic(
self, self,
handler: &'_ rustc_errors::Handler, handler: &'_ rustc_errors::Handler,
@ -571,7 +571,7 @@ pub struct CannotFindCrate {
pub locator_triple: TargetTriple, pub locator_triple: TargetTriple,
} }
impl SessionDiagnostic<'_> for CannotFindCrate { impl IntoDiagnostic<'_> for CannotFindCrate {
fn into_diagnostic( fn into_diagnostic(
self, self,
handler: &'_ rustc_errors::Handler, handler: &'_ rustc_errors::Handler,
@ -617,7 +617,7 @@ impl SessionDiagnostic<'_> for CannotFindCrate {
} }
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::no_dylib_plugin, code = "E0457")] #[diag(metadata::no_dylib_plugin, code = "E0457")]
pub struct NoDylibPlugin { pub struct NoDylibPlugin {
#[primary_span] #[primary_span]
@ -625,7 +625,7 @@ pub struct NoDylibPlugin {
pub crate_name: Symbol, pub crate_name: Symbol,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::crate_location_unknown_type)] #[diag(metadata::crate_location_unknown_type)]
pub struct CrateLocationUnknownType<'a> { pub struct CrateLocationUnknownType<'a> {
#[primary_span] #[primary_span]
@ -633,7 +633,7 @@ pub struct CrateLocationUnknownType<'a> {
pub path: &'a Path, pub path: &'a Path,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::lib_filename_form)] #[diag(metadata::lib_filename_form)]
pub struct LibFilenameForm<'a> { pub struct LibFilenameForm<'a> {
#[primary_span] #[primary_span]
@ -642,28 +642,28 @@ pub struct LibFilenameForm<'a> {
pub dll_suffix: &'a str, pub dll_suffix: &'a str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::multiple_import_name_type)] #[diag(metadata::multiple_import_name_type)]
pub struct MultipleImportNameType { pub struct MultipleImportNameType {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::import_name_type_form)] #[diag(metadata::import_name_type_form)]
pub struct ImportNameTypeForm { pub struct ImportNameTypeForm {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::import_name_type_x86)] #[diag(metadata::import_name_type_x86)]
pub struct ImportNameTypeX86 { pub struct ImportNameTypeX86 {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::unknown_import_name_type)] #[diag(metadata::unknown_import_name_type)]
pub struct UnknownImportNameType<'a> { pub struct UnknownImportNameType<'a> {
#[primary_span] #[primary_span]
@ -671,7 +671,7 @@ pub struct UnknownImportNameType<'a> {
pub import_name_type: &'a str, pub import_name_type: &'a str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(metadata::import_name_type_raw)] #[diag(metadata::import_name_type_raw)]
pub struct ImportNameTypeRaw { pub struct ImportNameTypeRaw {
#[primary_span] #[primary_span]

View file

@ -1,9 +1,9 @@
use rustc_macros::SessionDiagnostic; use rustc_macros::Diagnostic;
use rustc_span::Span; use rustc_span::Span;
use crate::ty::Ty; use crate::ty::Ty;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(middle::drop_check_overflow, code = "E0320")] #[diag(middle::drop_check_overflow, code = "E0320")]
#[note] #[note]
pub struct DropCheckOverflow<'tcx> { pub struct DropCheckOverflow<'tcx> {
@ -13,7 +13,7 @@ pub struct DropCheckOverflow<'tcx> {
pub overflow_ty: Ty<'tcx>, pub overflow_ty: Ty<'tcx>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(middle::opaque_hidden_type_mismatch)] #[diag(middle::opaque_hidden_type_mismatch)]
pub struct OpaqueHiddenTypeMismatch<'tcx> { pub struct OpaqueHiddenTypeMismatch<'tcx> {
pub self_ty: Ty<'tcx>, pub self_ty: Ty<'tcx>,
@ -25,7 +25,7 @@ pub struct OpaqueHiddenTypeMismatch<'tcx> {
pub sub: TypeMismatchReason, pub sub: TypeMismatchReason,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub enum TypeMismatchReason { pub enum TypeMismatchReason {
#[label(middle::conflict_types)] #[label(middle::conflict_types)]
ConflictType { ConflictType {
@ -39,7 +39,7 @@ pub enum TypeMismatchReason {
}, },
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(middle::limit_invalid)] #[diag(middle::limit_invalid)]
pub struct LimitInvalid<'a> { pub struct LimitInvalid<'a> {
#[primary_span] #[primary_span]

View file

@ -53,6 +53,7 @@ use rustc_query_system::ich::StableHashingContext;
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder}; use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
use rustc_session::config::{CrateType, OutputFilenames}; use rustc_session::config::{CrateType, OutputFilenames};
use rustc_session::cstore::CrateStoreDyn; use rustc_session::cstore::CrateStoreDyn;
use rustc_session::errors::TargetDataLayoutErrorsWrapper;
use rustc_session::lint::Lint; use rustc_session::lint::Lint;
use rustc_session::Limit; use rustc_session::Limit;
use rustc_session::Session; use rustc_session::Session;
@ -1245,7 +1246,7 @@ impl<'tcx> TyCtxt<'tcx> {
output_filenames: OutputFilenames, output_filenames: OutputFilenames,
) -> GlobalCtxt<'tcx> { ) -> GlobalCtxt<'tcx> {
let data_layout = TargetDataLayout::parse(&s.target).unwrap_or_else(|err| { let data_layout = TargetDataLayout::parse(&s.target).unwrap_or_else(|err| {
s.emit_fatal(err); s.emit_fatal(TargetDataLayoutErrorsWrapper(err));
}); });
let interners = CtxtInterners::new(arena); let interners = CtxtInterners::new(arena);
let common_types = CommonTypes::new( let common_types = CommonTypes::new(

View file

@ -1,21 +1,21 @@
use rustc_macros::SessionDiagnostic; use rustc_macros::Diagnostic;
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(mir_dataflow::path_must_end_in_filename)] #[diag(mir_dataflow::path_must_end_in_filename)]
pub(crate) struct PathMustEndInFilename { pub(crate) struct PathMustEndInFilename {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(mir_dataflow::unknown_formatter)] #[diag(mir_dataflow::unknown_formatter)]
pub(crate) struct UnknownFormatter { pub(crate) struct UnknownFormatter {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(mir_dataflow::duplicate_values_for)] #[diag(mir_dataflow::duplicate_values_for)]
pub(crate) struct DuplicateValuesFor { pub(crate) struct DuplicateValuesFor {
#[primary_span] #[primary_span]
@ -23,7 +23,7 @@ pub(crate) struct DuplicateValuesFor {
pub name: Symbol, pub name: Symbol,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(mir_dataflow::requires_an_argument)] #[diag(mir_dataflow::requires_an_argument)]
pub(crate) struct RequiresAnArgument { pub(crate) struct RequiresAnArgument {
#[primary_span] #[primary_span]
@ -31,39 +31,39 @@ pub(crate) struct RequiresAnArgument {
pub name: Symbol, pub name: Symbol,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(mir_dataflow::stop_after_dataflow_ended_compilation)] #[diag(mir_dataflow::stop_after_dataflow_ended_compilation)]
pub(crate) struct StopAfterDataFlowEndedCompilation; pub(crate) struct StopAfterDataFlowEndedCompilation;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(mir_dataflow::peek_must_be_place_or_ref_place)] #[diag(mir_dataflow::peek_must_be_place_or_ref_place)]
pub(crate) struct PeekMustBePlaceOrRefPlace { pub(crate) struct PeekMustBePlaceOrRefPlace {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(mir_dataflow::peek_must_be_not_temporary)] #[diag(mir_dataflow::peek_must_be_not_temporary)]
pub(crate) struct PeekMustBeNotTemporary { pub(crate) struct PeekMustBeNotTemporary {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(mir_dataflow::peek_bit_not_set)] #[diag(mir_dataflow::peek_bit_not_set)]
pub(crate) struct PeekBitNotSet { pub(crate) struct PeekBitNotSet {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(mir_dataflow::peek_argument_not_a_local)] #[diag(mir_dataflow::peek_argument_not_a_local)]
pub(crate) struct PeekArgumentNotALocal { pub(crate) struct PeekArgumentNotALocal {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(mir_dataflow::peek_argument_untracked)] #[diag(mir_dataflow::peek_argument_untracked)]
pub(crate) struct PeekArgumentUntracked { pub(crate) struct PeekArgumentUntracked {
#[primary_span] #[primary_span]

View file

@ -1,11 +1,11 @@
use std::path::PathBuf; use std::path::PathBuf;
use rustc_errors::ErrorGuaranteed; use rustc_errors::ErrorGuaranteed;
use rustc_macros::{LintDiagnostic, SessionDiagnostic}; use rustc_errors::IntoDiagnostic;
use rustc_session::SessionDiagnostic; use rustc_macros::{Diagnostic, LintDiagnostic};
use rustc_span::Span; use rustc_span::Span;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(monomorphize::recursion_limit)] #[diag(monomorphize::recursion_limit)]
pub struct RecursionLimit { pub struct RecursionLimit {
#[primary_span] #[primary_span]
@ -19,7 +19,7 @@ pub struct RecursionLimit {
pub path: PathBuf, pub path: PathBuf,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(monomorphize::type_length_limit)] #[diag(monomorphize::type_length_limit)]
#[help(monomorphize::consider_type_length_limit)] #[help(monomorphize::consider_type_length_limit)]
pub struct TypeLengthLimit { pub struct TypeLengthLimit {
@ -32,7 +32,7 @@ pub struct TypeLengthLimit {
pub type_length: usize, pub type_length: usize,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(monomorphize::requires_lang_item)] #[diag(monomorphize::requires_lang_item)]
pub struct RequiresLangItem { pub struct RequiresLangItem {
pub lang_item: String, pub lang_item: String,
@ -44,7 +44,7 @@ pub struct UnusedGenericParams {
pub param_names: Vec<String>, pub param_names: Vec<String>,
} }
impl SessionDiagnostic<'_> for UnusedGenericParams { impl IntoDiagnostic<'_> for UnusedGenericParams {
fn into_diagnostic( fn into_diagnostic(
self, self,
handler: &'_ rustc_errors::Handler, handler: &'_ rustc_errors::Handler,
@ -72,11 +72,11 @@ pub struct LargeAssignmentsLint {
pub limit: u64, pub limit: u64,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(monomorphize::unknown_partition_strategy)] #[diag(monomorphize::unknown_partition_strategy)]
pub struct UnknownPartitionStrategy; pub struct UnknownPartitionStrategy;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(monomorphize::symbol_already_defined)] #[diag(monomorphize::symbol_already_defined)]
pub struct SymbolAlreadyDefined { pub struct SymbolAlreadyDefined {
#[primary_span] #[primary_span]

View file

@ -20,7 +20,7 @@ use rustc_errors::{
fluent, Applicability, DiagnosticBuilder, DiagnosticMessage, Handler, MultiSpan, PResult, fluent, Applicability, DiagnosticBuilder, DiagnosticMessage, Handler, MultiSpan, PResult,
}; };
use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed}; use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed};
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic}; use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::source_map::Spanned; use rustc_span::source_map::Spanned;
use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::symbol::{kw, sym, Ident};
use rustc_span::{Span, SpanSnippetError, DUMMY_SP}; use rustc_span::{Span, SpanSnippetError, DUMMY_SP};
@ -242,7 +242,7 @@ impl MultiSugg {
} }
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::maybe_report_ambiguous_plus)] #[diag(parser::maybe_report_ambiguous_plus)]
struct AmbiguousPlus { struct AmbiguousPlus {
pub sum_ty: String, pub sum_ty: String,
@ -251,7 +251,7 @@ struct AmbiguousPlus {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::maybe_recover_from_bad_type_plus, code = "E0178")] #[diag(parser::maybe_recover_from_bad_type_plus, code = "E0178")]
struct BadTypePlus { struct BadTypePlus {
pub ty: String, pub ty: String,
@ -261,7 +261,7 @@ struct BadTypePlus {
pub sub: BadTypePlusSub, pub sub: BadTypePlusSub,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub enum BadTypePlusSub { pub enum BadTypePlusSub {
#[suggestion( #[suggestion(
parser::add_paren, parser::add_paren,
@ -285,7 +285,7 @@ pub enum BadTypePlusSub {
}, },
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::maybe_recover_from_bad_qpath_stage_2)] #[diag(parser::maybe_recover_from_bad_qpath_stage_2)]
struct BadQPathStage2 { struct BadQPathStage2 {
#[primary_span] #[primary_span]
@ -294,7 +294,7 @@ struct BadQPathStage2 {
ty: String, ty: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::incorrect_semicolon)] #[diag(parser::incorrect_semicolon)]
struct IncorrectSemicolon<'a> { struct IncorrectSemicolon<'a> {
#[primary_span] #[primary_span]
@ -305,7 +305,7 @@ struct IncorrectSemicolon<'a> {
name: &'a str, name: &'a str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::incorrect_use_of_await)] #[diag(parser::incorrect_use_of_await)]
struct IncorrectUseOfAwait { struct IncorrectUseOfAwait {
#[primary_span] #[primary_span]
@ -313,7 +313,7 @@ struct IncorrectUseOfAwait {
span: Span, span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::incorrect_use_of_await)] #[diag(parser::incorrect_use_of_await)]
struct IncorrectAwait { struct IncorrectAwait {
#[primary_span] #[primary_span]
@ -324,7 +324,7 @@ struct IncorrectAwait {
question_mark: &'static str, question_mark: &'static str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::in_in_typo)] #[diag(parser::in_in_typo)]
struct InInTypo { struct InInTypo {
#[primary_span] #[primary_span]
@ -333,7 +333,7 @@ struct InInTypo {
sugg_span: Span, sugg_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::invalid_variable_declaration)] #[diag(parser::invalid_variable_declaration)]
pub struct InvalidVariableDeclaration { pub struct InvalidVariableDeclaration {
#[primary_span] #[primary_span]
@ -342,7 +342,7 @@ pub struct InvalidVariableDeclaration {
pub sub: InvalidVariableDeclarationSub, pub sub: InvalidVariableDeclarationSub,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub enum InvalidVariableDeclarationSub { pub enum InvalidVariableDeclarationSub {
#[suggestion( #[suggestion(
parser::switch_mut_let_order, parser::switch_mut_let_order,
@ -362,7 +362,7 @@ pub enum InvalidVariableDeclarationSub {
UseLetNotVar(#[primary_span] Span), UseLetNotVar(#[primary_span] Span),
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::invalid_comparison_operator)] #[diag(parser::invalid_comparison_operator)]
pub(crate) struct InvalidComparisonOperator { pub(crate) struct InvalidComparisonOperator {
#[primary_span] #[primary_span]
@ -372,7 +372,7 @@ pub(crate) struct InvalidComparisonOperator {
pub sub: InvalidComparisonOperatorSub, pub sub: InvalidComparisonOperatorSub,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub(crate) enum InvalidComparisonOperatorSub { pub(crate) enum InvalidComparisonOperatorSub {
#[suggestion_short( #[suggestion_short(
parser::use_instead, parser::use_instead,
@ -389,7 +389,7 @@ pub(crate) enum InvalidComparisonOperatorSub {
Spaceship(#[primary_span] Span), Spaceship(#[primary_span] Span),
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::invalid_logical_operator)] #[diag(parser::invalid_logical_operator)]
#[note] #[note]
pub(crate) struct InvalidLogicalOperator { pub(crate) struct InvalidLogicalOperator {
@ -400,7 +400,7 @@ pub(crate) struct InvalidLogicalOperator {
pub sub: InvalidLogicalOperatorSub, pub sub: InvalidLogicalOperatorSub,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub(crate) enum InvalidLogicalOperatorSub { pub(crate) enum InvalidLogicalOperatorSub {
#[suggestion_short( #[suggestion_short(
parser::use_amp_amp_for_conjunction, parser::use_amp_amp_for_conjunction,
@ -416,7 +416,7 @@ pub(crate) enum InvalidLogicalOperatorSub {
Disjunction(#[primary_span] Span), Disjunction(#[primary_span] Span),
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::tilde_is_not_unary_operator)] #[diag(parser::tilde_is_not_unary_operator)]
pub(crate) struct TildeAsUnaryOperator( pub(crate) struct TildeAsUnaryOperator(
#[primary_span] #[primary_span]
@ -424,7 +424,7 @@ pub(crate) struct TildeAsUnaryOperator(
pub Span, pub Span,
); );
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::unexpected_token_after_not)] #[diag(parser::unexpected_token_after_not)]
pub(crate) struct NotAsNegationOperator { pub(crate) struct NotAsNegationOperator {
#[primary_span] #[primary_span]
@ -434,7 +434,7 @@ pub(crate) struct NotAsNegationOperator {
pub sub: NotAsNegationOperatorSub, pub sub: NotAsNegationOperatorSub,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub enum NotAsNegationOperatorSub { pub enum NotAsNegationOperatorSub {
#[suggestion_short( #[suggestion_short(
parser::unexpected_token_after_not_default, parser::unexpected_token_after_not_default,
@ -458,7 +458,7 @@ pub enum NotAsNegationOperatorSub {
SuggestNotLogical(#[primary_span] Span), SuggestNotLogical(#[primary_span] Span),
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::malformed_loop_label)] #[diag(parser::malformed_loop_label)]
pub(crate) struct MalformedLoopLabel { pub(crate) struct MalformedLoopLabel {
#[primary_span] #[primary_span]
@ -467,7 +467,7 @@ pub(crate) struct MalformedLoopLabel {
pub correct_label: Ident, pub correct_label: Ident,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::lifetime_in_borrow_expression)] #[diag(parser::lifetime_in_borrow_expression)]
pub(crate) struct LifetimeInBorrowExpression { pub(crate) struct LifetimeInBorrowExpression {
#[primary_span] #[primary_span]
@ -477,15 +477,15 @@ pub(crate) struct LifetimeInBorrowExpression {
pub lifetime_span: Span, pub lifetime_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::field_expression_with_generic)] #[diag(parser::field_expression_with_generic)]
pub(crate) struct FieldExpressionWithGeneric(#[primary_span] pub Span); pub(crate) struct FieldExpressionWithGeneric(#[primary_span] pub Span);
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::macro_invocation_with_qualified_path)] #[diag(parser::macro_invocation_with_qualified_path)]
pub(crate) struct MacroInvocationWithQualifiedPath(#[primary_span] pub Span); pub(crate) struct MacroInvocationWithQualifiedPath(#[primary_span] pub Span);
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::unexpected_token_after_label)] #[diag(parser::unexpected_token_after_label)]
pub(crate) struct UnexpectedTokenAfterLabel( pub(crate) struct UnexpectedTokenAfterLabel(
#[primary_span] #[primary_span]
@ -493,7 +493,7 @@ pub(crate) struct UnexpectedTokenAfterLabel(
pub Span, pub Span,
); );
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::require_colon_after_labeled_expression)] #[diag(parser::require_colon_after_labeled_expression)]
#[note] #[note]
pub(crate) struct RequireColonAfterLabeledExpression { pub(crate) struct RequireColonAfterLabeledExpression {
@ -505,7 +505,7 @@ pub(crate) struct RequireColonAfterLabeledExpression {
pub label_end: Span, pub label_end: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::do_catch_syntax_removed)] #[diag(parser::do_catch_syntax_removed)]
#[note] #[note]
pub(crate) struct DoCatchSyntaxRemoved { pub(crate) struct DoCatchSyntaxRemoved {
@ -514,7 +514,7 @@ pub(crate) struct DoCatchSyntaxRemoved {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::float_literal_requires_integer_part)] #[diag(parser::float_literal_requires_integer_part)]
pub(crate) struct FloatLiteralRequiresIntegerPart { pub(crate) struct FloatLiteralRequiresIntegerPart {
#[primary_span] #[primary_span]
@ -523,7 +523,7 @@ pub(crate) struct FloatLiteralRequiresIntegerPart {
pub correct: String, pub correct: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::invalid_int_literal_width)] #[diag(parser::invalid_int_literal_width)]
#[help] #[help]
pub(crate) struct InvalidIntLiteralWidth { pub(crate) struct InvalidIntLiteralWidth {
@ -532,7 +532,7 @@ pub(crate) struct InvalidIntLiteralWidth {
pub width: String, pub width: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::invalid_num_literal_base_prefix)] #[diag(parser::invalid_num_literal_base_prefix)]
#[note] #[note]
pub(crate) struct InvalidNumLiteralBasePrefix { pub(crate) struct InvalidNumLiteralBasePrefix {
@ -542,7 +542,7 @@ pub(crate) struct InvalidNumLiteralBasePrefix {
pub fixed: String, pub fixed: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::invalid_num_literal_suffix)] #[diag(parser::invalid_num_literal_suffix)]
#[help] #[help]
pub(crate) struct InvalidNumLiteralSuffix { pub(crate) struct InvalidNumLiteralSuffix {
@ -552,7 +552,7 @@ pub(crate) struct InvalidNumLiteralSuffix {
pub suffix: String, pub suffix: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::invalid_float_literal_width)] #[diag(parser::invalid_float_literal_width)]
#[help] #[help]
pub(crate) struct InvalidFloatLiteralWidth { pub(crate) struct InvalidFloatLiteralWidth {
@ -561,7 +561,7 @@ pub(crate) struct InvalidFloatLiteralWidth {
pub width: String, pub width: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::invalid_float_literal_suffix)] #[diag(parser::invalid_float_literal_suffix)]
#[help] #[help]
pub(crate) struct InvalidFloatLiteralSuffix { pub(crate) struct InvalidFloatLiteralSuffix {
@ -571,14 +571,14 @@ pub(crate) struct InvalidFloatLiteralSuffix {
pub suffix: String, pub suffix: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::int_literal_too_large)] #[diag(parser::int_literal_too_large)]
pub(crate) struct IntLiteralTooLarge { pub(crate) struct IntLiteralTooLarge {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::missing_semicolon_before_array)] #[diag(parser::missing_semicolon_before_array)]
pub(crate) struct MissingSemicolonBeforeArray { pub(crate) struct MissingSemicolonBeforeArray {
#[primary_span] #[primary_span]
@ -587,7 +587,7 @@ pub(crate) struct MissingSemicolonBeforeArray {
pub semicolon: Span, pub semicolon: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::invalid_block_macro_segment)] #[diag(parser::invalid_block_macro_segment)]
pub(crate) struct InvalidBlockMacroSegment { pub(crate) struct InvalidBlockMacroSegment {
#[primary_span] #[primary_span]
@ -596,7 +596,7 @@ pub(crate) struct InvalidBlockMacroSegment {
pub context: Span, pub context: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::if_expression_missing_then_block)] #[diag(parser::if_expression_missing_then_block)]
pub(crate) struct IfExpressionMissingThenBlock { pub(crate) struct IfExpressionMissingThenBlock {
#[primary_span] #[primary_span]
@ -605,7 +605,7 @@ pub(crate) struct IfExpressionMissingThenBlock {
pub sub: IfExpressionMissingThenBlockSub, pub sub: IfExpressionMissingThenBlockSub,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub(crate) enum IfExpressionMissingThenBlockSub { pub(crate) enum IfExpressionMissingThenBlockSub {
#[help(parser::condition_possibly_unfinished)] #[help(parser::condition_possibly_unfinished)]
UnfinishedCondition(#[primary_span] Span), UnfinishedCondition(#[primary_span] Span),
@ -613,7 +613,7 @@ pub(crate) enum IfExpressionMissingThenBlockSub {
AddThenBlock(#[primary_span] Span), AddThenBlock(#[primary_span] Span),
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::if_expression_missing_condition)] #[diag(parser::if_expression_missing_condition)]
pub(crate) struct IfExpressionMissingCondition { pub(crate) struct IfExpressionMissingCondition {
#[primary_span] #[primary_span]
@ -623,14 +623,14 @@ pub(crate) struct IfExpressionMissingCondition {
pub block_span: Span, pub block_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::expected_expression_found_let)] #[diag(parser::expected_expression_found_let)]
pub(crate) struct ExpectedExpressionFoundLet { pub(crate) struct ExpectedExpressionFoundLet {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::expected_else_block)] #[diag(parser::expected_else_block)]
pub(crate) struct ExpectedElseBlock { pub(crate) struct ExpectedElseBlock {
#[primary_span] #[primary_span]
@ -642,7 +642,7 @@ pub(crate) struct ExpectedElseBlock {
pub condition_start: Span, pub condition_start: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::outer_attribute_not_allowed_on_if_else)] #[diag(parser::outer_attribute_not_allowed_on_if_else)]
pub(crate) struct OuterAttributeNotAllowedOnIfElse { pub(crate) struct OuterAttributeNotAllowedOnIfElse {
#[primary_span] #[primary_span]
@ -659,7 +659,7 @@ pub(crate) struct OuterAttributeNotAllowedOnIfElse {
pub attributes: Span, pub attributes: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::missing_in_in_for_loop)] #[diag(parser::missing_in_in_for_loop)]
pub(crate) struct MissingInInForLoop { pub(crate) struct MissingInInForLoop {
#[primary_span] #[primary_span]
@ -668,7 +668,7 @@ pub(crate) struct MissingInInForLoop {
pub sub: MissingInInForLoopSub, pub sub: MissingInInForLoopSub,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub(crate) enum MissingInInForLoopSub { pub(crate) enum MissingInInForLoopSub {
// Has been misleading, at least in the past (closed Issue #48492), thus maybe-incorrect // Has been misleading, at least in the past (closed Issue #48492), thus maybe-incorrect
#[suggestion_short(parser::use_in_not_of, applicability = "maybe-incorrect", code = "in")] #[suggestion_short(parser::use_in_not_of, applicability = "maybe-incorrect", code = "in")]
@ -677,7 +677,7 @@ pub(crate) enum MissingInInForLoopSub {
AddIn(#[primary_span] Span), AddIn(#[primary_span] Span),
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::missing_comma_after_match_arm)] #[diag(parser::missing_comma_after_match_arm)]
pub(crate) struct MissingCommaAfterMatchArm { pub(crate) struct MissingCommaAfterMatchArm {
#[primary_span] #[primary_span]
@ -685,7 +685,7 @@ pub(crate) struct MissingCommaAfterMatchArm {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::catch_after_try)] #[diag(parser::catch_after_try)]
#[help] #[help]
pub(crate) struct CatchAfterTry { pub(crate) struct CatchAfterTry {
@ -693,7 +693,7 @@ pub(crate) struct CatchAfterTry {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::comma_after_base_struct)] #[diag(parser::comma_after_base_struct)]
#[note] #[note]
pub(crate) struct CommaAfterBaseStruct { pub(crate) struct CommaAfterBaseStruct {
@ -703,7 +703,7 @@ pub(crate) struct CommaAfterBaseStruct {
pub comma: Span, pub comma: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::eq_field_init)] #[diag(parser::eq_field_init)]
pub(crate) struct EqFieldInit { pub(crate) struct EqFieldInit {
#[primary_span] #[primary_span]
@ -712,7 +712,7 @@ pub(crate) struct EqFieldInit {
pub eq: Span, pub eq: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::dotdotdot)] #[diag(parser::dotdotdot)]
pub(crate) struct DotDotDot { pub(crate) struct DotDotDot {
#[primary_span] #[primary_span]
@ -721,7 +721,7 @@ pub(crate) struct DotDotDot {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::left_arrow_operator)] #[diag(parser::left_arrow_operator)]
pub(crate) struct LeftArrowOperator { pub(crate) struct LeftArrowOperator {
#[primary_span] #[primary_span]
@ -729,7 +729,7 @@ pub(crate) struct LeftArrowOperator {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::remove_let)] #[diag(parser::remove_let)]
pub(crate) struct RemoveLet { pub(crate) struct RemoveLet {
#[primary_span] #[primary_span]
@ -737,7 +737,7 @@ pub(crate) struct RemoveLet {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::use_eq_instead)] #[diag(parser::use_eq_instead)]
pub(crate) struct UseEqInstead { pub(crate) struct UseEqInstead {
#[primary_span] #[primary_span]

View file

@ -36,10 +36,10 @@ use rustc_ast::{AnonConst, BinOp, BinOpKind, FnDecl, FnRetTy, MacCall, Param, Ty
use rustc_ast::{Arm, Async, BlockCheckMode, Expr, ExprKind, Label, Movability, RangeLimits}; use rustc_ast::{Arm, Async, BlockCheckMode, Expr, ExprKind, Label, Movability, RangeLimits};
use rustc_ast::{ClosureBinder, StmtKind}; use rustc_ast::{ClosureBinder, StmtKind};
use rustc_ast_pretty::pprust; use rustc_ast_pretty::pprust;
use rustc_errors::IntoDiagnostic;
use rustc_errors::{Applicability, Diagnostic, PResult}; use rustc_errors::{Applicability, Diagnostic, PResult};
use rustc_session::lint::builtin::BREAK_WITH_LABEL_AND_LOOP; use rustc_session::lint::builtin::BREAK_WITH_LABEL_AND_LOOP;
use rustc_session::lint::BuiltinLintDiagnostics; use rustc_session::lint::BuiltinLintDiagnostics;
use rustc_session::SessionDiagnostic;
use rustc_span::source_map::{self, Span, Spanned}; use rustc_span::source_map::{self, Span, Spanned};
use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{BytePos, Pos}; use rustc_span::{BytePos, Pos};

View file

@ -1,5 +1,5 @@
use rustc_errors::{Applicability, MultiSpan}; use rustc_errors::{Applicability, MultiSpan};
use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic}; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
@ -32,7 +32,7 @@ pub struct IgnoredInlineAttrFnProto;
#[note] #[note]
pub struct IgnoredInlineAttrConstants; pub struct IgnoredInlineAttrConstants;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::inline_not_fn_or_closure, code = "E0518")] #[diag(passes::inline_not_fn_or_closure, code = "E0518")]
pub struct InlineNotFnOrClosure { pub struct InlineNotFnOrClosure {
#[primary_span] #[primary_span]
@ -53,7 +53,7 @@ pub struct IgnoredNoCoveragePropagate;
#[diag(passes::no_coverage_fn_defn)] #[diag(passes::no_coverage_fn_defn)]
pub struct IgnoredNoCoverageFnDefn; pub struct IgnoredNoCoverageFnDefn;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::no_coverage_not_coverable, code = "E0788")] #[diag(passes::no_coverage_not_coverable, code = "E0788")]
pub struct IgnoredNoCoverageNotCoverable { pub struct IgnoredNoCoverageNotCoverable {
#[primary_span] #[primary_span]
@ -62,7 +62,7 @@ pub struct IgnoredNoCoverageNotCoverable {
pub defn_span: Span, pub defn_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::should_be_applied_to_fn)] #[diag(passes::should_be_applied_to_fn)]
pub struct AttrShouldBeAppliedToFn { pub struct AttrShouldBeAppliedToFn {
#[primary_span] #[primary_span]
@ -71,14 +71,14 @@ pub struct AttrShouldBeAppliedToFn {
pub defn_span: Span, pub defn_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::naked_tracked_caller, code = "E0736")] #[diag(passes::naked_tracked_caller, code = "E0736")]
pub struct NakedTrackedCaller { pub struct NakedTrackedCaller {
#[primary_span] #[primary_span]
pub attr_span: Span, pub attr_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::should_be_applied_to_fn, code = "E0739")] #[diag(passes::should_be_applied_to_fn, code = "E0739")]
pub struct TrackedCallerWrongLocation { pub struct TrackedCallerWrongLocation {
#[primary_span] #[primary_span]
@ -87,7 +87,7 @@ pub struct TrackedCallerWrongLocation {
pub defn_span: Span, pub defn_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::should_be_applied_to_struct_enum, code = "E0701")] #[diag(passes::should_be_applied_to_struct_enum, code = "E0701")]
pub struct NonExhaustiveWrongLocation { pub struct NonExhaustiveWrongLocation {
#[primary_span] #[primary_span]
@ -96,7 +96,7 @@ pub struct NonExhaustiveWrongLocation {
pub defn_span: Span, pub defn_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::should_be_applied_to_trait)] #[diag(passes::should_be_applied_to_trait)]
pub struct AttrShouldBeAppliedToTrait { pub struct AttrShouldBeAppliedToTrait {
#[primary_span] #[primary_span]
@ -109,7 +109,7 @@ pub struct AttrShouldBeAppliedToTrait {
#[diag(passes::target_feature_on_statement)] #[diag(passes::target_feature_on_statement)]
pub struct TargetFeatureOnStatement; pub struct TargetFeatureOnStatement;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::should_be_applied_to_static)] #[diag(passes::should_be_applied_to_static)]
pub struct AttrShouldBeAppliedToStatic { pub struct AttrShouldBeAppliedToStatic {
#[primary_span] #[primary_span]
@ -118,7 +118,7 @@ pub struct AttrShouldBeAppliedToStatic {
pub defn_span: Span, pub defn_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::doc_expect_str)] #[diag(passes::doc_expect_str)]
pub struct DocExpectStr<'a> { pub struct DocExpectStr<'a> {
#[primary_span] #[primary_span]
@ -126,7 +126,7 @@ pub struct DocExpectStr<'a> {
pub attr_name: &'a str, pub attr_name: &'a str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::doc_alias_empty)] #[diag(passes::doc_alias_empty)]
pub struct DocAliasEmpty<'a> { pub struct DocAliasEmpty<'a> {
#[primary_span] #[primary_span]
@ -134,7 +134,7 @@ pub struct DocAliasEmpty<'a> {
pub attr_str: &'a str, pub attr_str: &'a str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::doc_alias_bad_char)] #[diag(passes::doc_alias_bad_char)]
pub struct DocAliasBadChar<'a> { pub struct DocAliasBadChar<'a> {
#[primary_span] #[primary_span]
@ -143,7 +143,7 @@ pub struct DocAliasBadChar<'a> {
pub char_: char, pub char_: char,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::doc_alias_start_end)] #[diag(passes::doc_alias_start_end)]
pub struct DocAliasStartEnd<'a> { pub struct DocAliasStartEnd<'a> {
#[primary_span] #[primary_span]
@ -151,7 +151,7 @@ pub struct DocAliasStartEnd<'a> {
pub attr_str: &'a str, pub attr_str: &'a str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::doc_alias_bad_location)] #[diag(passes::doc_alias_bad_location)]
pub struct DocAliasBadLocation<'a> { pub struct DocAliasBadLocation<'a> {
#[primary_span] #[primary_span]
@ -160,7 +160,7 @@ pub struct DocAliasBadLocation<'a> {
pub location: &'a str, pub location: &'a str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::doc_alias_not_an_alias)] #[diag(passes::doc_alias_not_an_alias)]
pub struct DocAliasNotAnAlias<'a> { pub struct DocAliasNotAnAlias<'a> {
#[primary_span] #[primary_span]
@ -175,35 +175,35 @@ pub struct DocAliasDuplicated {
pub first_defn: Span, pub first_defn: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::doc_alias_not_string_literal)] #[diag(passes::doc_alias_not_string_literal)]
pub struct DocAliasNotStringLiteral { pub struct DocAliasNotStringLiteral {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::doc_alias_malformed)] #[diag(passes::doc_alias_malformed)]
pub struct DocAliasMalformed { pub struct DocAliasMalformed {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::doc_keyword_empty_mod)] #[diag(passes::doc_keyword_empty_mod)]
pub struct DocKeywordEmptyMod { pub struct DocKeywordEmptyMod {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::doc_keyword_not_mod)] #[diag(passes::doc_keyword_not_mod)]
pub struct DocKeywordNotMod { pub struct DocKeywordNotMod {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::doc_keyword_invalid_ident)] #[diag(passes::doc_keyword_invalid_ident)]
pub struct DocKeywordInvalidIdent { pub struct DocKeywordInvalidIdent {
#[primary_span] #[primary_span]
@ -211,21 +211,21 @@ pub struct DocKeywordInvalidIdent {
pub doc_keyword: Symbol, pub doc_keyword: Symbol,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::doc_fake_variadic_not_valid)] #[diag(passes::doc_fake_variadic_not_valid)]
pub struct DocFakeVariadicNotValid { pub struct DocFakeVariadicNotValid {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::doc_keyword_only_impl)] #[diag(passes::doc_keyword_only_impl)]
pub struct DocKeywordOnlyImpl { pub struct DocKeywordOnlyImpl {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::doc_inline_conflict)] #[diag(passes::doc_inline_conflict)]
#[help] #[help]
pub struct DocKeywordConflict { pub struct DocKeywordConflict {
@ -243,7 +243,7 @@ pub struct DocInlineOnlyUse {
pub item_span: Option<Span>, pub item_span: Option<Span>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::doc_attr_not_crate_level)] #[diag(passes::doc_attr_not_crate_level)]
pub struct DocAttrNotCrateLevel<'a> { pub struct DocAttrNotCrateLevel<'a> {
#[primary_span] #[primary_span]
@ -295,7 +295,7 @@ pub struct DocTestUnknownInclude {
#[diag(passes::doc_invalid)] #[diag(passes::doc_invalid)]
pub struct DocInvalid; pub struct DocInvalid;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::pass_by_value)] #[diag(passes::pass_by_value)]
pub struct PassByValue { pub struct PassByValue {
#[primary_span] #[primary_span]
@ -304,7 +304,7 @@ pub struct PassByValue {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::allow_incoherent_impl)] #[diag(passes::allow_incoherent_impl)]
pub struct AllowIncoherentImpl { pub struct AllowIncoherentImpl {
#[primary_span] #[primary_span]
@ -313,7 +313,7 @@ pub struct AllowIncoherentImpl {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::has_incoherent_inherent_impl)] #[diag(passes::has_incoherent_inherent_impl)]
pub struct HasIncoherentInherentImpl { pub struct HasIncoherentInherentImpl {
#[primary_span] #[primary_span]
@ -336,7 +336,7 @@ pub struct MustUseNoEffect {
pub target: rustc_hir::Target, pub target: rustc_hir::Target,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::must_not_suspend)] #[diag(passes::must_not_suspend)]
pub struct MustNotSuspend { pub struct MustNotSuspend {
#[primary_span] #[primary_span]
@ -372,7 +372,7 @@ pub struct LinkName<'a> {
pub value: &'a str, pub value: &'a str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::no_link)] #[diag(passes::no_link)]
pub struct NoLink { pub struct NoLink {
#[primary_span] #[primary_span]
@ -381,7 +381,7 @@ pub struct NoLink {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::export_name)] #[diag(passes::export_name)]
pub struct ExportName { pub struct ExportName {
#[primary_span] #[primary_span]
@ -390,7 +390,7 @@ pub struct ExportName {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::rustc_layout_scalar_valid_range_not_struct)] #[diag(passes::rustc_layout_scalar_valid_range_not_struct)]
pub struct RustcLayoutScalarValidRangeNotStruct { pub struct RustcLayoutScalarValidRangeNotStruct {
#[primary_span] #[primary_span]
@ -399,14 +399,14 @@ pub struct RustcLayoutScalarValidRangeNotStruct {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::rustc_layout_scalar_valid_range_arg)] #[diag(passes::rustc_layout_scalar_valid_range_arg)]
pub struct RustcLayoutScalarValidRangeArg { pub struct RustcLayoutScalarValidRangeArg {
#[primary_span] #[primary_span]
pub attr_span: Span, pub attr_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::rustc_legacy_const_generics_only)] #[diag(passes::rustc_legacy_const_generics_only)]
pub struct RustcLegacyConstGenericsOnly { pub struct RustcLegacyConstGenericsOnly {
#[primary_span] #[primary_span]
@ -415,7 +415,7 @@ pub struct RustcLegacyConstGenericsOnly {
pub param_span: Span, pub param_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::rustc_legacy_const_generics_index)] #[diag(passes::rustc_legacy_const_generics_index)]
pub struct RustcLegacyConstGenericsIndex { pub struct RustcLegacyConstGenericsIndex {
#[primary_span] #[primary_span]
@ -424,7 +424,7 @@ pub struct RustcLegacyConstGenericsIndex {
pub generics_span: Span, pub generics_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::rustc_legacy_const_generics_index_exceed)] #[diag(passes::rustc_legacy_const_generics_index_exceed)]
pub struct RustcLegacyConstGenericsIndexExceed { pub struct RustcLegacyConstGenericsIndexExceed {
#[primary_span] #[primary_span]
@ -433,14 +433,14 @@ pub struct RustcLegacyConstGenericsIndexExceed {
pub arg_count: usize, pub arg_count: usize,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::rustc_legacy_const_generics_index_negative)] #[diag(passes::rustc_legacy_const_generics_index_negative)]
pub struct RustcLegacyConstGenericsIndexNegative { pub struct RustcLegacyConstGenericsIndexNegative {
#[primary_span] #[primary_span]
pub invalid_args: Vec<Span>, pub invalid_args: Vec<Span>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::rustc_dirty_clean)] #[diag(passes::rustc_dirty_clean)]
pub struct RustcDirtyClean { pub struct RustcDirtyClean {
#[primary_span] #[primary_span]
@ -475,7 +475,7 @@ pub struct NoMangle {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::repr_ident, code = "E0565")] #[diag(passes::repr_ident, code = "E0565")]
pub struct ReprIdent { pub struct ReprIdent {
#[primary_span] #[primary_span]
@ -486,21 +486,21 @@ pub struct ReprIdent {
#[diag(passes::repr_conflicting, code = "E0566")] #[diag(passes::repr_conflicting, code = "E0566")]
pub struct ReprConflicting; pub struct ReprConflicting;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::used_static)] #[diag(passes::used_static)]
pub struct UsedStatic { pub struct UsedStatic {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::used_compiler_linker)] #[diag(passes::used_compiler_linker)]
pub struct UsedCompilerLinker { pub struct UsedCompilerLinker {
#[primary_span] #[primary_span]
pub spans: Vec<Span>, pub spans: Vec<Span>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::allow_internal_unstable)] #[diag(passes::allow_internal_unstable)]
pub struct AllowInternalUnstable { pub struct AllowInternalUnstable {
#[primary_span] #[primary_span]
@ -509,14 +509,14 @@ pub struct AllowInternalUnstable {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::debug_visualizer_placement)] #[diag(passes::debug_visualizer_placement)]
pub struct DebugVisualizerPlacement { pub struct DebugVisualizerPlacement {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::debug_visualizer_invalid)] #[diag(passes::debug_visualizer_invalid)]
#[note(passes::note_1)] #[note(passes::note_1)]
#[note(passes::note_2)] #[note(passes::note_2)]
@ -526,7 +526,7 @@ pub struct DebugVisualizerInvalid {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::rustc_allow_const_fn_unstable)] #[diag(passes::rustc_allow_const_fn_unstable)]
pub struct RustcAllowConstFnUnstable { pub struct RustcAllowConstFnUnstable {
#[primary_span] #[primary_span]
@ -535,7 +535,7 @@ pub struct RustcAllowConstFnUnstable {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::rustc_std_internal_symbol)] #[diag(passes::rustc_std_internal_symbol)]
pub struct RustcStdInternalSymbol { pub struct RustcStdInternalSymbol {
#[primary_span] #[primary_span]
@ -544,21 +544,21 @@ pub struct RustcStdInternalSymbol {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::const_trait)] #[diag(passes::const_trait)]
pub struct ConstTrait { pub struct ConstTrait {
#[primary_span] #[primary_span]
pub attr_span: Span, pub attr_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::link_ordinal)] #[diag(passes::link_ordinal)]
pub struct LinkOrdinal { pub struct LinkOrdinal {
#[primary_span] #[primary_span]
pub attr_span: Span, pub attr_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::stability_promotable)] #[diag(passes::stability_promotable)]
pub struct StabilityPromotable { pub struct StabilityPromotable {
#[primary_span] #[primary_span]
@ -583,7 +583,7 @@ pub struct MacroExport;
#[diag(passes::plugin_registrar)] #[diag(passes::plugin_registrar)]
pub struct PluginRegistrar; pub struct PluginRegistrar;
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub enum UnusedNote { pub enum UnusedNote {
#[note(passes::unused_empty_lints_note)] #[note(passes::unused_empty_lints_note)]
EmptyList { name: Symbol }, EmptyList { name: Symbol },
@ -602,7 +602,7 @@ pub struct Unused {
pub note: UnusedNote, pub note: UnusedNote,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::non_exported_macro_invalid_attrs, code = "E0518")] #[diag(passes::non_exported_macro_invalid_attrs, code = "E0518")]
pub struct NonExportedMacroInvalidAttrs { pub struct NonExportedMacroInvalidAttrs {
#[primary_span] #[primary_span]
@ -621,7 +621,7 @@ pub struct UnusedDuplicate {
pub warning: Option<()>, pub warning: Option<()>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::unused_multiple)] #[diag(passes::unused_multiple)]
pub struct UnusedMultiple { pub struct UnusedMultiple {
#[primary_span] #[primary_span]
@ -632,7 +632,7 @@ pub struct UnusedMultiple {
pub name: Symbol, pub name: Symbol,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::rustc_lint_opt_ty)] #[diag(passes::rustc_lint_opt_ty)]
pub struct RustcLintOptTy { pub struct RustcLintOptTy {
#[primary_span] #[primary_span]
@ -641,7 +641,7 @@ pub struct RustcLintOptTy {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::rustc_lint_opt_deny_field_access)] #[diag(passes::rustc_lint_opt_deny_field_access)]
pub struct RustcLintOptDenyFieldAccess { pub struct RustcLintOptDenyFieldAccess {
#[primary_span] #[primary_span]
@ -650,7 +650,7 @@ pub struct RustcLintOptDenyFieldAccess {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(passes::collapse_debuginfo)] #[diag(passes::collapse_debuginfo)]
pub struct CollapseDebuginfo { pub struct CollapseDebuginfo {
#[primary_span] #[primary_span]

View file

@ -1,9 +1,9 @@
//! Errors emitted by plugin_impl //! Errors emitted by plugin_impl
use rustc_macros::SessionDiagnostic; use rustc_macros::Diagnostic;
use rustc_span::Span; use rustc_span::Span;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(plugin_impl::load_plugin_error)] #[diag(plugin_impl::load_plugin_error)]
pub struct LoadPluginError { pub struct LoadPluginError {
#[primary_span] #[primary_span]
@ -11,7 +11,7 @@ pub struct LoadPluginError {
pub msg: String, pub msg: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(plugin_impl::malformed_plugin_attribute, code = "E0498")] #[diag(plugin_impl::malformed_plugin_attribute, code = "E0498")]
pub struct MalformedPluginAttribute { pub struct MalformedPluginAttribute {
#[primary_span] #[primary_span]

View file

@ -1,8 +1,8 @@
use rustc_errors::DiagnosticArgFromDisplay; use rustc_errors::DiagnosticArgFromDisplay;
use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic}; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(privacy::field_is_private, code = "E0451")] #[diag(privacy::field_is_private, code = "E0451")]
pub struct FieldIsPrivate { pub struct FieldIsPrivate {
#[primary_span] #[primary_span]
@ -14,7 +14,7 @@ pub struct FieldIsPrivate {
pub label: FieldIsPrivateLabel, pub label: FieldIsPrivateLabel,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub enum FieldIsPrivateLabel { pub enum FieldIsPrivateLabel {
#[label(privacy::field_is_private_is_update_syntax_label)] #[label(privacy::field_is_private_is_update_syntax_label)]
IsUpdateSyntax { IsUpdateSyntax {
@ -29,7 +29,7 @@ pub enum FieldIsPrivateLabel {
}, },
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(privacy::item_is_private)] #[diag(privacy::item_is_private)]
pub struct ItemIsPrivate<'a> { pub struct ItemIsPrivate<'a> {
#[primary_span] #[primary_span]
@ -39,7 +39,7 @@ pub struct ItemIsPrivate<'a> {
pub descr: DiagnosticArgFromDisplay<'a>, pub descr: DiagnosticArgFromDisplay<'a>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(privacy::unnamed_item_is_private)] #[diag(privacy::unnamed_item_is_private)]
pub struct UnnamedItemIsPrivate { pub struct UnnamedItemIsPrivate {
#[primary_span] #[primary_span]
@ -48,7 +48,7 @@ pub struct UnnamedItemIsPrivate {
} }
// Duplicate of `InPublicInterface` but with a different error code, shares the same slug. // Duplicate of `InPublicInterface` but with a different error code, shares the same slug.
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(privacy::in_public_interface, code = "E0445")] #[diag(privacy::in_public_interface, code = "E0445")]
pub struct InPublicInterfaceTraits<'a> { pub struct InPublicInterfaceTraits<'a> {
#[primary_span] #[primary_span]
@ -62,7 +62,7 @@ pub struct InPublicInterfaceTraits<'a> {
} }
// Duplicate of `InPublicInterfaceTraits` but with a different error code, shares the same slug. // Duplicate of `InPublicInterfaceTraits` but with a different error code, shares the same slug.
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(privacy::in_public_interface, code = "E0446")] #[diag(privacy::in_public_interface, code = "E0446")]
pub struct InPublicInterface<'a> { pub struct InPublicInterface<'a> {
#[primary_span] #[primary_span]
@ -75,7 +75,7 @@ pub struct InPublicInterface<'a> {
pub vis_span: Span, pub vis_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(privacy::report_effective_visibility)] #[diag(privacy::report_effective_visibility)]
pub struct ReportEffectiveVisibility { pub struct ReportEffectiveVisibility {
#[primary_span] #[primary_span]

View file

@ -1,4 +1,5 @@
use rustc_errors::AddSubdiagnostic; use rustc_errors::AddToDiagnostic;
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_session::Limit; use rustc_session::Limit;
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
@ -7,7 +8,7 @@ pub struct CycleStack {
pub desc: String, pub desc: String,
} }
impl AddSubdiagnostic for CycleStack { impl AddToDiagnostic for CycleStack {
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
diag.span_note(self.span, &format!("...which requires {}...", self.desc)); diag.span_note(self.span, &format!("...which requires {}...", self.desc));
} }
@ -20,7 +21,7 @@ pub enum HandleCycleError {
DelayBug, DelayBug,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub enum StackCount { pub enum StackCount {
#[note(query_system::cycle_stack_single)] #[note(query_system::cycle_stack_single)]
Single, Single,
@ -28,7 +29,7 @@ pub enum StackCount {
Multiple, Multiple,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub enum Alias { pub enum Alias {
#[note(query_system::cycle_recursive_ty_alias)] #[note(query_system::cycle_recursive_ty_alias)]
#[help(query_system::cycle_recursive_ty_alias_help1)] #[help(query_system::cycle_recursive_ty_alias_help1)]
@ -38,7 +39,7 @@ pub enum Alias {
Trait, Trait,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[note(query_system::cycle_usage)] #[note(query_system::cycle_usage)]
pub struct CycleUsage { pub struct CycleUsage {
#[primary_span] #[primary_span]
@ -46,7 +47,7 @@ pub struct CycleUsage {
pub usage: String, pub usage: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(query_system::cycle, code = "E0391")] #[diag(query_system::cycle, code = "E0391")]
pub struct Cycle { pub struct Cycle {
#[primary_span] #[primary_span]
@ -62,11 +63,11 @@ pub struct Cycle {
pub cycle_usage: Option<CycleUsage>, pub cycle_usage: Option<CycleUsage>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(query_system::reentrant)] #[diag(query_system::reentrant)]
pub struct Reentrant; pub struct Reentrant;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(query_system::increment_compilation)] #[diag(query_system::increment_compilation)]
#[help] #[help]
#[note(query_system::increment_compilation_note1)] #[note(query_system::increment_compilation_note1)]
@ -76,7 +77,7 @@ pub struct IncrementCompilation {
pub dep_node: String, pub dep_node: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[help] #[help]
#[diag(query_system::query_overflow)] #[diag(query_system::query_overflow)]
pub struct QueryOverflow { pub struct QueryOverflow {
@ -88,7 +89,7 @@ pub struct QueryOverflow {
pub crate_name: Symbol, pub crate_name: Symbol,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[note(query_system::layout_of_depth)] #[note(query_system::layout_of_depth)]
pub struct LayoutOfDepth { pub struct LayoutOfDepth {
pub desc: String, pub desc: String,

View file

@ -3,9 +3,11 @@ use crate::query::plumbing::CycleError;
use crate::query::{QueryContext, QueryStackFrame}; use crate::query::{QueryContext, QueryStackFrame};
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, Level}; use rustc_errors::{
Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic, Level,
};
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_session::{Session, SessionDiagnostic}; use rustc_session::Session;
use rustc_span::Span; use rustc_span::Span;
use std::hash::Hash; use std::hash::Hash;

View file

@ -1,8 +1,8 @@
use rustc_macros::SessionDiagnostic; use rustc_macros::Diagnostic;
use std::path::Path; use std::path::Path;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(save_analysis::could_not_open)] #[diag(save_analysis::could_not_open)]
pub(crate) struct CouldNotOpen<'a> { pub(crate) struct CouldNotOpen<'a> {
pub file_name: &'a Path, pub file_name: &'a Path,

View file

@ -3,6 +3,7 @@
pub use crate::options::*; pub use crate::options::*;
use crate::errors::TargetDataLayoutErrorsWrapper;
use crate::search_paths::SearchPath; use crate::search_paths::SearchPath;
use crate::utils::{CanonicalizedPath, NativeLib, NativeLibKind}; use crate::utils::{CanonicalizedPath, NativeLib, NativeLibKind};
use crate::{early_error, early_warn, Session}; use crate::{early_error, early_warn, Session};
@ -898,7 +899,7 @@ fn default_configuration(sess: &Session) -> CrateConfig {
let max_atomic_width = sess.target.max_atomic_width(); let max_atomic_width = sess.target.max_atomic_width();
let atomic_cas = sess.target.atomic_cas; let atomic_cas = sess.target.atomic_cas;
let layout = TargetDataLayout::parse(&sess.target).unwrap_or_else(|err| { let layout = TargetDataLayout::parse(&sess.target).unwrap_or_else(|err| {
sess.emit_fatal(err); sess.emit_fatal(TargetDataLayoutErrorsWrapper(err));
}); });
let mut ret = CrateConfig::default(); let mut ret = CrateConfig::default();

View file

@ -1,14 +1,15 @@
use std::num::NonZeroU32; use std::num::NonZeroU32;
use crate::cgu_reuse_tracker::CguReuse; use crate::cgu_reuse_tracker::CguReuse;
use crate::{self as rustc_session, SessionDiagnostic}; use rustc_errors::{
use rustc_errors::{fluent, DiagnosticBuilder, ErrorGuaranteed, Handler, MultiSpan}; fluent, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic, MultiSpan,
use rustc_macros::SessionDiagnostic; };
use rustc_macros::Diagnostic;
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
use rustc_target::abi::TargetDataLayoutErrors; use rustc_target::abi::TargetDataLayoutErrors;
use rustc_target::spec::{SplitDebuginfo, StackProtector, TargetTriple}; use rustc_target::spec::{SplitDebuginfo, StackProtector, TargetTriple};
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(session::incorrect_cgu_reuse_type)] #[diag(session::incorrect_cgu_reuse_type)]
pub struct IncorrectCguReuseType<'a> { pub struct IncorrectCguReuseType<'a> {
#[primary_span] #[primary_span]
@ -19,14 +20,14 @@ pub struct IncorrectCguReuseType<'a> {
pub at_least: u8, pub at_least: u8,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(session::cgu_not_recorded)] #[diag(session::cgu_not_recorded)]
pub struct CguNotRecorded<'a> { pub struct CguNotRecorded<'a> {
pub cgu_user_name: &'a str, pub cgu_user_name: &'a str,
pub cgu_name: &'a str, pub cgu_name: &'a str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(session::feature_gate_error, code = "E0658")] #[diag(session::feature_gate_error, code = "E0658")]
pub struct FeatureGateError<'a> { pub struct FeatureGateError<'a> {
#[primary_span] #[primary_span]
@ -34,31 +35,33 @@ pub struct FeatureGateError<'a> {
pub explain: &'a str, pub explain: &'a str,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[note(session::feature_diagnostic_for_issue)] #[note(session::feature_diagnostic_for_issue)]
pub struct FeatureDiagnosticForIssue { pub struct FeatureDiagnosticForIssue {
pub n: NonZeroU32, pub n: NonZeroU32,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[help(session::feature_diagnostic_help)] #[help(session::feature_diagnostic_help)]
pub struct FeatureDiagnosticHelp { pub struct FeatureDiagnosticHelp {
pub feature: Symbol, pub feature: Symbol,
} }
impl SessionDiagnostic<'_, !> for TargetDataLayoutErrors<'_> { pub struct TargetDataLayoutErrorsWrapper<'a>(pub TargetDataLayoutErrors<'a>);
fn into_diagnostic(self, sess: &Handler) -> DiagnosticBuilder<'_, !> {
impl IntoDiagnostic<'_, !> for TargetDataLayoutErrorsWrapper<'_> {
fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, !> {
let mut diag; let mut diag;
match self { match self.0 {
TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => { TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => {
diag = sess.struct_fatal(fluent::session::target_invalid_address_space); diag = handler.struct_fatal(fluent::session::target_invalid_address_space);
diag.set_arg("addr_space", addr_space); diag.set_arg("addr_space", addr_space);
diag.set_arg("cause", cause); diag.set_arg("cause", cause);
diag.set_arg("err", err); diag.set_arg("err", err);
diag diag
} }
TargetDataLayoutErrors::InvalidBits { kind, bit, cause, err } => { TargetDataLayoutErrors::InvalidBits { kind, bit, cause, err } => {
diag = sess.struct_fatal(fluent::session::target_invalid_bits); diag = handler.struct_fatal(fluent::session::target_invalid_bits);
diag.set_arg("kind", kind); diag.set_arg("kind", kind);
diag.set_arg("bit", bit); diag.set_arg("bit", bit);
diag.set_arg("cause", cause); diag.set_arg("cause", cause);
@ -66,30 +69,30 @@ impl SessionDiagnostic<'_, !> for TargetDataLayoutErrors<'_> {
diag diag
} }
TargetDataLayoutErrors::MissingAlignment { cause } => { TargetDataLayoutErrors::MissingAlignment { cause } => {
diag = sess.struct_fatal(fluent::session::target_missing_alignment); diag = handler.struct_fatal(fluent::session::target_missing_alignment);
diag.set_arg("cause", cause); diag.set_arg("cause", cause);
diag diag
} }
TargetDataLayoutErrors::InvalidAlignment { cause, err } => { TargetDataLayoutErrors::InvalidAlignment { cause, err } => {
diag = sess.struct_fatal(fluent::session::target_invalid_alignment); diag = handler.struct_fatal(fluent::session::target_invalid_alignment);
diag.set_arg("cause", cause); diag.set_arg("cause", cause);
diag.set_arg("err", err); diag.set_arg("err", err);
diag diag
} }
TargetDataLayoutErrors::InconsistentTargetArchitecture { dl, target } => { TargetDataLayoutErrors::InconsistentTargetArchitecture { dl, target } => {
diag = sess.struct_fatal(fluent::session::target_inconsistent_architecture); diag = handler.struct_fatal(fluent::session::target_inconsistent_architecture);
diag.set_arg("dl", dl); diag.set_arg("dl", dl);
diag.set_arg("target", target); diag.set_arg("target", target);
diag diag
} }
TargetDataLayoutErrors::InconsistentTargetPointerWidth { pointer_size, target } => { TargetDataLayoutErrors::InconsistentTargetPointerWidth { pointer_size, target } => {
diag = sess.struct_fatal(fluent::session::target_inconsistent_pointer_width); diag = handler.struct_fatal(fluent::session::target_inconsistent_pointer_width);
diag.set_arg("pointer_size", pointer_size); diag.set_arg("pointer_size", pointer_size);
diag.set_arg("target", target); diag.set_arg("target", target);
diag diag
} }
TargetDataLayoutErrors::InvalidBitsSize { err } => { TargetDataLayoutErrors::InvalidBitsSize { err } => {
diag = sess.struct_fatal(fluent::session::target_invalid_bits_size); diag = handler.struct_fatal(fluent::session::target_invalid_bits_size);
diag.set_arg("err", err); diag.set_arg("err", err);
diag diag
} }
@ -97,87 +100,87 @@ impl SessionDiagnostic<'_, !> for TargetDataLayoutErrors<'_> {
} }
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(session::not_circumvent_feature)] #[diag(session::not_circumvent_feature)]
pub struct NotCircumventFeature; pub struct NotCircumventFeature;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(session::linker_plugin_lto_windows_not_supported)] #[diag(session::linker_plugin_lto_windows_not_supported)]
pub struct LinkerPluginToWindowsNotSupported; pub struct LinkerPluginToWindowsNotSupported;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(session::profile_use_file_does_not_exist)] #[diag(session::profile_use_file_does_not_exist)]
pub struct ProfileUseFileDoesNotExist<'a> { pub struct ProfileUseFileDoesNotExist<'a> {
pub path: &'a std::path::Path, pub path: &'a std::path::Path,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(session::profile_sample_use_file_does_not_exist)] #[diag(session::profile_sample_use_file_does_not_exist)]
pub struct ProfileSampleUseFileDoesNotExist<'a> { pub struct ProfileSampleUseFileDoesNotExist<'a> {
pub path: &'a std::path::Path, pub path: &'a std::path::Path,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(session::target_requires_unwind_tables)] #[diag(session::target_requires_unwind_tables)]
pub struct TargetRequiresUnwindTables; pub struct TargetRequiresUnwindTables;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(session::sanitizer_not_supported)] #[diag(session::sanitizer_not_supported)]
pub struct SanitizerNotSupported { pub struct SanitizerNotSupported {
pub us: String, pub us: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(session::sanitizers_not_supported)] #[diag(session::sanitizers_not_supported)]
pub struct SanitizersNotSupported { pub struct SanitizersNotSupported {
pub us: String, pub us: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(session::cannot_mix_and_match_sanitizers)] #[diag(session::cannot_mix_and_match_sanitizers)]
pub struct CannotMixAndMatchSanitizers { pub struct CannotMixAndMatchSanitizers {
pub first: String, pub first: String,
pub second: String, pub second: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(session::cannot_enable_crt_static_linux)] #[diag(session::cannot_enable_crt_static_linux)]
pub struct CannotEnableCrtStaticLinux; pub struct CannotEnableCrtStaticLinux;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(session::sanitizer_cfi_enabled)] #[diag(session::sanitizer_cfi_enabled)]
pub struct SanitizerCfiEnabled; pub struct SanitizerCfiEnabled;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(session::unstable_virtual_function_elimination)] #[diag(session::unstable_virtual_function_elimination)]
pub struct UnstableVirtualFunctionElimination; pub struct UnstableVirtualFunctionElimination;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(session::unsupported_dwarf_version)] #[diag(session::unsupported_dwarf_version)]
pub struct UnsupportedDwarfVersion { pub struct UnsupportedDwarfVersion {
pub dwarf_version: u32, pub dwarf_version: u32,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(session::target_stack_protector_not_supported)] #[diag(session::target_stack_protector_not_supported)]
pub struct StackProtectorNotSupportedForTarget<'a> { pub struct StackProtectorNotSupportedForTarget<'a> {
pub stack_protector: StackProtector, pub stack_protector: StackProtector,
pub target_triple: &'a TargetTriple, pub target_triple: &'a TargetTriple,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(session::split_debuginfo_unstable_platform)] #[diag(session::split_debuginfo_unstable_platform)]
pub struct SplitDebugInfoUnstablePlatform { pub struct SplitDebugInfoUnstablePlatform {
pub debuginfo: SplitDebuginfo, pub debuginfo: SplitDebuginfo,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(session::file_is_not_writeable)] #[diag(session::file_is_not_writeable)]
pub struct FileIsNotWriteable<'a> { pub struct FileIsNotWriteable<'a> {
pub file: &'a std::path::Path, pub file: &'a std::path::Path,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(session::crate_name_does_not_match)] #[diag(session::crate_name_does_not_match)]
pub struct CrateNameDoesNotMatch<'a> { pub struct CrateNameDoesNotMatch<'a> {
#[primary_span] #[primary_span]
@ -186,13 +189,13 @@ pub struct CrateNameDoesNotMatch<'a> {
pub name: Symbol, pub name: Symbol,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(session::crate_name_invalid)] #[diag(session::crate_name_invalid)]
pub struct CrateNameInvalid<'a> { pub struct CrateNameInvalid<'a> {
pub s: &'a str, pub s: &'a str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(session::crate_name_empty)] #[diag(session::crate_name_empty)]
pub struct CrateNameEmpty { pub struct CrateNameEmpty {
#[primary_span] #[primary_span]
@ -205,11 +208,8 @@ pub struct InvalidCharacterInCrateName<'a> {
pub crate_name: &'a str, pub crate_name: &'a str,
} }
impl crate::SessionDiagnostic<'_> for InvalidCharacterInCrateName<'_> { impl IntoDiagnostic<'_> for InvalidCharacterInCrateName<'_> {
fn into_diagnostic( fn into_diagnostic(self, sess: &Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
self,
sess: &Handler,
) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
let mut diag = sess.struct_err(fluent::session::invalid_character_in_create_name); let mut diag = sess.struct_err(fluent::session::invalid_character_in_create_name);
if let Some(sp) = self.span { if let Some(sp) = self.span {
diag.set_span(sp); diag.set_span(sp);

View file

@ -6,14 +6,13 @@ use crate::errors::{FeatureDiagnosticForIssue, FeatureDiagnosticHelp, FeatureGat
use crate::lint::{ use crate::lint::{
builtin::UNSTABLE_SYNTAX_PRE_EXPANSION, BufferedEarlyLint, BuiltinLintDiagnostics, Lint, LintId, builtin::UNSTABLE_SYNTAX_PRE_EXPANSION, BufferedEarlyLint, BuiltinLintDiagnostics, Lint, LintId,
}; };
use crate::SessionDiagnostic;
use rustc_ast::node_id::NodeId; use rustc_ast::node_id::NodeId;
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
use rustc_data_structures::sync::{Lock, Lrc}; use rustc_data_structures::sync::{Lock, Lrc};
use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler}; use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler};
use rustc_errors::{ use rustc_errors::{
fallback_fluent_bundle, Applicability, Diagnostic, DiagnosticBuilder, DiagnosticId, fallback_fluent_bundle, Applicability, Diagnostic, DiagnosticBuilder, DiagnosticId,
DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, MultiSpan, StashKey, DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, IntoDiagnostic, MultiSpan, StashKey,
}; };
use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures}; use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures};
use rustc_span::edition::Edition; use rustc_span::edition::Edition;
@ -345,34 +344,34 @@ impl ParseSess {
pub fn create_err<'a>( pub fn create_err<'a>(
&'a self, &'a self,
err: impl SessionDiagnostic<'a>, err: impl IntoDiagnostic<'a>,
) -> DiagnosticBuilder<'a, ErrorGuaranteed> { ) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
err.into_diagnostic(&self.span_diagnostic) err.into_diagnostic(&self.span_diagnostic)
} }
pub fn emit_err<'a>(&'a self, err: impl SessionDiagnostic<'a>) -> ErrorGuaranteed { pub fn emit_err<'a>(&'a self, err: impl IntoDiagnostic<'a>) -> ErrorGuaranteed {
self.create_err(err).emit() self.create_err(err).emit()
} }
pub fn create_warning<'a>( pub fn create_warning<'a>(
&'a self, &'a self,
warning: impl SessionDiagnostic<'a, ()>, warning: impl IntoDiagnostic<'a, ()>,
) -> DiagnosticBuilder<'a, ()> { ) -> DiagnosticBuilder<'a, ()> {
warning.into_diagnostic(&self.span_diagnostic) warning.into_diagnostic(&self.span_diagnostic)
} }
pub fn emit_warning<'a>(&'a self, warning: impl SessionDiagnostic<'a, ()>) { pub fn emit_warning<'a>(&'a self, warning: impl IntoDiagnostic<'a, ()>) {
self.create_warning(warning).emit() self.create_warning(warning).emit()
} }
pub fn create_fatal<'a>( pub fn create_fatal<'a>(
&'a self, &'a self,
fatal: impl SessionDiagnostic<'a, !>, fatal: impl IntoDiagnostic<'a, !>,
) -> DiagnosticBuilder<'a, !> { ) -> DiagnosticBuilder<'a, !> {
fatal.into_diagnostic(&self.span_diagnostic) fatal.into_diagnostic(&self.span_diagnostic)
} }
pub fn emit_fatal<'a>(&'a self, fatal: impl SessionDiagnostic<'a, !>) -> ! { pub fn emit_fatal<'a>(&'a self, fatal: impl IntoDiagnostic<'a, !>) -> ! {
self.create_fatal(fatal).emit() self.create_fatal(fatal).emit()
} }

View file

@ -28,7 +28,7 @@ use rustc_errors::json::JsonEmitter;
use rustc_errors::registry::Registry; use rustc_errors::registry::Registry;
use rustc_errors::{ use rustc_errors::{
error_code, fallback_fluent_bundle, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, error_code, fallback_fluent_bundle, DiagnosticBuilder, DiagnosticId, DiagnosticMessage,
EmissionGuarantee, ErrorGuaranteed, FluentBundle, Handler, LazyFallbackBundle, MultiSpan, ErrorGuaranteed, FluentBundle, IntoDiagnostic, LazyFallbackBundle, MultiSpan,
}; };
use rustc_macros::HashStable_Generic; use rustc_macros::HashStable_Generic;
pub use rustc_span::def_id::StableCrateId; pub use rustc_span::def_id::StableCrateId;
@ -223,15 +223,6 @@ pub struct PerfStats {
pub normalize_projection_ty: AtomicUsize, pub normalize_projection_ty: AtomicUsize,
} }
/// Trait implemented by error types. This should not be implemented manually. Instead, use
/// `#[derive(SessionDiagnostic)]` -- see [rustc_macros::SessionDiagnostic].
#[rustc_diagnostic_item = "SessionDiagnostic"]
pub trait SessionDiagnostic<'a, T: EmissionGuarantee = ErrorGuaranteed> {
/// Write out as a diagnostic out of `Handler`.
#[must_use]
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, T>;
}
impl Session { impl Session {
pub fn miri_unleashed_feature(&self, span: Span, feature_gate: Option<Symbol>) { pub fn miri_unleashed_feature(&self, span: Span, feature_gate: Option<Symbol>) {
self.miri_unleashed_features.lock().push((span, feature_gate)); self.miri_unleashed_features.lock().push((span, feature_gate));
@ -514,13 +505,13 @@ impl Session {
} }
pub fn create_err<'a>( pub fn create_err<'a>(
&'a self, &'a self,
err: impl SessionDiagnostic<'a>, err: impl IntoDiagnostic<'a>,
) -> DiagnosticBuilder<'a, ErrorGuaranteed> { ) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
self.parse_sess.create_err(err) self.parse_sess.create_err(err)
} }
pub fn create_feature_err<'a>( pub fn create_feature_err<'a>(
&'a self, &'a self,
err: impl SessionDiagnostic<'a>, err: impl IntoDiagnostic<'a>,
feature: Symbol, feature: Symbol,
) -> DiagnosticBuilder<'a, ErrorGuaranteed> { ) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
let mut err = self.parse_sess.create_err(err); let mut err = self.parse_sess.create_err(err);
@ -530,25 +521,25 @@ impl Session {
add_feature_diagnostics(&mut err, &self.parse_sess, feature); add_feature_diagnostics(&mut err, &self.parse_sess, feature);
err err
} }
pub fn emit_err<'a>(&'a self, err: impl SessionDiagnostic<'a>) -> ErrorGuaranteed { pub fn emit_err<'a>(&'a self, err: impl IntoDiagnostic<'a>) -> ErrorGuaranteed {
self.parse_sess.emit_err(err) self.parse_sess.emit_err(err)
} }
pub fn create_warning<'a>( pub fn create_warning<'a>(
&'a self, &'a self,
err: impl SessionDiagnostic<'a, ()>, err: impl IntoDiagnostic<'a, ()>,
) -> DiagnosticBuilder<'a, ()> { ) -> DiagnosticBuilder<'a, ()> {
self.parse_sess.create_warning(err) self.parse_sess.create_warning(err)
} }
pub fn emit_warning<'a>(&'a self, warning: impl SessionDiagnostic<'a, ()>) { pub fn emit_warning<'a>(&'a self, warning: impl IntoDiagnostic<'a, ()>) {
self.parse_sess.emit_warning(warning) self.parse_sess.emit_warning(warning)
} }
pub fn create_fatal<'a>( pub fn create_fatal<'a>(
&'a self, &'a self,
fatal: impl SessionDiagnostic<'a, !>, fatal: impl IntoDiagnostic<'a, !>,
) -> DiagnosticBuilder<'a, !> { ) -> DiagnosticBuilder<'a, !> {
self.parse_sess.create_fatal(fatal) self.parse_sess.create_fatal(fatal)
} }
pub fn emit_fatal<'a>(&'a self, fatal: impl SessionDiagnostic<'a, !>) -> ! { pub fn emit_fatal<'a>(&'a self, fatal: impl IntoDiagnostic<'a, !>) -> ! {
self.parse_sess.emit_fatal(fatal) self.parse_sess.emit_fatal(fatal)
} }
#[inline] #[inline]

View file

@ -125,7 +125,7 @@ symbols! {
Symbols { Symbols {
AcqRel, AcqRel,
Acquire, Acquire,
AddSubdiagnostic, AddToDiagnostic,
Alignment, Alignment,
Any, Any,
Arc, Arc,
@ -210,6 +210,7 @@ symbols! {
Implied, Implied,
Input, Input,
Into, Into,
IntoDiagnostic,
IntoFuture, IntoFuture,
IntoIterator, IntoIterator,
IoRead, IoRead,
@ -277,7 +278,6 @@ symbols! {
RwLockWriteGuard, RwLockWriteGuard,
Send, Send,
SeqCst, SeqCst,
SessionDiagnostic,
SliceIndex, SliceIndex,
Some, Some,
String, String,

View file

@ -1,10 +1,10 @@
//! Errors emitted by symbol_mangling. //! Errors emitted by symbol_mangling.
use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg}; use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
use rustc_macros::SessionDiagnostic; use rustc_macros::Diagnostic;
use rustc_span::Span; use rustc_span::Span;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(symbol_mangling::test_output)] #[diag(symbol_mangling::test_output)]
pub struct TestOutput { pub struct TestOutput {
#[primary_span] #[primary_span]

View file

@ -1,10 +1,10 @@
use rustc_errors::{fluent, ErrorGuaranteed, Handler}; use rustc_errors::{fluent, ErrorGuaranteed, Handler, IntoDiagnostic};
use rustc_macros::SessionDiagnostic; use rustc_macros::Diagnostic;
use rustc_middle::ty::{PolyTraitRef, Ty, Unevaluated}; use rustc_middle::ty::{PolyTraitRef, Ty, Unevaluated};
use rustc_session::{Limit, SessionDiagnostic}; use rustc_session::Limit;
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(trait_selection::dump_vtable_entries)] #[diag(trait_selection::dump_vtable_entries)]
pub struct DumpVTableEntries<'a> { pub struct DumpVTableEntries<'a> {
#[primary_span] #[primary_span]
@ -13,7 +13,7 @@ pub struct DumpVTableEntries<'a> {
pub entries: String, pub entries: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(trait_selection::unable_to_construct_constant_value)] #[diag(trait_selection::unable_to_construct_constant_value)]
pub struct UnableToConstructConstantValue<'a> { pub struct UnableToConstructConstantValue<'a> {
#[primary_span] #[primary_span]
@ -21,7 +21,7 @@ pub struct UnableToConstructConstantValue<'a> {
pub unevaluated: Unevaluated<'a>, pub unevaluated: Unevaluated<'a>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[help] #[help]
#[diag(trait_selection::auto_deref_reached_recursion_limit, code = "E0055")] #[diag(trait_selection::auto_deref_reached_recursion_limit, code = "E0055")]
pub struct AutoDerefReachedRecursionLimit<'a> { pub struct AutoDerefReachedRecursionLimit<'a> {
@ -33,7 +33,7 @@ pub struct AutoDerefReachedRecursionLimit<'a> {
pub crate_name: Symbol, pub crate_name: Symbol,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(trait_selection::empty_on_clause_in_rustc_on_unimplemented, code = "E0232")] #[diag(trait_selection::empty_on_clause_in_rustc_on_unimplemented, code = "E0232")]
pub struct EmptyOnClauseInOnUnimplemented { pub struct EmptyOnClauseInOnUnimplemented {
#[primary_span] #[primary_span]
@ -41,7 +41,7 @@ pub struct EmptyOnClauseInOnUnimplemented {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(trait_selection::invalid_on_clause_in_rustc_on_unimplemented, code = "E0232")] #[diag(trait_selection::invalid_on_clause_in_rustc_on_unimplemented, code = "E0232")]
pub struct InvalidOnClauseInOnUnimplemented { pub struct InvalidOnClauseInOnUnimplemented {
#[primary_span] #[primary_span]
@ -49,7 +49,7 @@ pub struct InvalidOnClauseInOnUnimplemented {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(trait_selection::no_value_in_rustc_on_unimplemented, code = "E0232")] #[diag(trait_selection::no_value_in_rustc_on_unimplemented, code = "E0232")]
#[note] #[note]
pub struct NoValueInOnUnimplemented { pub struct NoValueInOnUnimplemented {
@ -66,7 +66,7 @@ pub struct NegativePositiveConflict<'a> {
pub positive_impl_span: Result<Span, Symbol>, pub positive_impl_span: Result<Span, Symbol>,
} }
impl SessionDiagnostic<'_> for NegativePositiveConflict<'_> { impl IntoDiagnostic<'_> for NegativePositiveConflict<'_> {
fn into_diagnostic( fn into_diagnostic(
self, self,
handler: &Handler, handler: &Handler,

View file

@ -1,16 +1,16 @@
//! Errors emitted by ty_utils //! Errors emitted by ty_utils
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic}; use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;
use rustc_span::Span; use rustc_span::Span;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ty_utils::needs_drop_overflow)] #[diag(ty_utils::needs_drop_overflow)]
pub struct NeedsDropOverflow<'tcx> { pub struct NeedsDropOverflow<'tcx> {
pub query_ty: Ty<'tcx>, pub query_ty: Ty<'tcx>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(ty_utils::generic_constant_too_complex)] #[diag(ty_utils::generic_constant_too_complex)]
#[help] #[help]
pub struct GenericConstantTooComplex { pub struct GenericConstantTooComplex {
@ -22,7 +22,7 @@ pub struct GenericConstantTooComplex {
pub sub: GenericConstantTooComplexSub, pub sub: GenericConstantTooComplexSub,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub enum GenericConstantTooComplexSub { pub enum GenericConstantTooComplexSub {
#[label(ty_utils::borrow_not_supported)] #[label(ty_utils::borrow_not_supported)]
BorrowNotSupported(#[primary_span] Span), BorrowNotSupported(#[primary_span] Span),

View file

@ -881,7 +881,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return; return;
} }
// FIXME: Make this use SessionDiagnostic once error codes can be dynamically set. // FIXME: Make this use Diagnostic once error codes can be dynamically set.
let mut err = self.tcx.sess.struct_span_err_with_code( let mut err = self.tcx.sess.struct_span_err_with_code(
op_span, op_span,
"invalid left-hand side of assignment", "invalid left-hand side of assignment",

View file

@ -1,11 +1,11 @@
//! Errors emitted by typeck. //! Errors emitted by typeck.
use rustc_errors::IntoDiagnostic;
use rustc_errors::{error_code, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler}; use rustc_errors::{error_code, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler};
use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic}; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;
use rustc_session::SessionDiagnostic;
use rustc_span::{symbol::Ident, Span, Symbol}; use rustc_span::{symbol::Ident, Span, Symbol};
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::field_multiply_specified_in_initializer, code = "E0062")] #[diag(typeck::field_multiply_specified_in_initializer, code = "E0062")]
pub struct FieldMultiplySpecifiedInInitializer { pub struct FieldMultiplySpecifiedInInitializer {
#[primary_span] #[primary_span]
@ -16,7 +16,7 @@ pub struct FieldMultiplySpecifiedInInitializer {
pub ident: Ident, pub ident: Ident,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::unrecognized_atomic_operation, code = "E0092")] #[diag(typeck::unrecognized_atomic_operation, code = "E0092")]
pub struct UnrecognizedAtomicOperation<'a> { pub struct UnrecognizedAtomicOperation<'a> {
#[primary_span] #[primary_span]
@ -25,7 +25,7 @@ pub struct UnrecognizedAtomicOperation<'a> {
pub op: &'a str, pub op: &'a str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::wrong_number_of_generic_arguments_to_intrinsic, code = "E0094")] #[diag(typeck::wrong_number_of_generic_arguments_to_intrinsic, code = "E0094")]
pub struct WrongNumberOfGenericArgumentsToIntrinsic<'a> { pub struct WrongNumberOfGenericArgumentsToIntrinsic<'a> {
#[primary_span] #[primary_span]
@ -36,7 +36,7 @@ pub struct WrongNumberOfGenericArgumentsToIntrinsic<'a> {
pub descr: &'a str, pub descr: &'a str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::unrecognized_intrinsic_function, code = "E0093")] #[diag(typeck::unrecognized_intrinsic_function, code = "E0093")]
pub struct UnrecognizedIntrinsicFunction { pub struct UnrecognizedIntrinsicFunction {
#[primary_span] #[primary_span]
@ -45,7 +45,7 @@ pub struct UnrecognizedIntrinsicFunction {
pub name: Symbol, pub name: Symbol,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::lifetimes_or_bounds_mismatch_on_trait, code = "E0195")] #[diag(typeck::lifetimes_or_bounds_mismatch_on_trait, code = "E0195")]
pub struct LifetimesOrBoundsMismatchOnTrait { pub struct LifetimesOrBoundsMismatchOnTrait {
#[primary_span] #[primary_span]
@ -57,7 +57,7 @@ pub struct LifetimesOrBoundsMismatchOnTrait {
pub ident: Ident, pub ident: Ident,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::drop_impl_on_wrong_item, code = "E0120")] #[diag(typeck::drop_impl_on_wrong_item, code = "E0120")]
pub struct DropImplOnWrongItem { pub struct DropImplOnWrongItem {
#[primary_span] #[primary_span]
@ -65,7 +65,7 @@ pub struct DropImplOnWrongItem {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::field_already_declared, code = "E0124")] #[diag(typeck::field_already_declared, code = "E0124")]
pub struct FieldAlreadyDeclared { pub struct FieldAlreadyDeclared {
pub field_name: Ident, pub field_name: Ident,
@ -76,7 +76,7 @@ pub struct FieldAlreadyDeclared {
pub prev_span: Span, pub prev_span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::copy_impl_on_type_with_dtor, code = "E0184")] #[diag(typeck::copy_impl_on_type_with_dtor, code = "E0184")]
pub struct CopyImplOnTypeWithDtor { pub struct CopyImplOnTypeWithDtor {
#[primary_span] #[primary_span]
@ -84,14 +84,14 @@ pub struct CopyImplOnTypeWithDtor {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::multiple_relaxed_default_bounds, code = "E0203")] #[diag(typeck::multiple_relaxed_default_bounds, code = "E0203")]
pub struct MultipleRelaxedDefaultBounds { pub struct MultipleRelaxedDefaultBounds {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::copy_impl_on_non_adt, code = "E0206")] #[diag(typeck::copy_impl_on_non_adt, code = "E0206")]
pub struct CopyImplOnNonAdt { pub struct CopyImplOnNonAdt {
#[primary_span] #[primary_span]
@ -99,7 +99,7 @@ pub struct CopyImplOnNonAdt {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::trait_object_declared_with_no_traits, code = "E0224")] #[diag(typeck::trait_object_declared_with_no_traits, code = "E0224")]
pub struct TraitObjectDeclaredWithNoTraits { pub struct TraitObjectDeclaredWithNoTraits {
#[primary_span] #[primary_span]
@ -108,14 +108,14 @@ pub struct TraitObjectDeclaredWithNoTraits {
pub trait_alias_span: Option<Span>, pub trait_alias_span: Option<Span>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0227")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0227")]
pub struct AmbiguousLifetimeBound { pub struct AmbiguousLifetimeBound {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::assoc_type_binding_not_allowed, code = "E0229")] #[diag(typeck::assoc_type_binding_not_allowed, code = "E0229")]
pub struct AssocTypeBindingNotAllowed { pub struct AssocTypeBindingNotAllowed {
#[primary_span] #[primary_span]
@ -123,14 +123,14 @@ pub struct AssocTypeBindingNotAllowed {
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::functional_record_update_on_non_struct, code = "E0436")] #[diag(typeck::functional_record_update_on_non_struct, code = "E0436")]
pub struct FunctionalRecordUpdateOnNonStruct { pub struct FunctionalRecordUpdateOnNonStruct {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::typeof_reserved_keyword_used, code = "E0516")] #[diag(typeck::typeof_reserved_keyword_used, code = "E0516")]
pub struct TypeofReservedKeywordUsed<'tcx> { pub struct TypeofReservedKeywordUsed<'tcx> {
pub ty: Ty<'tcx>, pub ty: Ty<'tcx>,
@ -141,7 +141,7 @@ pub struct TypeofReservedKeywordUsed<'tcx> {
pub opt_sugg: Option<(Span, Applicability)>, pub opt_sugg: Option<(Span, Applicability)>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::return_stmt_outside_of_fn_body, code = "E0572")] #[diag(typeck::return_stmt_outside_of_fn_body, code = "E0572")]
pub struct ReturnStmtOutsideOfFnBody { pub struct ReturnStmtOutsideOfFnBody {
#[primary_span] #[primary_span]
@ -152,14 +152,14 @@ pub struct ReturnStmtOutsideOfFnBody {
pub encl_fn_span: Option<Span>, pub encl_fn_span: Option<Span>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::yield_expr_outside_of_generator, code = "E0627")] #[diag(typeck::yield_expr_outside_of_generator, code = "E0627")]
pub struct YieldExprOutsideOfGenerator { pub struct YieldExprOutsideOfGenerator {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::struct_expr_non_exhaustive, code = "E0639")] #[diag(typeck::struct_expr_non_exhaustive, code = "E0639")]
pub struct StructExprNonExhaustive { pub struct StructExprNonExhaustive {
#[primary_span] #[primary_span]
@ -167,14 +167,14 @@ pub struct StructExprNonExhaustive {
pub what: &'static str, pub what: &'static str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::method_call_on_unknown_type, code = "E0699")] #[diag(typeck::method_call_on_unknown_type, code = "E0699")]
pub struct MethodCallOnUnknownType { pub struct MethodCallOnUnknownType {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::value_of_associated_struct_already_specified, code = "E0719")] #[diag(typeck::value_of_associated_struct_already_specified, code = "E0719")]
pub struct ValueOfAssociatedStructAlreadySpecified { pub struct ValueOfAssociatedStructAlreadySpecified {
#[primary_span] #[primary_span]
@ -186,7 +186,7 @@ pub struct ValueOfAssociatedStructAlreadySpecified {
pub def_path: String, pub def_path: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::address_of_temporary_taken, code = "E0745")] #[diag(typeck::address_of_temporary_taken, code = "E0745")]
pub struct AddressOfTemporaryTaken { pub struct AddressOfTemporaryTaken {
#[primary_span] #[primary_span]
@ -194,7 +194,7 @@ pub struct AddressOfTemporaryTaken {
pub span: Span, pub span: Span,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub enum AddReturnTypeSuggestion { pub enum AddReturnTypeSuggestion {
#[suggestion( #[suggestion(
typeck::add_return_type_add, typeck::add_return_type_add,
@ -217,7 +217,7 @@ pub enum AddReturnTypeSuggestion {
}, },
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
pub enum ExpectedReturnTypeLabel<'tcx> { pub enum ExpectedReturnTypeLabel<'tcx> {
#[label(typeck::expected_default_return_type)] #[label(typeck::expected_default_return_type)]
Unit { Unit {
@ -232,7 +232,7 @@ pub enum ExpectedReturnTypeLabel<'tcx> {
}, },
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::unconstrained_opaque_type)] #[diag(typeck::unconstrained_opaque_type)]
#[note] #[note]
pub struct UnconstrainedOpaqueType { pub struct UnconstrainedOpaqueType {
@ -249,8 +249,8 @@ pub struct MissingTypeParams {
pub empty_generic_args: bool, pub empty_generic_args: bool,
} }
// Manual implementation of `SessionDiagnostic` to be able to call `span_to_snippet`. // Manual implementation of `IntoDiagnostic` to be able to call `span_to_snippet`.
impl<'a> SessionDiagnostic<'a> for MissingTypeParams { impl<'a> IntoDiagnostic<'a> for MissingTypeParams {
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> { fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
let mut err = handler.struct_span_err_with_code( let mut err = handler.struct_span_err_with_code(
self.span, self.span,
@ -306,7 +306,7 @@ impl<'a> SessionDiagnostic<'a> for MissingTypeParams {
} }
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::manual_implementation, code = "E0183")] #[diag(typeck::manual_implementation, code = "E0183")]
#[help] #[help]
pub struct ManualImplementation { pub struct ManualImplementation {
@ -316,7 +316,7 @@ pub struct ManualImplementation {
pub trait_name: String, pub trait_name: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::substs_on_overridden_impl)] #[diag(typeck::substs_on_overridden_impl)]
pub struct SubstsOnOverriddenImpl { pub struct SubstsOnOverriddenImpl {
#[primary_span] #[primary_span]
@ -339,7 +339,7 @@ pub struct ExternCrateNotIdiomatic {
pub suggestion_code: String, pub suggestion_code: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::expected_used_symbol)] #[diag(typeck::expected_used_symbol)]
pub struct ExpectedUsedSymbol { pub struct ExpectedUsedSymbol {
#[primary_span] #[primary_span]

View file

@ -12,55 +12,55 @@ extern crate rustc_session;
extern crate rustc_span; extern crate rustc_span;
use rustc_errors::{ use rustc_errors::{
AddSubdiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, fluent AddToDiagnostic, IntoDiagnostic, Diagnostic, DiagnosticBuilder,
ErrorGuaranteed, Handler, fluent
}; };
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic}; use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_session::SessionDiagnostic;
use rustc_span::Span; use rustc_span::Span;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(parser::expect_path)] #[diag(parser::expect_path)]
struct DeriveSessionDiagnostic { struct DeriveDiagnostic {
#[primary_span] #[primary_span]
span: Span, span: Span,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[note(parser::add_paren)] #[note(parser::add_paren)]
struct Note { struct Note {
#[primary_span] #[primary_span]
span: Span, span: Span,
} }
pub struct UntranslatableInSessionDiagnostic; pub struct UntranslatableInIntoDiagnostic;
impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for UntranslatableInSessionDiagnostic { impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for UntranslatableInIntoDiagnostic {
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> { fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
handler.struct_err("untranslatable diagnostic") handler.struct_err("untranslatable diagnostic")
//~^ ERROR diagnostics should be created using translatable messages //~^ ERROR diagnostics should be created using translatable messages
} }
} }
pub struct TranslatableInSessionDiagnostic; pub struct TranslatableInIntoDiagnostic;
impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for TranslatableInSessionDiagnostic { impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for TranslatableInIntoDiagnostic {
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> { fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
handler.struct_err(fluent::parser::expect_path) handler.struct_err(fluent::parser::expect_path)
} }
} }
pub struct UntranslatableInAddSubdiagnostic; pub struct UntranslatableInAddToDiagnostic;
impl AddSubdiagnostic for UntranslatableInAddSubdiagnostic { impl AddToDiagnostic for UntranslatableInAddToDiagnostic {
fn add_to_diagnostic(self, diag: &mut Diagnostic) { fn add_to_diagnostic(self, diag: &mut Diagnostic) {
diag.note("untranslatable diagnostic"); diag.note("untranslatable diagnostic");
//~^ ERROR diagnostics should be created using translatable messages //~^ ERROR diagnostics should be created using translatable messages
} }
} }
pub struct TranslatableInAddSubdiagnostic; pub struct TranslatableInAddToDiagnostic;
impl AddSubdiagnostic for TranslatableInAddSubdiagnostic { impl AddToDiagnostic for TranslatableInAddToDiagnostic {
fn add_to_diagnostic(self, diag: &mut Diagnostic) { fn add_to_diagnostic(self, diag: &mut Diagnostic) {
diag.note(fluent::typeck::note); diag.note(fluent::typeck::note);
} }
@ -68,10 +68,10 @@ impl AddSubdiagnostic for TranslatableInAddSubdiagnostic {
pub fn make_diagnostics<'a>(handler: &'a Handler) { pub fn make_diagnostics<'a>(handler: &'a Handler) {
let _diag = handler.struct_err(fluent::parser::expect_path); let _diag = handler.struct_err(fluent::parser::expect_path);
//~^ ERROR diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls //~^ ERROR diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls
let _diag = handler.struct_err("untranslatable diagnostic"); let _diag = handler.struct_err("untranslatable diagnostic");
//~^ ERROR diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls //~^ ERROR diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls
//~^^ ERROR diagnostics should be created using translatable messages //~^^ ERROR diagnostics should be created using translatable messages
} }

View file

@ -16,7 +16,7 @@ error: diagnostics should be created using translatable messages
LL | diag.note("untranslatable diagnostic"); LL | diag.note("untranslatable diagnostic");
| ^^^^ | ^^^^
error: diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls error: diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls
--> $DIR/diagnostics.rs:70:25 --> $DIR/diagnostics.rs:70:25
| |
LL | let _diag = handler.struct_err(fluent::parser::expect_path); LL | let _diag = handler.struct_err(fluent::parser::expect_path);
@ -28,7 +28,7 @@ note: the lint level is defined here
LL | #![deny(rustc::diagnostic_outside_of_impl)] LL | #![deny(rustc::diagnostic_outside_of_impl)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls error: diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls
--> $DIR/diagnostics.rs:73:25 --> $DIR/diagnostics.rs:73:25
| |
LL | let _diag = handler.struct_err("untranslatable diagnostic"); LL | let _diag = handler.struct_err("untranslatable diagnostic");

View file

@ -1,10 +1,10 @@
// check-fail // check-fail
// Tests error conditions for specifying diagnostics using #[derive(SessionDiagnostic)] // Tests error conditions for specifying diagnostics using #[derive(Diagnostic)]
// normalize-stderr-test "the following other types implement trait `IntoDiagnosticArg`:(?:.*\n){0,9}\s+and \d+ others" -> "normalized in stderr" // normalize-stderr-test "the following other types implement trait `IntoDiagnosticArg`:(?:.*\n){0,9}\s+and \d+ others" -> "normalized in stderr"
// normalize-stderr-test "diagnostic_builder\.rs:[0-9]+:[0-9]+" -> "diagnostic_builder.rs:LL:CC" // normalize-stderr-test "diagnostic_builder\.rs:[0-9]+:[0-9]+" -> "diagnostic_builder.rs:LL:CC"
// The proc_macro2 crate handles spans differently when on beta/stable release rather than nightly, // The proc_macro2 crate handles spans differently when on beta/stable release rather than nightly,
// changing the output of this test. Since SessionDiagnostic is strictly internal to the compiler // changing the output of this test. Since Diagnostic is strictly internal to the compiler
// the test is just ignored on stable and beta: // the test is just ignored on stable and beta:
// ignore-beta // ignore-beta
// ignore-stable // ignore-stable
@ -17,7 +17,7 @@ use rustc_span::symbol::Ident;
use rustc_span::Span; use rustc_span::Span;
extern crate rustc_macros; extern crate rustc_macros;
use rustc_macros::{SessionDiagnostic, LintDiagnostic, SessionSubdiagnostic}; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
extern crate rustc_middle; extern crate rustc_middle;
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;
@ -27,70 +27,70 @@ use rustc_errors::{Applicability, MultiSpan};
extern crate rustc_session; extern crate rustc_session;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct Hello {} struct Hello {}
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct HelloWarn {} struct HelloWarn {}
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
//~^ ERROR `#[derive(SessionDiagnostic)]` can only be used on structs //~^ ERROR `#[derive(Diagnostic)]` can only be used on structs
enum SessionDiagnosticOnEnum { enum DiagnosticOnEnum {
Foo, Foo,
Bar, Bar,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
#[diag = "E0123"] #[diag = "E0123"]
//~^ ERROR `#[diag = ...]` is not a valid attribute //~^ ERROR `#[diag = ...]` is not a valid attribute
struct WrongStructAttrStyle {} struct WrongStructAttrStyle {}
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[nonsense(typeck::ambiguous_lifetime_bound, code = "E0123")] #[nonsense(typeck::ambiguous_lifetime_bound, code = "E0123")]
//~^ ERROR `#[nonsense(...)]` is not a valid attribute //~^ ERROR `#[nonsense(...)]` is not a valid attribute
//~^^ ERROR diagnostic slug not specified //~^^ ERROR diagnostic slug not specified
//~^^^ ERROR cannot find attribute `nonsense` in this scope //~^^^ ERROR cannot find attribute `nonsense` in this scope
struct InvalidStructAttr {} struct InvalidStructAttr {}
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag("E0123")] #[diag("E0123")]
//~^ ERROR `#[diag("...")]` is not a valid attribute //~^ ERROR `#[diag("...")]` is not a valid attribute
//~^^ ERROR diagnostic slug not specified //~^^ ERROR diagnostic slug not specified
struct InvalidLitNestedAttr {} struct InvalidLitNestedAttr {}
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(nonsense, code = "E0123")] #[diag(nonsense, code = "E0123")]
//~^ ERROR cannot find value `nonsense` in module `rustc_errors::fluent` //~^ ERROR cannot find value `nonsense` in module `rustc_errors::fluent`
struct InvalidNestedStructAttr {} struct InvalidNestedStructAttr {}
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(nonsense("foo"), code = "E0123", slug = "foo")] #[diag(nonsense("foo"), code = "E0123", slug = "foo")]
//~^ ERROR `#[diag(nonsense(...))]` is not a valid attribute //~^ ERROR `#[diag(nonsense(...))]` is not a valid attribute
//~^^ ERROR diagnostic slug not specified //~^^ ERROR diagnostic slug not specified
struct InvalidNestedStructAttr1 {} struct InvalidNestedStructAttr1 {}
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(nonsense = "...", code = "E0123", slug = "foo")] #[diag(nonsense = "...", code = "E0123", slug = "foo")]
//~^ ERROR `#[diag(nonsense = ...)]` is not a valid attribute //~^ ERROR `#[diag(nonsense = ...)]` is not a valid attribute
//~^^ ERROR diagnostic slug not specified //~^^ ERROR diagnostic slug not specified
struct InvalidNestedStructAttr2 {} struct InvalidNestedStructAttr2 {}
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(nonsense = 4, code = "E0123", slug = "foo")] #[diag(nonsense = 4, code = "E0123", slug = "foo")]
//~^ ERROR `#[diag(nonsense = ...)]` is not a valid attribute //~^ ERROR `#[diag(nonsense = ...)]` is not a valid attribute
//~^^ ERROR diagnostic slug not specified //~^^ ERROR diagnostic slug not specified
struct InvalidNestedStructAttr3 {} struct InvalidNestedStructAttr3 {}
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123", slug = "foo")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123", slug = "foo")]
//~^ ERROR `#[diag(slug = ...)]` is not a valid attribute //~^ ERROR `#[diag(slug = ...)]` is not a valid attribute
struct InvalidNestedStructAttr4 {} struct InvalidNestedStructAttr4 {}
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct WrongPlaceField { struct WrongPlaceField {
#[suggestion = "bar"] #[suggestion = "bar"]
@ -98,36 +98,36 @@ struct WrongPlaceField {
sp: Span, sp: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0456")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0456")]
//~^ ERROR specified multiple times //~^ ERROR specified multiple times
//~^^ ERROR specified multiple times //~^^ ERROR specified multiple times
struct DiagSpecifiedTwice {} struct DiagSpecifiedTwice {}
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0456", code = "E0457")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0456", code = "E0457")]
//~^ ERROR specified multiple times //~^ ERROR specified multiple times
struct CodeSpecifiedTwice {} struct CodeSpecifiedTwice {}
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, typeck::ambiguous_lifetime_bound, code = "E0456")] #[diag(typeck::ambiguous_lifetime_bound, typeck::ambiguous_lifetime_bound, code = "E0456")]
//~^ ERROR `#[diag(typeck::ambiguous_lifetime_bound)]` is not a valid attribute //~^ ERROR `#[diag(typeck::ambiguous_lifetime_bound)]` is not a valid attribute
struct SlugSpecifiedTwice {} struct SlugSpecifiedTwice {}
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
struct KindNotProvided {} //~ ERROR diagnostic slug not specified struct KindNotProvided {} //~ ERROR diagnostic slug not specified
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(code = "E0456")] #[diag(code = "E0456")]
//~^ ERROR diagnostic slug not specified //~^ ERROR diagnostic slug not specified
struct SlugNotProvided {} struct SlugNotProvided {}
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound)] #[diag(typeck::ambiguous_lifetime_bound)]
struct CodeNotProvided {} struct CodeNotProvided {}
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct MessageWrongType { struct MessageWrongType {
#[primary_span] #[primary_span]
@ -135,7 +135,7 @@ struct MessageWrongType {
foo: String, foo: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct InvalidPathFieldAttr { struct InvalidPathFieldAttr {
#[nonsense] #[nonsense]
@ -144,7 +144,7 @@ struct InvalidPathFieldAttr {
foo: String, foo: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct ErrorWithField { struct ErrorWithField {
name: String, name: String,
@ -152,7 +152,7 @@ struct ErrorWithField {
span: Span, span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct ErrorWithMessageAppliedToField { struct ErrorWithMessageAppliedToField {
#[label(typeck::label)] #[label(typeck::label)]
@ -160,7 +160,7 @@ struct ErrorWithMessageAppliedToField {
name: String, name: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct ErrorWithNonexistentField { struct ErrorWithNonexistentField {
#[suggestion(typeck::suggestion, code = "{name}")] #[suggestion(typeck::suggestion, code = "{name}")]
@ -168,7 +168,7 @@ struct ErrorWithNonexistentField {
suggestion: (Span, Applicability), suggestion: (Span, Applicability),
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
//~^ ERROR invalid format string: expected `'}'` //~^ ERROR invalid format string: expected `'}'`
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct ErrorMissingClosingBrace { struct ErrorMissingClosingBrace {
@ -178,7 +178,7 @@ struct ErrorMissingClosingBrace {
val: usize, val: usize,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
//~^ ERROR invalid format string: unmatched `}` //~^ ERROR invalid format string: unmatched `}`
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct ErrorMissingOpeningBrace { struct ErrorMissingOpeningBrace {
@ -188,14 +188,14 @@ struct ErrorMissingOpeningBrace {
val: usize, val: usize,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct LabelOnSpan { struct LabelOnSpan {
#[label(typeck::label)] #[label(typeck::label)]
sp: Span, sp: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct LabelOnNonSpan { struct LabelOnNonSpan {
#[label(typeck::label)] #[label(typeck::label)]
@ -203,7 +203,7 @@ struct LabelOnNonSpan {
id: u32, id: u32,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct Suggest { struct Suggest {
#[suggestion(typeck::suggestion, code = "This is the suggested code")] #[suggestion(typeck::suggestion, code = "This is the suggested code")]
@ -213,14 +213,14 @@ struct Suggest {
suggestion: (Span, Applicability), suggestion: (Span, Applicability),
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct SuggestWithoutCode { struct SuggestWithoutCode {
#[suggestion(typeck::suggestion)] #[suggestion(typeck::suggestion)]
suggestion: (Span, Applicability), suggestion: (Span, Applicability),
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct SuggestWithBadKey { struct SuggestWithBadKey {
#[suggestion(nonsense = "bar")] #[suggestion(nonsense = "bar")]
@ -228,7 +228,7 @@ struct SuggestWithBadKey {
suggestion: (Span, Applicability), suggestion: (Span, Applicability),
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct SuggestWithShorthandMsg { struct SuggestWithShorthandMsg {
#[suggestion(msg = "bar")] #[suggestion(msg = "bar")]
@ -236,21 +236,21 @@ struct SuggestWithShorthandMsg {
suggestion: (Span, Applicability), suggestion: (Span, Applicability),
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct SuggestWithoutMsg { struct SuggestWithoutMsg {
#[suggestion(code = "bar")] #[suggestion(code = "bar")]
suggestion: (Span, Applicability), suggestion: (Span, Applicability),
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct SuggestWithTypesSwapped { struct SuggestWithTypesSwapped {
#[suggestion(typeck::suggestion, code = "This is suggested code")] #[suggestion(typeck::suggestion, code = "This is suggested code")]
suggestion: (Applicability, Span), suggestion: (Applicability, Span),
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct SuggestWithWrongTypeApplicabilityOnly { struct SuggestWithWrongTypeApplicabilityOnly {
#[suggestion(typeck::suggestion, code = "This is suggested code")] #[suggestion(typeck::suggestion, code = "This is suggested code")]
@ -258,14 +258,14 @@ struct SuggestWithWrongTypeApplicabilityOnly {
suggestion: Applicability, suggestion: Applicability,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct SuggestWithSpanOnly { struct SuggestWithSpanOnly {
#[suggestion(typeck::suggestion, code = "This is suggested code")] #[suggestion(typeck::suggestion, code = "This is suggested code")]
suggestion: Span, suggestion: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct SuggestWithDuplicateSpanAndApplicability { struct SuggestWithDuplicateSpanAndApplicability {
#[suggestion(typeck::suggestion, code = "This is suggested code")] #[suggestion(typeck::suggestion, code = "This is suggested code")]
@ -273,7 +273,7 @@ struct SuggestWithDuplicateSpanAndApplicability {
suggestion: (Span, Span, Applicability), suggestion: (Span, Span, Applicability),
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct SuggestWithDuplicateApplicabilityAndSpan { struct SuggestWithDuplicateApplicabilityAndSpan {
#[suggestion(typeck::suggestion, code = "This is suggested code")] #[suggestion(typeck::suggestion, code = "This is suggested code")]
@ -281,7 +281,7 @@ struct SuggestWithDuplicateApplicabilityAndSpan {
suggestion: (Applicability, Applicability, Span), suggestion: (Applicability, Applicability, Span),
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct WrongKindOfAnnotation { struct WrongKindOfAnnotation {
#[label = "bar"] #[label = "bar"]
@ -289,7 +289,7 @@ struct WrongKindOfAnnotation {
z: Span, z: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct OptionsInErrors { struct OptionsInErrors {
#[label(typeck::label)] #[label(typeck::label)]
@ -298,7 +298,7 @@ struct OptionsInErrors {
opt_sugg: Option<(Span, Applicability)>, opt_sugg: Option<(Span, Applicability)>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0456")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0456")]
struct MoveOutOfBorrowError<'tcx> { struct MoveOutOfBorrowError<'tcx> {
name: Ident, name: Ident,
@ -312,7 +312,7 @@ struct MoveOutOfBorrowError<'tcx> {
opt_sugg: Option<(Span, Applicability)>, opt_sugg: Option<(Span, Applicability)>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct ErrorWithLifetime<'a> { struct ErrorWithLifetime<'a> {
#[label(typeck::label)] #[label(typeck::label)]
@ -320,7 +320,7 @@ struct ErrorWithLifetime<'a> {
name: &'a str, name: &'a str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct ErrorWithDefaultLabelAttr<'a> { struct ErrorWithDefaultLabelAttr<'a> {
#[label] #[label]
@ -328,7 +328,7 @@ struct ErrorWithDefaultLabelAttr<'a> {
name: &'a str, name: &'a str,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
//~^ ERROR the trait bound `Hello: IntoDiagnosticArg` is not satisfied //~^ ERROR the trait bound `Hello: IntoDiagnosticArg` is not satisfied
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct ArgFieldWithoutSkip { struct ArgFieldWithoutSkip {
@ -337,7 +337,7 @@ struct ArgFieldWithoutSkip {
other: Hello, other: Hello,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct ArgFieldWithSkip { struct ArgFieldWithSkip {
#[primary_span] #[primary_span]
@ -348,91 +348,91 @@ struct ArgFieldWithSkip {
other: Hello, other: Hello,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct ErrorWithSpannedNote { struct ErrorWithSpannedNote {
#[note] #[note]
span: Span, span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct ErrorWithSpannedNoteCustom { struct ErrorWithSpannedNoteCustom {
#[note(typeck::note)] #[note(typeck::note)]
span: Span, span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
#[note] #[note]
struct ErrorWithNote { struct ErrorWithNote {
val: String, val: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
#[note(typeck::note)] #[note(typeck::note)]
struct ErrorWithNoteCustom { struct ErrorWithNoteCustom {
val: String, val: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct ErrorWithSpannedHelp { struct ErrorWithSpannedHelp {
#[help] #[help]
span: Span, span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct ErrorWithSpannedHelpCustom { struct ErrorWithSpannedHelpCustom {
#[help(typeck::help)] #[help(typeck::help)]
span: Span, span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
#[help] #[help]
struct ErrorWithHelp { struct ErrorWithHelp {
val: String, val: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
#[help(typeck::help)] #[help(typeck::help)]
struct ErrorWithHelpCustom { struct ErrorWithHelpCustom {
val: String, val: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[help] #[help]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct ErrorWithHelpWrongOrder { struct ErrorWithHelpWrongOrder {
val: String, val: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[help(typeck::help)] #[help(typeck::help)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct ErrorWithHelpCustomWrongOrder { struct ErrorWithHelpCustomWrongOrder {
val: String, val: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[note] #[note]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct ErrorWithNoteWrongOrder { struct ErrorWithNoteWrongOrder {
val: String, val: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[note(typeck::note)] #[note(typeck::note)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct ErrorWithNoteCustomWrongOrder { struct ErrorWithNoteCustomWrongOrder {
val: String, val: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct ApplicabilityInBoth { struct ApplicabilityInBoth {
#[suggestion(typeck::suggestion, code = "...", applicability = "maybe-incorrect")] #[suggestion(typeck::suggestion, code = "...", applicability = "maybe-incorrect")]
@ -440,7 +440,7 @@ struct ApplicabilityInBoth {
suggestion: (Span, Applicability), suggestion: (Span, Applicability),
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct InvalidApplicability { struct InvalidApplicability {
#[suggestion(typeck::suggestion, code = "...", applicability = "batman")] #[suggestion(typeck::suggestion, code = "...", applicability = "batman")]
@ -448,32 +448,32 @@ struct InvalidApplicability {
suggestion: Span, suggestion: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct ValidApplicability { struct ValidApplicability {
#[suggestion(typeck::suggestion, code = "...", applicability = "maybe-incorrect")] #[suggestion(typeck::suggestion, code = "...", applicability = "maybe-incorrect")]
suggestion: Span, suggestion: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct NoApplicability { struct NoApplicability {
#[suggestion(typeck::suggestion, code = "...")] #[suggestion(typeck::suggestion, code = "...")]
suggestion: Span, suggestion: Span,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[note(parser::add_paren)] #[note(parser::add_paren)]
struct Note; struct Note;
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound)] #[diag(typeck::ambiguous_lifetime_bound)]
struct Subdiagnostic { struct Subdiagnostic {
#[subdiagnostic] #[subdiagnostic]
note: Note, note: Note,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct VecField { struct VecField {
#[primary_span] #[primary_span]
@ -481,7 +481,7 @@ struct VecField {
spans: Vec<Span>, spans: Vec<Span>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct UnitField { struct UnitField {
#[primary_span] #[primary_span]
@ -492,7 +492,7 @@ struct UnitField {
bar: (), bar: (),
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct OptUnitField { struct OptUnitField {
#[primary_span] #[primary_span]
@ -503,7 +503,7 @@ struct OptUnitField {
bar: Option<()>, bar: Option<()>,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct LabelWithTrailingPath { struct LabelWithTrailingPath {
#[label(typeck::label, foo)] #[label(typeck::label, foo)]
@ -511,7 +511,7 @@ struct LabelWithTrailingPath {
span: Span, span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct LabelWithTrailingNameValue { struct LabelWithTrailingNameValue {
#[label(typeck::label, foo = "...")] #[label(typeck::label, foo = "...")]
@ -519,7 +519,7 @@ struct LabelWithTrailingNameValue {
span: Span, span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct LabelWithTrailingList { struct LabelWithTrailingList {
#[label(typeck::label, foo("..."))] #[label(typeck::label, foo("..."))]
@ -540,35 +540,35 @@ struct PrimarySpanOnLint {
span: Span, span: Span,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
struct ErrorWithMultiSpan { struct ErrorWithMultiSpan {
#[primary_span] #[primary_span]
span: MultiSpan, span: MultiSpan,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
#[warning] #[warning]
struct ErrorWithWarn { struct ErrorWithWarn {
val: String, val: String,
} }
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[error(typeck::ambiguous_lifetime_bound, code = "E0123")] #[error(typeck::ambiguous_lifetime_bound, code = "E0123")]
//~^ ERROR `#[error(...)]` is not a valid attribute //~^ ERROR `#[error(...)]` is not a valid attribute
//~| ERROR diagnostic slug not specified //~| ERROR diagnostic slug not specified
//~| ERROR cannot find attribute `error` in this scope //~| ERROR cannot find attribute `error` in this scope
struct ErrorAttribute {} struct ErrorAttribute {}
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[warn_(typeck::ambiguous_lifetime_bound, code = "E0123")] #[warn_(typeck::ambiguous_lifetime_bound, code = "E0123")]
//~^ ERROR `#[warn_(...)]` is not a valid attribute //~^ ERROR `#[warn_(...)]` is not a valid attribute
//~| ERROR diagnostic slug not specified //~| ERROR diagnostic slug not specified
//~| ERROR cannot find attribute `warn_` in this scope //~| ERROR cannot find attribute `warn_` in this scope
struct WarnAttribute {} struct WarnAttribute {}
#[derive(SessionDiagnostic)] #[derive(Diagnostic)]
#[lint(typeck::ambiguous_lifetime_bound, code = "E0123")] #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")]
//~^ ERROR `#[lint(...)]` is not a valid attribute //~^ ERROR `#[lint(...)]` is not a valid attribute
//~| ERROR diagnostic slug not specified //~| ERROR diagnostic slug not specified

View file

@ -1,9 +1,9 @@
error: `#[derive(SessionDiagnostic)]` can only be used on structs error: `#[derive(Diagnostic)]` can only be used on structs
--> $DIR/diagnostic-derive.rs:39:1 --> $DIR/diagnostic-derive.rs:39:1
| |
LL | / #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] LL | / #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
LL | | LL | |
LL | | enum SessionDiagnosticOnEnum { LL | | enum DiagnosticOnEnum {
LL | | Foo, LL | | Foo,
LL | | Bar, LL | | Bar,
LL | | } LL | | }
@ -214,22 +214,22 @@ LL | #[suggestion(typeck::suggestion, code = "{name}")]
error: invalid format string: expected `'}'` but string was terminated error: invalid format string: expected `'}'` but string was terminated
--> $DIR/diagnostic-derive.rs:171:16 --> $DIR/diagnostic-derive.rs:171:16
| |
LL | #[derive(SessionDiagnostic)] LL | #[derive(Diagnostic)]
| - ^ expected `'}'` in format string | - ^ expected `'}'` in format string
| | | |
| because of this opening brace | because of this opening brace
| |
= note: if you intended to print `{`, you can escape it using `{{` = note: if you intended to print `{`, you can escape it using `{{`
= note: this error originates in the derive macro `SessionDiagnostic` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)
error: invalid format string: unmatched `}` found error: invalid format string: unmatched `}` found
--> $DIR/diagnostic-derive.rs:181:15 --> $DIR/diagnostic-derive.rs:181:15
| |
LL | #[derive(SessionDiagnostic)] LL | #[derive(Diagnostic)]
| ^ unmatched `}` in format string | ^ unmatched `}` in format string
| |
= note: if you intended to print `}`, you can escape it using `}}` = note: if you intended to print `}`, you can escape it using `}}`
= note: this error originates in the derive macro `SessionDiagnostic` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)
error: the `#[label(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan` error: the `#[label(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan`
--> $DIR/diagnostic-derive.rs:201:5 --> $DIR/diagnostic-derive.rs:201:5
@ -448,8 +448,8 @@ LL | #[diag(nonsense, code = "E0123")]
error[E0277]: the trait bound `Hello: IntoDiagnosticArg` is not satisfied error[E0277]: the trait bound `Hello: IntoDiagnosticArg` is not satisfied
--> $DIR/diagnostic-derive.rs:331:10 --> $DIR/diagnostic-derive.rs:331:10
| |
LL | #[derive(SessionDiagnostic)] LL | #[derive(Diagnostic)]
| ^^^^^^^^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `Hello` | ^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `Hello`
| |
= help: normalized in stderr = help: normalized in stderr
note: required by a bound in `DiagnosticBuilder::<'a, G>::set_arg` note: required by a bound in `DiagnosticBuilder::<'a, G>::set_arg`
@ -457,7 +457,7 @@ note: required by a bound in `DiagnosticBuilder::<'a, G>::set_arg`
| |
LL | arg: impl IntoDiagnosticArg, LL | arg: impl IntoDiagnosticArg,
| ^^^^^^^^^^^^^^^^^ required by this bound in `DiagnosticBuilder::<'a, G>::set_arg` | ^^^^^^^^^^^^^^^^^ required by this bound in `DiagnosticBuilder::<'a, G>::set_arg`
= note: this error originates in the derive macro `SessionDiagnostic` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 55 previous errors error: aborting due to 55 previous errors

View file

@ -1,8 +1,8 @@
// check-fail // check-fail
// Tests error conditions for specifying subdiagnostics using #[derive(SessionSubdiagnostic)] // Tests error conditions for specifying subdiagnostics using #[derive(Subdiagnostic)]
// The proc_macro2 crate handles spans differently when on beta/stable release rather than nightly, // The proc_macro2 crate handles spans differently when on beta/stable release rather than nightly,
// changing the output of this test. Since SessionSubdiagnostic is strictly internal to the compiler // changing the output of this test. Since Subdiagnostic is strictly internal to the compiler
// the test is just ignored on stable and beta: // the test is just ignored on stable and beta:
// ignore-beta // ignore-beta
// ignore-stable // ignore-stable
@ -17,9 +17,9 @@ extern crate rustc_macros;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_span::Span; use rustc_span::Span;
use rustc_macros::SessionSubdiagnostic; use rustc_macros::Subdiagnostic;
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[label(parser::add_paren)] #[label(parser::add_paren)]
struct A { struct A {
#[primary_span] #[primary_span]
@ -27,7 +27,7 @@ struct A {
var: String, var: String,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
enum B { enum B {
#[label(parser::add_paren)] #[label(parser::add_paren)]
A { A {
@ -43,14 +43,14 @@ enum B {
} }
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[label(parser::add_paren)] #[label(parser::add_paren)]
//~^ ERROR label without `#[primary_span]` field //~^ ERROR label without `#[primary_span]` field
struct C { struct C {
var: String, var: String,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[label] #[label]
//~^ ERROR `#[label]` is not a valid attribute //~^ ERROR `#[label]` is not a valid attribute
struct D { struct D {
@ -59,7 +59,7 @@ struct D {
var: String, var: String,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[foo] #[foo]
//~^ ERROR `#[foo]` is not a valid attribute //~^ ERROR `#[foo]` is not a valid attribute
//~^^ ERROR cannot find attribute `foo` in this scope //~^^ ERROR cannot find attribute `foo` in this scope
@ -69,7 +69,7 @@ struct E {
var: String, var: String,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[label = "..."] #[label = "..."]
//~^ ERROR `#[label = ...]` is not a valid attribute //~^ ERROR `#[label = ...]` is not a valid attribute
struct F { struct F {
@ -78,7 +78,7 @@ struct F {
var: String, var: String,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[label(bug = "...")] #[label(bug = "...")]
//~^ ERROR `#[label(bug = ...)]` is not a valid attribute //~^ ERROR `#[label(bug = ...)]` is not a valid attribute
struct G { struct G {
@ -87,7 +87,7 @@ struct G {
var: String, var: String,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[label("...")] #[label("...")]
//~^ ERROR `#[label("...")]` is not a valid attribute //~^ ERROR `#[label("...")]` is not a valid attribute
struct H { struct H {
@ -96,7 +96,7 @@ struct H {
var: String, var: String,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[label(slug = 4)] #[label(slug = 4)]
//~^ ERROR `#[label(slug = ...)]` is not a valid attribute //~^ ERROR `#[label(slug = ...)]` is not a valid attribute
struct J { struct J {
@ -105,7 +105,7 @@ struct J {
var: String, var: String,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[label(slug("..."))] #[label(slug("..."))]
//~^ ERROR `#[label(slug(...))]` is not a valid attribute //~^ ERROR `#[label(slug(...))]` is not a valid attribute
struct K { struct K {
@ -114,7 +114,7 @@ struct K {
var: String, var: String,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[label(slug)] #[label(slug)]
//~^ ERROR cannot find value `slug` in module `rustc_errors::fluent` //~^ ERROR cannot find value `slug` in module `rustc_errors::fluent`
//~^^ NOTE not found in `rustc_errors::fluent` //~^^ NOTE not found in `rustc_errors::fluent`
@ -124,7 +124,7 @@ struct L {
var: String, var: String,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[label()] #[label()]
//~^ ERROR diagnostic slug must be first argument of a `#[label(...)]` attribute //~^ ERROR diagnostic slug must be first argument of a `#[label(...)]` attribute
struct M { struct M {
@ -133,7 +133,7 @@ struct M {
var: String, var: String,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[label(parser::add_paren, code = "...")] #[label(parser::add_paren, code = "...")]
//~^ ERROR `code` is not a valid nested attribute of a `label` attribute //~^ ERROR `code` is not a valid nested attribute of a `label` attribute
struct N { struct N {
@ -142,7 +142,7 @@ struct N {
var: String, var: String,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[label(parser::add_paren, applicability = "machine-applicable")] #[label(parser::add_paren, applicability = "machine-applicable")]
//~^ ERROR `applicability` is not a valid nested attribute of a `label` attribute //~^ ERROR `applicability` is not a valid nested attribute of a `label` attribute
struct O { struct O {
@ -151,7 +151,7 @@ struct O {
var: String, var: String,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[foo] #[foo]
//~^ ERROR cannot find attribute `foo` in this scope //~^ ERROR cannot find attribute `foo` in this scope
//~^^ ERROR unsupported type attribute for subdiagnostic enum //~^^ ERROR unsupported type attribute for subdiagnostic enum
@ -164,7 +164,7 @@ enum P {
} }
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
enum Q { enum Q {
#[bar] #[bar]
//~^ ERROR `#[bar]` is not a valid attribute //~^ ERROR `#[bar]` is not a valid attribute
@ -176,7 +176,7 @@ enum Q {
} }
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
enum R { enum R {
#[bar = "..."] #[bar = "..."]
//~^ ERROR `#[bar = ...]` is not a valid attribute //~^ ERROR `#[bar = ...]` is not a valid attribute
@ -188,7 +188,7 @@ enum R {
} }
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
enum S { enum S {
#[bar = 4] #[bar = 4]
//~^ ERROR `#[bar = ...]` is not a valid attribute //~^ ERROR `#[bar = ...]` is not a valid attribute
@ -200,7 +200,7 @@ enum S {
} }
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
enum T { enum T {
#[bar("...")] #[bar("...")]
//~^ ERROR `#[bar(...)]` is not a valid attribute //~^ ERROR `#[bar(...)]` is not a valid attribute
@ -212,7 +212,7 @@ enum T {
} }
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
enum U { enum U {
#[label(code = "...")] #[label(code = "...")]
//~^ ERROR diagnostic slug must be first argument of a `#[label(...)]` attribute //~^ ERROR diagnostic slug must be first argument of a `#[label(...)]` attribute
@ -223,7 +223,7 @@ enum U {
} }
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
enum V { enum V {
#[label(parser::add_paren)] #[label(parser::add_paren)]
A { A {
@ -239,7 +239,7 @@ enum V {
} }
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[label(parser::add_paren)] #[label(parser::add_paren)]
//~^ ERROR label without `#[primary_span]` field //~^ ERROR label without `#[primary_span]` field
struct W { struct W {
@ -248,7 +248,7 @@ struct W {
span: String, span: String,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[label(parser::add_paren)] #[label(parser::add_paren)]
struct X { struct X {
#[primary_span] #[primary_span]
@ -258,7 +258,7 @@ struct X {
applicability: Applicability, applicability: Applicability,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[label(parser::add_paren)] #[label(parser::add_paren)]
struct Y { struct Y {
#[primary_span] #[primary_span]
@ -269,7 +269,7 @@ struct Y {
bar: String, bar: String,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[label(parser::add_paren)] #[label(parser::add_paren)]
struct Z { struct Z {
#[primary_span] #[primary_span]
@ -280,7 +280,7 @@ struct Z {
bar: String, bar: String,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[label(parser::add_paren)] #[label(parser::add_paren)]
struct AA { struct AA {
#[primary_span] #[primary_span]
@ -291,7 +291,7 @@ struct AA {
bar: String, bar: String,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[label(parser::add_paren)] #[label(parser::add_paren)]
struct AB { struct AB {
#[primary_span] #[primary_span]
@ -300,14 +300,14 @@ struct AB {
z: Z z: Z
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
union AC { union AC {
//~^ ERROR unexpected unsupported untagged union //~^ ERROR unexpected unsupported untagged union
span: u32, span: u32,
b: u64 b: u64
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[label(parser::add_paren)] #[label(parser::add_paren)]
#[label(parser::add_paren)] #[label(parser::add_paren)]
struct AD { struct AD {
@ -315,7 +315,7 @@ struct AD {
span: Span, span: Span,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[label(parser::add_paren, parser::add_paren)] #[label(parser::add_paren, parser::add_paren)]
//~^ ERROR `#[label(parser::add_paren)]` is not a valid attribute //~^ ERROR `#[label(parser::add_paren)]` is not a valid attribute
struct AE { struct AE {
@ -323,7 +323,7 @@ struct AE {
span: Span, span: Span,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[label(parser::add_paren)] #[label(parser::add_paren)]
struct AF { struct AF {
#[primary_span] #[primary_span]
@ -334,14 +334,14 @@ struct AF {
span_b: Span, span_b: Span,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
struct AG { struct AG {
//~^ ERROR subdiagnostic kind not specified //~^ ERROR subdiagnostic kind not specified
#[primary_span] #[primary_span]
span: Span, span: Span,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[suggestion(parser::add_paren, code = "...")] #[suggestion(parser::add_paren, code = "...")]
struct AH { struct AH {
#[primary_span] #[primary_span]
@ -351,7 +351,7 @@ struct AH {
var: String, var: String,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
enum AI { enum AI {
#[suggestion(parser::add_paren, code = "...")] #[suggestion(parser::add_paren, code = "...")]
A { A {
@ -371,7 +371,7 @@ enum AI {
} }
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[suggestion(parser::add_paren, code = "...", code = "...")] #[suggestion(parser::add_paren, code = "...", code = "...")]
//~^ ERROR specified multiple times //~^ ERROR specified multiple times
//~^^ NOTE previously specified here //~^^ NOTE previously specified here
@ -382,7 +382,7 @@ struct AJ {
applicability: Applicability, applicability: Applicability,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[suggestion(parser::add_paren, code = "...")] #[suggestion(parser::add_paren, code = "...")]
struct AK { struct AK {
#[primary_span] #[primary_span]
@ -395,7 +395,7 @@ struct AK {
applicability_b: Applicability, applicability_b: Applicability,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[suggestion(parser::add_paren, code = "...")] #[suggestion(parser::add_paren, code = "...")]
struct AL { struct AL {
#[primary_span] #[primary_span]
@ -405,14 +405,14 @@ struct AL {
applicability: Span, applicability: Span,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[suggestion(parser::add_paren, code = "...")] #[suggestion(parser::add_paren, code = "...")]
struct AM { struct AM {
#[primary_span] #[primary_span]
span: Span, span: Span,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[suggestion(parser::add_paren)] #[suggestion(parser::add_paren)]
//~^ ERROR suggestion without `code = "..."` //~^ ERROR suggestion without `code = "..."`
struct AN { struct AN {
@ -422,7 +422,7 @@ struct AN {
applicability: Applicability, applicability: Applicability,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[suggestion(parser::add_paren, code ="...", applicability = "foo")] #[suggestion(parser::add_paren, code ="...", applicability = "foo")]
//~^ ERROR invalid applicability //~^ ERROR invalid applicability
struct AO { struct AO {
@ -430,31 +430,31 @@ struct AO {
span: Span, span: Span,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[help(parser::add_paren)] #[help(parser::add_paren)]
struct AP { struct AP {
var: String var: String
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[note(parser::add_paren)] #[note(parser::add_paren)]
struct AQ; struct AQ;
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[suggestion(parser::add_paren, code = "...")] #[suggestion(parser::add_paren, code = "...")]
//~^ ERROR suggestion without `#[primary_span]` field //~^ ERROR suggestion without `#[primary_span]` field
struct AR { struct AR {
var: String, var: String,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[suggestion(parser::add_paren, code ="...", applicability = "machine-applicable")] #[suggestion(parser::add_paren, code ="...", applicability = "machine-applicable")]
struct AS { struct AS {
#[primary_span] #[primary_span]
span: Span, span: Span,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[label] #[label]
//~^ ERROR unsupported type attribute for subdiagnostic enum //~^ ERROR unsupported type attribute for subdiagnostic enum
enum AT { enum AT {
@ -466,7 +466,7 @@ enum AT {
} }
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")] #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
struct AU { struct AU {
#[primary_span] #[primary_span]
@ -474,7 +474,7 @@ struct AU {
var: String, var: String,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")] #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
//~^ ERROR `var` doesn't refer to a field on this type //~^ ERROR `var` doesn't refer to a field on this type
struct AV { struct AV {
@ -482,7 +482,7 @@ struct AV {
span: Span, span: Span,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
enum AW { enum AW {
#[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")] #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
A { A {
@ -492,7 +492,7 @@ enum AW {
} }
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
enum AX { enum AX {
#[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")] #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
//~^ ERROR `var` doesn't refer to a field on this type //~^ ERROR `var` doesn't refer to a field on this type
@ -502,18 +502,18 @@ enum AX {
} }
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[warning(parser::add_paren)] #[warning(parser::add_paren)]
struct AY {} struct AY {}
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[warning(parser::add_paren)] #[warning(parser::add_paren)]
struct AZ { struct AZ {
#[primary_span] #[primary_span]
span: Span, span: Span,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[suggestion(parser::add_paren, code = "...")] #[suggestion(parser::add_paren, code = "...")]
//~^ ERROR suggestion without `#[primary_span]` field //~^ ERROR suggestion without `#[primary_span]` field
struct BA { struct BA {
@ -528,7 +528,7 @@ struct BA {
var: String, var: String,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[multipart_suggestion(parser::add_paren, code = "...", applicability = "machine-applicable")] #[multipart_suggestion(parser::add_paren, code = "...", applicability = "machine-applicable")]
//~^ ERROR multipart suggestion without any `#[suggestion_part(...)]` fields //~^ ERROR multipart suggestion without any `#[suggestion_part(...)]` fields
//~| ERROR `code` is not a valid nested attribute of a `multipart_suggestion` attribute //~| ERROR `code` is not a valid nested attribute of a `multipart_suggestion` attribute
@ -536,7 +536,7 @@ struct BBa {
var: String, var: String,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")] #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
struct BBb { struct BBb {
#[suggestion_part] #[suggestion_part]
@ -544,7 +544,7 @@ struct BBb {
span1: Span, span1: Span,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")] #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
struct BBc { struct BBc {
#[suggestion_part()] #[suggestion_part()]
@ -552,7 +552,7 @@ struct BBc {
span1: Span, span1: Span,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[multipart_suggestion(parser::add_paren)] #[multipart_suggestion(parser::add_paren)]
//~^ ERROR multipart suggestion without any `#[suggestion_part(...)]` fields //~^ ERROR multipart suggestion without any `#[suggestion_part(...)]` fields
struct BC { struct BC {
@ -561,7 +561,7 @@ struct BC {
span: Span, span: Span,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[multipart_suggestion(parser::add_paren)] #[multipart_suggestion(parser::add_paren)]
struct BD { struct BD {
#[suggestion_part] #[suggestion_part]
@ -581,7 +581,7 @@ struct BD {
s2: String, s2: String,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")] #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
struct BE { struct BE {
#[suggestion_part(code = "...", code = ",,,")] #[suggestion_part(code = "...", code = ",,,")]
@ -590,7 +590,7 @@ struct BE {
span: Span, span: Span,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")] #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
struct BF { struct BF {
#[suggestion_part(code = "(")] #[suggestion_part(code = "(")]
@ -599,7 +599,7 @@ struct BF {
second: Span, second: Span,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[multipart_suggestion(parser::add_paren)] #[multipart_suggestion(parser::add_paren)]
struct BG { struct BG {
#[applicability] #[applicability]
@ -610,7 +610,7 @@ struct BG {
second: Span, second: Span,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")] #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
//~^ NOTE previously specified here //~^ NOTE previously specified here
struct BH { struct BH {
@ -623,7 +623,7 @@ struct BH {
second: Span, second: Span,
} }
#[derive(SessionSubdiagnostic)] #[derive(Subdiagnostic)]
#[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")] #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
struct BI { struct BI {
#[suggestion_part(code = "")] #[suggestion_part(code = "")]