@@ -132,7 +132,7 @@ impl EmissionGuarantee for ErrorGuaranteed {
132132 DiagnosticBuilderState :: Emittable ( handler) => {
133133 db. inner . state = DiagnosticBuilderState :: AlreadyEmittedOrDuringCancellation ;
134134
135- let guar = handler. emit_diagnostic ( & mut db. inner . diagnostic ) ;
135+ let guar = handler. emit_diagnostic_without_consuming ( & mut db. inner . diagnostic ) ;
136136
137137 // Only allow a guarantee if the `level` wasn't switched to a
138138 // non-error - the field isn't `pub`, but the whole `Diagnostic`
@@ -181,7 +181,7 @@ impl EmissionGuarantee for () {
181181 DiagnosticBuilderState :: Emittable ( handler) => {
182182 db. inner . state = DiagnosticBuilderState :: AlreadyEmittedOrDuringCancellation ;
183183
184- handler. emit_diagnostic ( & mut db. inner . diagnostic ) ;
184+ handler. emit_diagnostic_without_consuming ( & mut db. inner . diagnostic ) ;
185185 }
186186 // `.emit()` was previously called, disallowed from repeating it.
187187 DiagnosticBuilderState :: AlreadyEmittedOrDuringCancellation => { }
@@ -207,7 +207,7 @@ impl EmissionGuarantee for Noted {
207207 // First `.emit()` call, the `&Handler` is still available.
208208 DiagnosticBuilderState :: Emittable ( handler) => {
209209 db. inner . state = DiagnosticBuilderState :: AlreadyEmittedOrDuringCancellation ;
210- handler. emit_diagnostic ( & mut db. inner . diagnostic ) ;
210+ handler. emit_diagnostic_without_consuming ( & mut db. inner . diagnostic ) ;
211211 }
212212 // `.emit()` was previously called, disallowed from repeating it.
213213 DiagnosticBuilderState :: AlreadyEmittedOrDuringCancellation => { }
@@ -236,7 +236,7 @@ impl EmissionGuarantee for Bug {
236236 DiagnosticBuilderState :: Emittable ( handler) => {
237237 db. inner . state = DiagnosticBuilderState :: AlreadyEmittedOrDuringCancellation ;
238238
239- handler. emit_diagnostic ( & mut db. inner . diagnostic ) ;
239+ handler. emit_diagnostic_without_consuming ( & mut db. inner . diagnostic ) ;
240240 }
241241 // `.emit()` was previously called, disallowed from repeating it.
242242 DiagnosticBuilderState :: AlreadyEmittedOrDuringCancellation => { }
@@ -260,7 +260,7 @@ impl EmissionGuarantee for ! {
260260 DiagnosticBuilderState :: Emittable ( handler) => {
261261 db. inner . state = DiagnosticBuilderState :: AlreadyEmittedOrDuringCancellation ;
262262
263- handler. emit_diagnostic ( & mut db. inner . diagnostic ) ;
263+ handler. emit_diagnostic_without_consuming ( & mut db. inner . diagnostic ) ;
264264 }
265265 // `.emit()` was previously called, disallowed from repeating it.
266266 DiagnosticBuilderState :: AlreadyEmittedOrDuringCancellation => { }
@@ -284,7 +284,7 @@ impl EmissionGuarantee for rustc_span::fatal_error::FatalError {
284284 DiagnosticBuilderState :: Emittable ( handler) => {
285285 db. inner . state = DiagnosticBuilderState :: AlreadyEmittedOrDuringCancellation ;
286286
287- handler. emit_diagnostic ( & mut db. inner . diagnostic ) ;
287+ handler. emit_diagnostic_without_consuming ( & mut db. inner . diagnostic ) ;
288288 }
289289 // `.emit()` was previously called, disallowed from repeating it.
290290 DiagnosticBuilderState :: AlreadyEmittedOrDuringCancellation => { }
@@ -365,7 +365,9 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
365365 }
366366 }
367367
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`.
369371 #[ track_caller]
370372 pub fn emit ( & mut self ) -> G {
371373 G :: diagnostic_builder_emit_producing_guarantee ( self )
@@ -640,13 +642,13 @@ impl Drop for DiagnosticBuilderInner<'_> {
640642 // No `.emit()` or `.cancel()` calls.
641643 DiagnosticBuilderState :: Emittable ( handler) => {
642644 if !panicking ( ) {
643- handler. emit_diagnostic ( & mut Diagnostic :: new (
645+ handler. emit_diagnostic ( Diagnostic :: new (
644646 Level :: Bug ,
645647 DiagnosticMessage :: from (
646648 "the following error was constructed but not emitted" ,
647649 ) ,
648650 ) ) ;
649- handler. emit_diagnostic ( & mut self . diagnostic ) ;
651+ handler. emit_diagnostic_without_consuming ( & mut self . diagnostic ) ;
650652 panic ! ( "error was constructed but not emitted" ) ;
651653 }
652654 }
0 commit comments