@@ -132,7 +132,7 @@ impl EmissionGuarantee for ErrorGuaranteed {
132
132
DiagnosticBuilderState :: Emittable ( handler) => {
133
133
db. inner . state = DiagnosticBuilderState :: AlreadyEmittedOrDuringCancellation ;
134
134
135
- let guar = handler. emit_diagnostic ( & mut db. inner . diagnostic ) ;
135
+ let guar = handler. emit_diagnostic_without_consuming ( & mut db. inner . diagnostic ) ;
136
136
137
137
// Only allow a guarantee if the `level` wasn't switched to a
138
138
// non-error - the field isn't `pub`, but the whole `Diagnostic`
@@ -181,7 +181,7 @@ impl EmissionGuarantee for () {
181
181
DiagnosticBuilderState :: Emittable ( handler) => {
182
182
db. inner . state = DiagnosticBuilderState :: AlreadyEmittedOrDuringCancellation ;
183
183
184
- handler. emit_diagnostic ( & mut db. inner . diagnostic ) ;
184
+ handler. emit_diagnostic_without_consuming ( & mut db. inner . diagnostic ) ;
185
185
}
186
186
// `.emit()` was previously called, disallowed from repeating it.
187
187
DiagnosticBuilderState :: AlreadyEmittedOrDuringCancellation => { }
@@ -207,7 +207,7 @@ impl EmissionGuarantee for Noted {
207
207
// First `.emit()` call, the `&Handler` is still available.
208
208
DiagnosticBuilderState :: Emittable ( handler) => {
209
209
db. inner . state = DiagnosticBuilderState :: AlreadyEmittedOrDuringCancellation ;
210
- handler. emit_diagnostic ( & mut db. inner . diagnostic ) ;
210
+ handler. emit_diagnostic_without_consuming ( & mut db. inner . diagnostic ) ;
211
211
}
212
212
// `.emit()` was previously called, disallowed from repeating it.
213
213
DiagnosticBuilderState :: AlreadyEmittedOrDuringCancellation => { }
@@ -236,7 +236,7 @@ impl EmissionGuarantee for Bug {
236
236
DiagnosticBuilderState :: Emittable ( handler) => {
237
237
db. inner . state = DiagnosticBuilderState :: AlreadyEmittedOrDuringCancellation ;
238
238
239
- handler. emit_diagnostic ( & mut db. inner . diagnostic ) ;
239
+ handler. emit_diagnostic_without_consuming ( & mut db. inner . diagnostic ) ;
240
240
}
241
241
// `.emit()` was previously called, disallowed from repeating it.
242
242
DiagnosticBuilderState :: AlreadyEmittedOrDuringCancellation => { }
@@ -260,7 +260,7 @@ impl EmissionGuarantee for ! {
260
260
DiagnosticBuilderState :: Emittable ( handler) => {
261
261
db. inner . state = DiagnosticBuilderState :: AlreadyEmittedOrDuringCancellation ;
262
262
263
- handler. emit_diagnostic ( & mut db. inner . diagnostic ) ;
263
+ handler. emit_diagnostic_without_consuming ( & mut db. inner . diagnostic ) ;
264
264
}
265
265
// `.emit()` was previously called, disallowed from repeating it.
266
266
DiagnosticBuilderState :: AlreadyEmittedOrDuringCancellation => { }
@@ -284,7 +284,7 @@ impl EmissionGuarantee for rustc_span::fatal_error::FatalError {
284
284
DiagnosticBuilderState :: Emittable ( handler) => {
285
285
db. inner . state = DiagnosticBuilderState :: AlreadyEmittedOrDuringCancellation ;
286
286
287
- handler. emit_diagnostic ( & mut db. inner . diagnostic ) ;
287
+ handler. emit_diagnostic_without_consuming ( & mut db. inner . diagnostic ) ;
288
288
}
289
289
// `.emit()` was previously called, disallowed from repeating it.
290
290
DiagnosticBuilderState :: AlreadyEmittedOrDuringCancellation => { }
@@ -365,7 +365,9 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
365
365
}
366
366
}
367
367
368
- /// Emit the diagnostic.
368
+ /// Emit the diagnostic. Does not consume `self`, which may be surprising,
369
+ /// but there are various places that rely on continuing to use `self`
370
+ /// after calling `emit`.
369
371
#[ track_caller]
370
372
pub fn emit ( & mut self ) -> G {
371
373
G :: diagnostic_builder_emit_producing_guarantee ( self )
@@ -640,13 +642,13 @@ impl Drop for DiagnosticBuilderInner<'_> {
640
642
// No `.emit()` or `.cancel()` calls.
641
643
DiagnosticBuilderState :: Emittable ( handler) => {
642
644
if !panicking ( ) {
643
- handler. emit_diagnostic ( & mut Diagnostic :: new (
645
+ handler. emit_diagnostic ( Diagnostic :: new (
644
646
Level :: Bug ,
645
647
DiagnosticMessage :: from (
646
648
"the following error was constructed but not emitted" ,
647
649
) ,
648
650
) ) ;
649
- handler. emit_diagnostic ( & mut self . diagnostic ) ;
651
+ handler. emit_diagnostic_without_consuming ( & mut self . diagnostic ) ;
650
652
panic ! ( "error was constructed but not emitted" ) ;
651
653
}
652
654
}
0 commit comments