Skip to content

Commit

Permalink
XXX: make emit_producing_{guarantee,nothing} consuming
Browse files Browse the repository at this point in the history
  • Loading branch information
nnethercote committed Jan 5, 2024
1 parent b53aa9b commit 8bfeeac
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions compiler/rustc_errors/src/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ pub trait EmissionGuarantee: Sized {
/// `impl` of `EmissionGuarantee`, to make it impossible to create a value
/// of `Self::EmitResult` without actually performing the emission.
#[track_caller]
fn emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Self>) -> Self::EmitResult;
fn emit_producing_guarantee(db: DiagnosticBuilder<'_, Self>) -> Self::EmitResult;
}

impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
/// Most `emit_producing_guarantee` functions use this as a starting point.
fn emit_producing_nothing(&mut self) {
fn emit_producing_nothing(mut self) {
match self.state {
// First `.emit()` call, the `&DiagCtxt` is still available.
DiagnosticBuilderState::Emittable(dcx) => {
Expand All @@ -111,7 +111,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {

// FIXME(eddyb) make `ErrorGuaranteed` impossible to create outside `.emit()`.
impl EmissionGuarantee for ErrorGuaranteed {
fn emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Self>) -> Self::EmitResult {
fn emit_producing_guarantee(mut db: DiagnosticBuilder<'_, Self>) -> Self::EmitResult {
// Contrast this with `emit_producing_nothing`.
match db.state {
// First `.emit()` call, the `&DiagCtxt` is still available.
Expand Down Expand Up @@ -152,7 +152,7 @@ impl EmissionGuarantee for ErrorGuaranteed {

// FIXME(eddyb) should there be a `Option<ErrorGuaranteed>` impl as well?
impl EmissionGuarantee for () {
fn emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Self>) -> Self::EmitResult {
fn emit_producing_guarantee(db: DiagnosticBuilder<'_, Self>) -> Self::EmitResult {
db.emit_producing_nothing();
}
}
Expand All @@ -165,7 +165,7 @@ pub struct BugAbort;
impl EmissionGuarantee for BugAbort {
type EmitResult = !;

fn emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Self>) -> Self::EmitResult {
fn emit_producing_guarantee(db: DiagnosticBuilder<'_, Self>) -> Self::EmitResult {
db.emit_producing_nothing();
panic::panic_any(ExplicitBug);
}
Expand All @@ -179,14 +179,14 @@ pub struct FatalAbort;
impl EmissionGuarantee for FatalAbort {
type EmitResult = !;

fn emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Self>) -> Self::EmitResult {
fn emit_producing_guarantee(db: DiagnosticBuilder<'_, Self>) -> Self::EmitResult {
db.emit_producing_nothing();
crate::FatalError.raise()
}
}

impl EmissionGuarantee for rustc_span::fatal_error::FatalError {
fn emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Self>) -> Self::EmitResult {
fn emit_producing_guarantee(db: DiagnosticBuilder<'_, Self>) -> Self::EmitResult {
db.emit_producing_nothing();
rustc_span::fatal_error::FatalError
}
Expand Down Expand Up @@ -269,8 +269,8 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {

/// Emit and consume the diagnostic.
#[track_caller]
pub fn emit(mut self) -> G::EmitResult {
G::emit_producing_guarantee(&mut self)
pub fn emit(self) -> G::EmitResult {
G::emit_producing_guarantee(self)
}

/// Emit the diagnostic unless `delay` is true,
Expand Down

0 comments on commit 8bfeeac

Please sign in to comment.