Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e52e234

Browse files
committedSep 21, 2022
FIX - adopt new Diagnostic naming in newly migrated modules
FIX - ambiguous Diagnostic link in docs UPDATE - rename diagnostic_items to IntoDiagnostic and AddToDiagnostic [Gardening] FIX - formatting via `x fmt` FIX - rebase conflicts. NOTE: Confirm wheather or not we want to handle TargetDataLayoutErrorsWrapper this way DELETE - unneeded allow attributes in Handler method FIX - broken test FIX - Rebase conflict UPDATE - rename residual _SessionDiagnostic and fix LintDiag link
1 parent 5f91719 commit e52e234

File tree

28 files changed

+88
-127
lines changed

28 files changed

+88
-127
lines changed
 

‎compiler/rustc_ast_lowering/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ pub struct InclusiveRangeWithNoEnd {
335335
pub span: Span,
336336
}
337337

338-
#[derive(SessionDiagnostic, Clone, Copy)]
338+
#[derive(Diagnostic, Clone, Copy)]
339339
#[diag(ast_lowering::trait_fn_async, code = "E0706")]
340340
#[note]
341341
#[note(ast_lowering::note2)]

‎compiler/rustc_attr/src/session_diagnostics.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use std::num::IntErrorKind;
22

33
use rustc_ast as ast;
44
use rustc_errors::{
5-
error_code, fluent, Applicability, DiagnosticBuilder, IntoDiagnostic, ErrorGuaranteed,
6-
Handler,
5+
error_code, fluent, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic,
76
};
87
use rustc_macros::Diagnostic;
98
use rustc_span::{Span, Symbol};

‎compiler/rustc_errors/src/diagnostic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl IntoDiagnosticArg for hir::ConstContext {
178178
/// Trait implemented by error types. This should not be implemented manually. Instead, use
179179
/// `#[derive(Subdiagnostic)]` -- see [rustc_macros::Subdiagnostic].
180180
#[cfg_attr(bootstrap, rustc_diagnostic_item = "AddSubdiagnostic")]
181-
#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "Subdiagnostic")]
181+
#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "AddToDiagnostic")]
182182
pub trait AddToDiagnostic {
183183
/// Add a subdiagnostic to an existing diagnostic.
184184
fn add_to_diagnostic(self, diag: &mut Diagnostic);

‎compiler/rustc_errors/src/diagnostic_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::thread::panicking;
1616
/// Trait implemented by error types. This should not be implemented manually. Instead, use
1717
/// `#[derive(Diagnostic)]` -- see [rustc_macros::Diagnostic].
1818
#[cfg_attr(bootstrap, rustc_diagnostic_item = "SessionDiagnostic")]
19-
#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "Diagnostic")]
19+
#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "IntoDiagnostic")]
2020
pub trait IntoDiagnostic<'a, T: EmissionGuarantee = ErrorGuaranteed> {
2121
/// Write out as a diagnostic out of `Handler`.
2222
#[must_use]

‎compiler/rustc_errors/src/lib.rs

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -437,11 +437,11 @@ struct HandlerInner {
437437
/// have been converted.
438438
check_unstable_expect_diagnostics: bool,
439439

440-
/// Expected [`Diagnostic`]s store a [`LintExpectationId`] as part of
440+
/// Expected [`Diagnostic`][diagnostic::Diagnostic]s store a [`LintExpectationId`] as part of
441441
/// the lint level. [`LintExpectationId`]s created early during the compilation
442442
/// (before `HirId`s have been defined) are not stable and can therefore not be
443443
/// stored on disk. This buffer stores these diagnostics until the ID has been
444-
/// replaced by a stable [`LintExpectationId`]. The [`Diagnostic`]s are the
444+
/// replaced by a stable [`LintExpectationId`]. The [`Diagnostic`][diagnostic::Diagnostic]s are the
445445
/// submitted for storage and added to the list of fulfilled expectations.
446446
unstable_expect_diagnostics: Vec<Diagnostic>,
447447

@@ -647,8 +647,6 @@ impl Handler {
647647

648648
/// Construct a builder with the `msg` at the level appropriate for the specific `EmissionGuarantee`.
649649
#[rustc_lint_diagnostics]
650-
#[allow(rustc::diagnostic_outside_of_impl)]
651-
#[allow(rustc::untranslatable_diagnostic)]
652650
pub fn struct_diagnostic<G: EmissionGuarantee>(
653651
&self,
654652
msg: impl Into<DiagnosticMessage>,
@@ -662,8 +660,6 @@ impl Handler {
662660
/// * `can_emit_warnings` is `true`
663661
/// * `is_force_warn` was set in `DiagnosticId::Lint`
664662
#[rustc_lint_diagnostics]
665-
#[allow(rustc::diagnostic_outside_of_impl)]
666-
#[allow(rustc::untranslatable_diagnostic)]
667663
pub fn struct_span_warn(
668664
&self,
669665
span: impl Into<MultiSpan>,
@@ -680,8 +676,6 @@ impl Handler {
680676
/// Attempting to `.emit()` the builder will only emit if either:
681677
/// * `can_emit_warnings` is `true`
682678
/// * `is_force_warn` was set in `DiagnosticId::Lint`
683-
#[allow(rustc::diagnostic_outside_of_impl)]
684-
#[allow(rustc::untranslatable_diagnostic)]
685679
pub fn struct_span_warn_with_expectation(
686680
&self,
687681
span: impl Into<MultiSpan>,
@@ -695,8 +689,6 @@ impl Handler {
695689

696690
/// Construct a builder at the `Allow` level at the given `span` and with the `msg`.
697691
#[rustc_lint_diagnostics]
698-
#[allow(rustc::diagnostic_outside_of_impl)]
699-
#[allow(rustc::untranslatable_diagnostic)]
700692
pub fn struct_span_allow(
701693
&self,
702694
span: impl Into<MultiSpan>,
@@ -710,8 +702,6 @@ impl Handler {
710702
/// Construct a builder at the `Warning` level at the given `span` and with the `msg`.
711703
/// Also include a code.
712704
#[rustc_lint_diagnostics]
713-
#[allow(rustc::diagnostic_outside_of_impl)]
714-
#[allow(rustc::untranslatable_diagnostic)]
715705
pub fn struct_span_warn_with_code(
716706
&self,
717707
span: impl Into<MultiSpan>,
@@ -729,8 +719,6 @@ impl Handler {
729719
/// * `can_emit_warnings` is `true`
730720
/// * `is_force_warn` was set in `DiagnosticId::Lint`
731721
#[rustc_lint_diagnostics]
732-
#[allow(rustc::diagnostic_outside_of_impl)]
733-
#[allow(rustc::untranslatable_diagnostic)]
734722
pub fn struct_warn(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
735723
DiagnosticBuilder::new(self, Level::Warning(None), msg)
736724
}
@@ -741,8 +729,6 @@ impl Handler {
741729
/// Attempting to `.emit()` the builder will only emit if either:
742730
/// * `can_emit_warnings` is `true`
743731
/// * `is_force_warn` was set in `DiagnosticId::Lint`
744-
#[allow(rustc::diagnostic_outside_of_impl)]
745-
#[allow(rustc::untranslatable_diagnostic)]
746732
pub fn struct_warn_with_expectation(
747733
&self,
748734
msg: impl Into<DiagnosticMessage>,
@@ -753,16 +739,12 @@ impl Handler {
753739

754740
/// Construct a builder at the `Allow` level with the `msg`.
755741
#[rustc_lint_diagnostics]
756-
#[allow(rustc::diagnostic_outside_of_impl)]
757-
#[allow(rustc::untranslatable_diagnostic)]
758742
pub fn struct_allow(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
759743
DiagnosticBuilder::new(self, Level::Allow, msg)
760744
}
761745

762746
/// Construct a builder at the `Expect` level with the `msg`.
763747
#[rustc_lint_diagnostics]
764-
#[allow(rustc::diagnostic_outside_of_impl)]
765-
#[allow(rustc::untranslatable_diagnostic)]
766748
pub fn struct_expect(
767749
&self,
768750
msg: impl Into<DiagnosticMessage>,
@@ -773,8 +755,6 @@ impl Handler {
773755

774756
/// Construct a builder at the `Error` level at the given `span` and with the `msg`.
775757
#[rustc_lint_diagnostics]
776-
#[allow(rustc::diagnostic_outside_of_impl)]
777-
#[allow(rustc::untranslatable_diagnostic)]
778758
pub fn struct_span_err(
779759
&self,
780760
span: impl Into<MultiSpan>,
@@ -787,8 +767,6 @@ impl Handler {
787767

788768
/// Construct a builder at the `Error` level at the given `span`, with the `msg`, and `code`.
789769
#[rustc_lint_diagnostics]
790-
#[allow(rustc::diagnostic_outside_of_impl)]
791-
#[allow(rustc::untranslatable_diagnostic)]
792770
pub fn struct_span_err_with_code(
793771
&self,
794772
span: impl Into<MultiSpan>,
@@ -803,8 +781,6 @@ impl Handler {
803781
/// Construct a builder at the `Error` level with the `msg`.
804782
// FIXME: This method should be removed (every error should have an associated error code).
805783
#[rustc_lint_diagnostics]
806-
#[allow(rustc::diagnostic_outside_of_impl)]
807-
#[allow(rustc::untranslatable_diagnostic)]
808784
pub fn struct_err(
809785
&self,
810786
msg: impl Into<DiagnosticMessage>,
@@ -814,16 +790,12 @@ impl Handler {
814790

815791
/// This should only be used by `rustc_middle::lint::struct_lint_level`. Do not use it for hard errors.
816792
#[doc(hidden)]
817-
#[allow(rustc::diagnostic_outside_of_impl)]
818-
#[allow(rustc::untranslatable_diagnostic)]
819793
pub fn struct_err_lint(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
820794
DiagnosticBuilder::new(self, Level::Error { lint: true }, msg)
821795
}
822796

823797
/// Construct a builder at the `Error` level with the `msg` and the `code`.
824798
#[rustc_lint_diagnostics]
825-
#[allow(rustc::diagnostic_outside_of_impl)]
826-
#[allow(rustc::untranslatable_diagnostic)]
827799
pub fn struct_err_with_code(
828800
&self,
829801
msg: impl Into<DiagnosticMessage>,
@@ -836,8 +808,6 @@ impl Handler {
836808

837809
/// Construct a builder at the `Warn` level with the `msg` and the `code`.
838810
#[rustc_lint_diagnostics]
839-
#[allow(rustc::diagnostic_outside_of_impl)]
840-
#[allow(rustc::untranslatable_diagnostic)]
841811
pub fn struct_warn_with_code(
842812
&self,
843813
msg: impl Into<DiagnosticMessage>,
@@ -850,8 +820,6 @@ impl Handler {
850820

851821
/// Construct a builder at the `Fatal` level at the given `span` and with the `msg`.
852822
#[rustc_lint_diagnostics]
853-
#[allow(rustc::diagnostic_outside_of_impl)]
854-
#[allow(rustc::untranslatable_diagnostic)]
855823
pub fn struct_span_fatal(
856824
&self,
857825
span: impl Into<MultiSpan>,
@@ -864,8 +832,6 @@ impl Handler {
864832

865833
/// Construct a builder at the `Fatal` level at the given `span`, with the `msg`, and `code`.
866834
#[rustc_lint_diagnostics]
867-
#[allow(rustc::diagnostic_outside_of_impl)]
868-
#[allow(rustc::untranslatable_diagnostic)]
869835
pub fn struct_span_fatal_with_code(
870836
&self,
871837
span: impl Into<MultiSpan>,
@@ -879,24 +845,18 @@ impl Handler {
879845

880846
/// Construct a builder at the `Error` level with the `msg`.
881847
#[rustc_lint_diagnostics]
882-
#[allow(rustc::diagnostic_outside_of_impl)]
883-
#[allow(rustc::untranslatable_diagnostic)]
884848
pub fn struct_fatal(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, !> {
885849
DiagnosticBuilder::new_fatal(self, msg)
886850
}
887851

888852
/// Construct a builder at the `Help` level with the `msg`.
889853
#[rustc_lint_diagnostics]
890-
#[allow(rustc::diagnostic_outside_of_impl)]
891-
#[allow(rustc::untranslatable_diagnostic)]
892854
pub fn struct_help(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
893855
DiagnosticBuilder::new(self, Level::Help, msg)
894856
}
895857

896858
/// Construct a builder at the `Note` level with the `msg`.
897859
#[rustc_lint_diagnostics]
898-
#[allow(rustc::diagnostic_outside_of_impl)]
899-
#[allow(rustc::untranslatable_diagnostic)]
900860
pub fn struct_note_without_error(
901861
&self,
902862
msg: impl Into<DiagnosticMessage>,

‎compiler/rustc_expand/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_attr::{self as attr, Deprecation, Stability};
1111
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
1212
use rustc_data_structures::sync::{self, Lrc};
1313
use rustc_errors::{
14-
Applicability, DiagnosticBuilder, IntoDiagnostic, ErrorGuaranteed, MultiSpan, PResult,
14+
Applicability, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic, MultiSpan, PResult,
1515
};
1616
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
1717
use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics};

‎compiler/rustc_infer/src/errors/mod.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use hir::GenericParamKind;
22
use rustc_errors::{
3-
fluent, AddSubdiagnostic, Applicability, DiagnosticMessage, DiagnosticStyledString, MultiSpan,
3+
fluent, AddToDiagnostic, Applicability, DiagnosticMessage, DiagnosticStyledString, MultiSpan,
44
};
55
use rustc_hir as hir;
66
use rustc_hir::{FnRetTy, Ty};
7-
use rustc_macros::SessionDiagnostic;
7+
use rustc_macros::{Diagnostic, Subdiagnostic};
88
use rustc_middle::ty::{Region, TyCtxt};
99
use rustc_span::symbol::kw;
1010
use rustc_span::{symbol::Ident, BytePos, Span};
@@ -16,7 +16,7 @@ use crate::infer::error_reporting::{
1616

1717
pub mod note_and_explain;
1818

19-
#[derive(SessionDiagnostic)]
19+
#[derive(Diagnostic)]
2020
#[diag(infer::opaque_hidden_type)]
2121
pub struct OpaqueHiddenTypeDiag {
2222
#[primary_span]
@@ -28,7 +28,7 @@ pub struct OpaqueHiddenTypeDiag {
2828
pub hidden_type: Span,
2929
}
3030

31-
#[derive(SessionDiagnostic)]
31+
#[derive(Diagnostic)]
3232
#[diag(infer::type_annotations_needed, code = "E0282")]
3333
pub struct AnnotationRequired<'a> {
3434
#[primary_span]
@@ -46,7 +46,7 @@ pub struct AnnotationRequired<'a> {
4646
}
4747

4848
// Copy of `AnnotationRequired` for E0283
49-
#[derive(SessionDiagnostic)]
49+
#[derive(Diagnostic)]
5050
#[diag(infer::type_annotations_needed, code = "E0283")]
5151
pub struct AmbigousImpl<'a> {
5252
#[primary_span]
@@ -64,7 +64,7 @@ pub struct AmbigousImpl<'a> {
6464
}
6565

6666
// Copy of `AnnotationRequired` for E0284
67-
#[derive(SessionDiagnostic)]
67+
#[derive(Diagnostic)]
6868
#[diag(infer::type_annotations_needed, code = "E0284")]
6969
pub struct AmbigousReturn<'a> {
7070
#[primary_span]
@@ -81,7 +81,7 @@ pub struct AmbigousReturn<'a> {
8181
pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
8282
}
8383

84-
#[derive(SessionDiagnostic)]
84+
#[derive(Diagnostic)]
8585
#[diag(infer::need_type_info_in_generator, code = "E0698")]
8686
pub struct NeedTypeInfoInGenerator<'a> {
8787
#[primary_span]
@@ -92,7 +92,7 @@ pub struct NeedTypeInfoInGenerator<'a> {
9292
}
9393

9494
// Used when a better one isn't available
95-
#[derive(SessionSubdiagnostic)]
95+
#[derive(Subdiagnostic)]
9696
#[label(infer::label_bad)]
9797
pub struct InferenceBadError<'a> {
9898
#[primary_span]
@@ -106,7 +106,7 @@ pub struct InferenceBadError<'a> {
106106
pub name: String,
107107
}
108108

109-
#[derive(SessionSubdiagnostic)]
109+
#[derive(Subdiagnostic)]
110110
pub enum SourceKindSubdiag<'a> {
111111
#[suggestion_verbose(
112112
infer::source_kind_subdiag_let,
@@ -147,7 +147,7 @@ pub enum SourceKindSubdiag<'a> {
147147
},
148148
}
149149

150-
#[derive(SessionSubdiagnostic)]
150+
#[derive(Subdiagnostic)]
151151
pub enum SourceKindMultiSuggestion<'a> {
152152
#[multipart_suggestion_verbose(
153153
infer::source_kind_fully_qualified,
@@ -228,7 +228,7 @@ pub enum RegionOriginNote<'a> {
228228
},
229229
}
230230

231-
impl AddSubdiagnostic for RegionOriginNote<'_> {
231+
impl AddToDiagnostic for RegionOriginNote<'_> {
232232
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
233233
let mut label_or_note = |span, msg: DiagnosticMessage| {
234234
let sub_count = diag.children.iter().filter(|d| d.span.is_dummy()).count();
@@ -289,7 +289,7 @@ pub enum LifetimeMismatchLabels {
289289
},
290290
}
291291

292-
impl AddSubdiagnostic for LifetimeMismatchLabels {
292+
impl AddToDiagnostic for LifetimeMismatchLabels {
293293
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
294294
match self {
295295
LifetimeMismatchLabels::InRet { param_span, ret_span, span, label_var1 } => {
@@ -339,7 +339,7 @@ pub struct AddLifetimeParamsSuggestion<'a> {
339339
pub add_note: bool,
340340
}
341341

342-
impl AddSubdiagnostic for AddLifetimeParamsSuggestion<'_> {
342+
impl AddToDiagnostic for AddLifetimeParamsSuggestion<'_> {
343343
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
344344
let mut mk_suggestion = || {
345345
let (
@@ -422,7 +422,7 @@ impl AddSubdiagnostic for AddLifetimeParamsSuggestion<'_> {
422422
}
423423
}
424424

425-
#[derive(SessionDiagnostic)]
425+
#[derive(Diagnostic)]
426426
#[diag(infer::lifetime_mismatch, code = "E0623")]
427427
pub struct LifetimeMismatch<'a> {
428428
#[primary_span]
@@ -438,7 +438,7 @@ pub struct IntroducesStaticBecauseUnmetLifetimeReq {
438438
pub binding_span: Span,
439439
}
440440

441-
impl AddSubdiagnostic for IntroducesStaticBecauseUnmetLifetimeReq {
441+
impl AddToDiagnostic for IntroducesStaticBecauseUnmetLifetimeReq {
442442
fn add_to_diagnostic(mut self, diag: &mut rustc_errors::Diagnostic) {
443443
self.unmet_requirements
444444
.push_span_label(self.binding_span, fluent::infer::msl_introduces_static);
@@ -450,7 +450,7 @@ pub struct ImplNote {
450450
pub impl_span: Option<Span>,
451451
}
452452

453-
impl AddSubdiagnostic for ImplNote {
453+
impl AddToDiagnostic for ImplNote {
454454
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
455455
match self.impl_span {
456456
Some(span) => diag.span_note(span, fluent::infer::msl_impl_note),
@@ -465,7 +465,7 @@ pub enum TraitSubdiag {
465465
}
466466

467467
// FIXME(#100717) used in `Vec<TraitSubdiag>` so requires eager translation/list support
468-
impl AddSubdiagnostic for TraitSubdiag {
468+
impl AddToDiagnostic for TraitSubdiag {
469469
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
470470
match self {
471471
TraitSubdiag::Note { span } => {
@@ -483,7 +483,7 @@ impl AddSubdiagnostic for TraitSubdiag {
483483
}
484484
}
485485

486-
#[derive(SessionDiagnostic)]
486+
#[derive(Diagnostic)]
487487
#[diag(infer::mismatched_static_lifetime)]
488488
pub struct MismatchedStaticLifetime<'a> {
489489
#[primary_span]

‎compiler/rustc_infer/src/errors/note_and_explain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::infer::error_reporting::nice_region_error::find_anon_type;
2-
use rustc_errors::{self, fluent, AddSubdiagnostic, IntoDiagnosticArg};
2+
use rustc_errors::{self, fluent, AddToDiagnostic, IntoDiagnosticArg};
33
use rustc_middle::ty::{self, TyCtxt};
44
use rustc_span::{symbol::kw, Span};
55

@@ -158,7 +158,7 @@ impl RegionExplanation<'_> {
158158
}
159159
}
160160

161-
impl AddSubdiagnostic for RegionExplanation<'_> {
161+
impl AddToDiagnostic for RegionExplanation<'_> {
162162
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
163163
if let Some(span) = self.desc.span {
164164
diag.span_note(span, fluent::infer::region_explanation);

‎compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::infer::lexical_region_resolve::RegionResolutionError;
1111
use crate::infer::SubregionOrigin;
1212
use crate::infer::TyCtxt;
1313

14-
use rustc_errors::AddSubdiagnostic;
14+
use rustc_errors::AddToDiagnostic;
1515
use rustc_errors::{Diagnostic, ErrorGuaranteed};
1616
use rustc_hir::Ty;
1717
use rustc_middle::ty::Region;

‎compiler/rustc_lint/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_errors::{fluent, AddToDiagnostic, IntoDiagnostic, ErrorGuaranteed, Handler};
1+
use rustc_errors::{fluent, AddToDiagnostic, ErrorGuaranteed, Handler, IntoDiagnostic};
22
use rustc_macros::{Diagnostic, Subdiagnostic};
33
use rustc_session::lint::Level;
44
use rustc_span::{Span, Symbol};

‎compiler/rustc_lint/src/internal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ impl LateLintPass<'_> for Diagnostics {
404404
let Impl { of_trait: Some(of_trait), .. } = impl_ &&
405405
let Some(def_id) = of_trait.trait_def_id() &&
406406
let Some(name) = cx.tcx.get_diagnostic_name(def_id) &&
407-
matches!(name, sym::Diagnostic | sym::Subdiagnostic | sym::DecorateLint)
407+
matches!(name, sym::IntoDiagnostic | sym::AddToDiagnostic | sym::DecorateLint)
408408
{
409409
found_impl = true;
410410
break;

‎compiler/rustc_macros/src/diagnostics/diagnostic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ use syn::spanned::Spanned;
99
use synstructure::Structure;
1010

1111
/// The central struct for constructing the `into_diagnostic` method from an annotated struct.
12-
pub(crate) struct SessionDiagnosticDerive<'a> {
12+
pub(crate) struct DiagnosticDerive<'a> {
1313
structure: Structure<'a>,
1414
handler: syn::Ident,
1515
builder: DiagnosticDeriveBuilder,
1616
}
1717

18-
impl<'a> SessionDiagnosticDerive<'a> {
18+
impl<'a> DiagnosticDerive<'a> {
1919
pub(crate) fn new(diag: syn::Ident, handler: syn::Ident, structure: Structure<'a>) -> Self {
2020
Self {
2121
builder: DiagnosticDeriveBuilder {
@@ -31,7 +31,7 @@ impl<'a> SessionDiagnosticDerive<'a> {
3131
}
3232

3333
pub(crate) fn into_tokens(self) -> TokenStream {
34-
let SessionDiagnosticDerive { mut structure, handler, mut builder } = self;
34+
let DiagnosticDerive { mut structure, handler, mut builder } = self;
3535

3636
let ast = structure.ast();
3737
let implementation = {

‎compiler/rustc_macros/src/diagnostics/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod fluent;
55
mod subdiagnostic;
66
mod utils;
77

8-
use diagnostic::{LintDiagnosticDerive, SessionDiagnosticDerive};
8+
use diagnostic::{DiagnosticDerive, LintDiagnosticDerive};
99
pub(crate) use fluent::fluent_messages;
1010
use proc_macro2::TokenStream;
1111
use quote::format_ident;
@@ -59,7 +59,7 @@ use synstructure::Structure;
5959
/// See rustc dev guide for more examples on using the `#[derive(Diagnostic)]`:
6060
/// <https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html>
6161
pub fn session_diagnostic_derive(s: Structure<'_>) -> TokenStream {
62-
SessionDiagnosticDerive::new(format_ident!("diag"), format_ident!("handler"), s).into_tokens()
62+
DiagnosticDerive::new(format_ident!("diag"), format_ident!("handler"), s).into_tokens()
6363
}
6464

6565
/// Implements `#[derive(LintDiagnostic)]`, which allows for lints to be specified as a struct,
@@ -103,7 +103,7 @@ pub fn session_diagnostic_derive(s: Structure<'_>) -> TokenStream {
103103
/// ```
104104
///
105105
/// See rustc dev guide for more examples on using the `#[derive(LintDiagnostic)]`:
106-
/// <https://rustc-dev-guide.rust-lang.org/diagnostics/sessiondiagnostic.html>
106+
/// <https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html#reference>
107107
pub fn lint_diagnostic_derive(s: Structure<'_>) -> TokenStream {
108108
LintDiagnosticDerive::new(format_ident!("diag"), s).into_tokens()
109109
}

‎compiler/rustc_metadata/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{
33
path::{Path, PathBuf},
44
};
55

6-
use rustc_errors::{error_code, IntoDiagnostic, ErrorGuaranteed};
6+
use rustc_errors::{error_code, ErrorGuaranteed, IntoDiagnostic};
77
use rustc_macros::Diagnostic;
88
use rustc_session::config;
99
use rustc_span::{sym, Span, Symbol};

‎compiler/rustc_middle/src/ty/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ use rustc_query_system::ich::StableHashingContext;
5353
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
5454
use rustc_session::config::{CrateType, OutputFilenames};
5555
use rustc_session::cstore::CrateStoreDyn;
56+
use rustc_session::errors::TargetDataLayoutErrorsWrapper;
5657
use rustc_session::lint::Lint;
5758
use rustc_session::Limit;
5859
use rustc_session::Session;
@@ -1245,7 +1246,7 @@ impl<'tcx> TyCtxt<'tcx> {
12451246
output_filenames: OutputFilenames,
12461247
) -> GlobalCtxt<'tcx> {
12471248
let data_layout = TargetDataLayout::parse(&s.target).unwrap_or_else(|err| {
1248-
s.emit_fatal(err);
1249+
s.emit_fatal(TargetDataLayoutErrorsWrapper(err));
12491250
});
12501251
let interners = CtxtInterners::new(arena);
12511252
let common_types = CommonTypes::new(

‎compiler/rustc_monomorphize/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::PathBuf;
22

3-
use rustc_errors::IntoDiagnostic;
43
use rustc_errors::ErrorGuaranteed;
4+
use rustc_errors::IntoDiagnostic;
55
use rustc_macros::{Diagnostic, LintDiagnostic};
66
use rustc_span::Span;
77

‎compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ pub(crate) struct NotAsNegationOperator {
434434
pub sub: NotAsNegationOperatorSub,
435435
}
436436

437-
#[derive(SessionSubdiagnostic)]
437+
#[derive(Subdiagnostic)]
438438
pub enum NotAsNegationOperatorSub {
439439
#[suggestion_short(
440440
parser::unexpected_token_after_not_default,
@@ -737,7 +737,7 @@ pub(crate) struct RemoveLet {
737737
pub span: Span,
738738
}
739739

740-
#[derive(SessionDiagnostic)]
740+
#[derive(Diagnostic)]
741741
#[diag(parser::use_eq_instead)]
742742
pub(crate) struct UseEqInstead {
743743
#[primary_span]

‎compiler/rustc_passes/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ pub struct RustcLintOptDenyFieldAccess {
650650
pub span: Span,
651651
}
652652

653-
#[derive(SessionDiagnostic)]
653+
#[derive(Diagnostic)]
654654
#[diag(passes::collapse_debuginfo)]
655655
pub struct CollapseDebuginfo {
656656
#[primary_span]

‎compiler/rustc_query_system/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_errors::AddToDiagnostic;
2+
use rustc_macros::{Diagnostic, Subdiagnostic};
23
use rustc_session::Limit;
34
use rustc_span::{Span, Symbol};
4-
use rustc_macros::{Diagnostic, Subdiagnostic};
55

66
pub struct CycleStack {
77
pub span: Span,

‎compiler/rustc_query_system/src/query/job.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::query::{QueryContext, QueryStackFrame};
44

55
use rustc_data_structures::fx::FxHashMap;
66
use rustc_errors::{
7-
Diagnostic, DiagnosticBuilder, IntoDiagnostic, ErrorGuaranteed, Handler, Level,
7+
Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic, Level,
88
};
99
use rustc_hir::def::DefKind;
1010
use rustc_session::Session;

‎compiler/rustc_session/src/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
pub use crate::options::*;
55

6+
use crate::errors::TargetDataLayoutErrorsWrapper;
67
use crate::search_paths::SearchPath;
78
use crate::utils::{CanonicalizedPath, NativeLib, NativeLibKind};
89
use crate::{early_error, early_warn, Session};
@@ -898,7 +899,7 @@ fn default_configuration(sess: &Session) -> CrateConfig {
898899
let max_atomic_width = sess.target.max_atomic_width();
899900
let atomic_cas = sess.target.atomic_cas;
900901
let layout = TargetDataLayout::parse(&sess.target).unwrap_or_else(|err| {
901-
sess.emit_fatal(err);
902+
sess.emit_fatal(TargetDataLayoutErrorsWrapper(err));
902903
});
903904

904905
let mut ret = CrateConfig::default();

‎compiler/rustc_session/src/errors.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use std::num::NonZeroU32;
22

33
use crate::cgu_reuse_tracker::CguReuse;
4-
use crate::{self as rustc_session, SessionDiagnostic};
5-
use rustc_errors::{fluent, DiagnosticBuilder, ErrorGuaranteed, Handler, MultiSpan};
6-
use rustc_macros::SessionDiagnostic;
4+
use rustc_errors::{
5+
fluent, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic, MultiSpan,
6+
};
7+
use rustc_macros::Diagnostic;
78
use rustc_span::{Span, Symbol};
89
use rustc_target::abi::TargetDataLayoutErrors;
910
use rustc_target::spec::{SplitDebuginfo, StackProtector, TargetTriple};
@@ -46,10 +47,12 @@ pub struct FeatureDiagnosticHelp {
4647
pub feature: Symbol,
4748
}
4849

49-
impl IntoDiagnostic<'_, !> for TargetDataLayoutErrors<'_> {
50+
pub struct TargetDataLayoutErrorsWrapper<'a>(pub TargetDataLayoutErrors<'a>);
51+
52+
impl IntoDiagnostic<'_, !> for TargetDataLayoutErrorsWrapper<'_> {
5053
fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, !> {
5154
let mut diag;
52-
match self {
55+
match self.0 {
5356
TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => {
5457
diag = handler.struct_fatal(fluent::session::target_invalid_address_space);
5558
diag.set_arg("addr_space", addr_space);
@@ -97,87 +100,87 @@ impl IntoDiagnostic<'_, !> for TargetDataLayoutErrors<'_> {
97100
}
98101
}
99102

100-
#[derive(SessionDiagnostic)]
103+
#[derive(Diagnostic)]
101104
#[diag(session::not_circumvent_feature)]
102105
pub struct NotCircumventFeature;
103106

104-
#[derive(SessionDiagnostic)]
107+
#[derive(Diagnostic)]
105108
#[diag(session::linker_plugin_lto_windows_not_supported)]
106109
pub struct LinkerPluginToWindowsNotSupported;
107110

108-
#[derive(SessionDiagnostic)]
111+
#[derive(Diagnostic)]
109112
#[diag(session::profile_use_file_does_not_exist)]
110113
pub struct ProfileUseFileDoesNotExist<'a> {
111114
pub path: &'a std::path::Path,
112115
}
113116

114-
#[derive(SessionDiagnostic)]
117+
#[derive(Diagnostic)]
115118
#[diag(session::profile_sample_use_file_does_not_exist)]
116119
pub struct ProfileSampleUseFileDoesNotExist<'a> {
117120
pub path: &'a std::path::Path,
118121
}
119122

120-
#[derive(SessionDiagnostic)]
123+
#[derive(Diagnostic)]
121124
#[diag(session::target_requires_unwind_tables)]
122125
pub struct TargetRequiresUnwindTables;
123126

124-
#[derive(SessionDiagnostic)]
127+
#[derive(Diagnostic)]
125128
#[diag(session::sanitizer_not_supported)]
126129
pub struct SanitizerNotSupported {
127130
pub us: String,
128131
}
129132

130-
#[derive(SessionDiagnostic)]
133+
#[derive(Diagnostic)]
131134
#[diag(session::sanitizers_not_supported)]
132135
pub struct SanitizersNotSupported {
133136
pub us: String,
134137
}
135138

136-
#[derive(SessionDiagnostic)]
139+
#[derive(Diagnostic)]
137140
#[diag(session::cannot_mix_and_match_sanitizers)]
138141
pub struct CannotMixAndMatchSanitizers {
139142
pub first: String,
140143
pub second: String,
141144
}
142145

143-
#[derive(SessionDiagnostic)]
146+
#[derive(Diagnostic)]
144147
#[diag(session::cannot_enable_crt_static_linux)]
145148
pub struct CannotEnableCrtStaticLinux;
146149

147-
#[derive(SessionDiagnostic)]
150+
#[derive(Diagnostic)]
148151
#[diag(session::sanitizer_cfi_enabled)]
149152
pub struct SanitizerCfiEnabled;
150153

151-
#[derive(SessionDiagnostic)]
154+
#[derive(Diagnostic)]
152155
#[diag(session::unstable_virtual_function_elimination)]
153156
pub struct UnstableVirtualFunctionElimination;
154157

155-
#[derive(SessionDiagnostic)]
158+
#[derive(Diagnostic)]
156159
#[diag(session::unsupported_dwarf_version)]
157160
pub struct UnsupportedDwarfVersion {
158161
pub dwarf_version: u32,
159162
}
160163

161-
#[derive(SessionDiagnostic)]
164+
#[derive(Diagnostic)]
162165
#[diag(session::target_stack_protector_not_supported)]
163166
pub struct StackProtectorNotSupportedForTarget<'a> {
164167
pub stack_protector: StackProtector,
165168
pub target_triple: &'a TargetTriple,
166169
}
167170

168-
#[derive(SessionDiagnostic)]
171+
#[derive(Diagnostic)]
169172
#[diag(session::split_debuginfo_unstable_platform)]
170173
pub struct SplitDebugInfoUnstablePlatform {
171174
pub debuginfo: SplitDebuginfo,
172175
}
173176

174-
#[derive(SessionDiagnostic)]
177+
#[derive(Diagnostic)]
175178
#[diag(session::file_is_not_writeable)]
176179
pub struct FileIsNotWriteable<'a> {
177180
pub file: &'a std::path::Path,
178181
}
179182

180-
#[derive(SessionDiagnostic)]
183+
#[derive(Diagnostic)]
181184
#[diag(session::crate_name_does_not_match)]
182185
pub struct CrateNameDoesNotMatch<'a> {
183186
#[primary_span]
@@ -186,13 +189,13 @@ pub struct CrateNameDoesNotMatch<'a> {
186189
pub name: Symbol,
187190
}
188191

189-
#[derive(SessionDiagnostic)]
192+
#[derive(Diagnostic)]
190193
#[diag(session::crate_name_invalid)]
191194
pub struct CrateNameInvalid<'a> {
192195
pub s: &'a str,
193196
}
194197

195-
#[derive(SessionDiagnostic)]
198+
#[derive(Diagnostic)]
196199
#[diag(session::crate_name_empty)]
197200
pub struct CrateNameEmpty {
198201
#[primary_span]
@@ -205,11 +208,8 @@ pub struct InvalidCharacterInCrateName<'a> {
205208
pub crate_name: &'a str,
206209
}
207210

208-
impl crate::SessionDiagnostic<'_> for InvalidCharacterInCrateName<'_> {
209-
fn into_diagnostic(
210-
self,
211-
sess: &Handler,
212-
) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
211+
impl IntoDiagnostic<'_> for InvalidCharacterInCrateName<'_> {
212+
fn into_diagnostic(self, sess: &Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
213213
let mut diag = sess.struct_err(fluent::session::invalid_character_in_create_name);
214214
if let Some(sp) = self.span {
215215
diag.set_span(sp);

‎compiler/rustc_session/src/parse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
1111
use rustc_data_structures::sync::{Lock, Lrc};
1212
use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler};
1313
use rustc_errors::{
14-
fallback_fluent_bundle, Applicability, Diagnostic, DiagnosticBuilder, IntoDiagnostic,
15-
DiagnosticId, DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, MultiSpan, StashKey,
14+
fallback_fluent_bundle, Applicability, Diagnostic, DiagnosticBuilder, DiagnosticId,
15+
DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, IntoDiagnostic, MultiSpan, StashKey,
1616
};
1717
use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures};
1818
use rustc_span::edition::Edition;

‎compiler/rustc_session/src/session.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ use rustc_errors::emitter::{Emitter, EmitterWriter, HumanReadableErrorType};
2727
use rustc_errors::json::JsonEmitter;
2828
use rustc_errors::registry::Registry;
2929
use rustc_errors::{
30-
error_code, fallback_fluent_bundle, DiagnosticBuilder, IntoDiagnostic, DiagnosticId,
31-
DiagnosticMessage, ErrorGuaranteed, FluentBundle, LazyFallbackBundle, MultiSpan,
30+
error_code, fallback_fluent_bundle, DiagnosticBuilder, DiagnosticId, DiagnosticMessage,
31+
ErrorGuaranteed, FluentBundle, IntoDiagnostic, LazyFallbackBundle, MultiSpan,
3232
};
3333
use rustc_macros::HashStable_Generic;
3434
pub use rustc_span::def_id::StableCrateId;

‎compiler/rustc_span/src/symbol.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ symbols! {
125125
Symbols {
126126
AcqRel,
127127
Acquire,
128+
AddToDiagnostic,
128129
Alignment,
129130
Any,
130131
Arc,
@@ -176,7 +177,6 @@ symbols! {
176177
DecorateLint,
177178
Default,
178179
Deref,
179-
Diagnostic,
180180
DiagnosticMessage,
181181
DirBuilder,
182182
Display,
@@ -210,6 +210,7 @@ symbols! {
210210
Implied,
211211
Input,
212212
Into,
213+
IntoDiagnostic,
213214
IntoFuture,
214215
IntoIterator,
215216
IoRead,
@@ -282,7 +283,6 @@ symbols! {
282283
String,
283284
StructuralEq,
284285
StructuralPartialEq,
285-
Subdiagnostic,
286286
SubdiagnosticMessage,
287287
Sync,
288288
T,

‎compiler/rustc_trait_selection/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_errors::{fluent, IntoDiagnostic, ErrorGuaranteed, Handler};
1+
use rustc_errors::{fluent, ErrorGuaranteed, Handler, IntoDiagnostic};
22
use rustc_macros::Diagnostic;
33
use rustc_middle::ty::{PolyTraitRef, Ty, Unevaluated};
44
use rustc_session::Limit;

‎src/test/ui-fulldeps/internal-lints/diagnostics.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_span::Span;
2020

2121
#[derive(Diagnostic)]
2222
#[diag(parser::expect_path)]
23-
struct DeriveSessionDiagnostic {
23+
struct DeriveDiagnostic {
2424
#[primary_span]
2525
span: Span,
2626
}
@@ -32,18 +32,18 @@ struct Note {
3232
span: Span,
3333
}
3434

35-
pub struct UntranslatableInSessionDiagnostic;
35+
pub struct UntranslatableInIntoDiagnostic;
3636

37-
impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for UntranslatableInSessionDiagnostic {
37+
impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for UntranslatableInIntoDiagnostic {
3838
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
3939
handler.struct_err("untranslatable diagnostic")
4040
//~^ ERROR diagnostics should be created using translatable messages
4141
}
4242
}
4343

44-
pub struct TranslatableInSessionDiagnostic;
44+
pub struct TranslatableInIntoDiagnostic;
4545

46-
impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for TranslatableInSessionDiagnostic {
46+
impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for TranslatableInIntoDiagnostic {
4747
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
4848
handler.struct_err(fluent::parser::expect_path)
4949
}

‎src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ error[E0277]: the trait bound `Hello: IntoDiagnosticArg` is not satisfied
449449
--> $DIR/diagnostic-derive.rs:331:10
450450
|
451451
LL | #[derive(Diagnostic)]
452-
| ^^^^^^^^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `Hello`
452+
| ^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `Hello`
453453
|
454454
= help: normalized in stderr
455455
note: required by a bound in `DiagnosticBuilder::<'a, G>::set_arg`

0 commit comments

Comments
 (0)
Please sign in to comment.