Skip to content

Commit e52e234

Browse files
committed
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

+1-1
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

+1-2
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

+1-1
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

+1-1
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

+2-42
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

+1-1
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

+18-18
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]

0 commit comments

Comments
 (0)