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 29f87ad

Browse files
committedFeb 20, 2024
Auto merge of #120576 - nnethercote:merge-Diagnostic-DiagnosticBuilder, r=davidtwco
Overhaul `Diagnostic` and `DiagnosticBuilder` Implements the first part of rust-lang/compiler-team#722, which moves functionality and use away from `Diagnostic`, onto `DiagnosticBuilder`. Likely follow-ups: - Move things around, because this PR was written to minimize diff size, so some things end up in sub-optimal places. E.g. `DiagnosticBuilder` has impls in both `diagnostic.rs` and `diagnostic_builder.rs`. - Rename `Diagnostic` as `DiagInner` and `DiagnosticBuilder` as `Diag`. r? `@davidtwco`
2 parents cce6a6e + f6f8779 commit 29f87ad

File tree

104 files changed

+1037
-848
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+1037
-848
lines changed
 

‎compiler/rustc_ast_lowering/src/errors.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use rustc_errors::{
2-
codes::*, AddToDiagnostic, Diagnostic, DiagnosticArgFromDisplay, SubdiagnosticMessageOp,
2+
codes::*, AddToDiagnostic, DiagnosticArgFromDisplay, DiagnosticBuilder, EmissionGuarantee,
3+
SubdiagnosticMessageOp,
34
};
45
use rustc_macros::{Diagnostic, Subdiagnostic};
56
use rustc_span::{symbol::Ident, Span, Symbol};
@@ -41,7 +42,11 @@ pub struct InvalidAbi {
4142
pub struct InvalidAbiReason(pub &'static str);
4243

4344
impl AddToDiagnostic for InvalidAbiReason {
44-
fn add_to_diagnostic_with<F: SubdiagnosticMessageOp>(self, diag: &mut Diagnostic, _: F) {
45+
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
46+
self,
47+
diag: &mut DiagnosticBuilder<'_, G>,
48+
_: F,
49+
) {
4550
#[allow(rustc::untranslatable_diagnostic)]
4651
diag.note(self.0);
4752
}

‎compiler/rustc_ast_passes/src/errors.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
//! Errors emitted by ast_passes.
22
33
use rustc_ast::ParamKindOrd;
4-
use rustc_errors::{codes::*, AddToDiagnostic, Applicability, Diagnostic, SubdiagnosticMessageOp};
4+
use rustc_errors::{
5+
codes::*, AddToDiagnostic, Applicability, DiagnosticBuilder, EmissionGuarantee,
6+
SubdiagnosticMessageOp,
7+
};
58
use rustc_macros::{Diagnostic, Subdiagnostic};
69
use rustc_span::{symbol::Ident, Span, Symbol};
710

@@ -372,7 +375,11 @@ pub struct EmptyLabelManySpans(pub Vec<Span>);
372375

373376
// The derive for `Vec<Span>` does multiple calls to `span_label`, adding commas between each
374377
impl AddToDiagnostic for EmptyLabelManySpans {
375-
fn add_to_diagnostic_with<F: SubdiagnosticMessageOp>(self, diag: &mut Diagnostic, _: F) {
378+
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
379+
self,
380+
diag: &mut DiagnosticBuilder<'_, G>,
381+
_: F,
382+
) {
376383
diag.span_labels(self.0, "");
377384
}
378385
}
@@ -729,7 +736,11 @@ pub struct StableFeature {
729736
}
730737

731738
impl AddToDiagnostic for StableFeature {
732-
fn add_to_diagnostic_with<F: SubdiagnosticMessageOp>(self, diag: &mut Diagnostic, _: F) {
739+
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
740+
self,
741+
diag: &mut DiagnosticBuilder<'_, G>,
742+
_: F,
743+
) {
733744
diag.arg("name", self.name);
734745
diag.arg("since", self.since);
735746
diag.help(fluent::ast_passes_stable_since);

0 commit comments

Comments
 (0)