@@ -255,6 +255,56 @@ impl EmissionGuarantee for () {
255255 }
256256}
257257
258+ /// Marker type which enables implementation of `create_note` and `emit_note` functions for
259+ /// note-without-error struct diagnostics.
260+ #[ derive( Copy , Clone ) ]
261+ pub struct Noted ;
262+
263+ impl < ' a > DiagnosticBuilder < ' a , Noted > {
264+ /// Convenience function for internal use, clients should use one of the
265+ /// `struct_*` methods on [`Handler`].
266+ pub ( crate ) fn new_note ( handler : & ' a Handler , message : impl Into < DiagnosticMessage > ) -> Self {
267+ let diagnostic = Diagnostic :: new_with_code ( Level :: Note , None , message) ;
268+ Self :: new_diagnostic_note ( handler, diagnostic)
269+ }
270+
271+ /// Creates a new `DiagnosticBuilder` with an already constructed
272+ /// diagnostic.
273+ pub ( crate ) fn new_diagnostic_note ( handler : & ' a Handler , diagnostic : Diagnostic ) -> Self {
274+ debug ! ( "Created new diagnostic" ) ;
275+ Self {
276+ inner : DiagnosticBuilderInner {
277+ state : DiagnosticBuilderState :: Emittable ( handler) ,
278+ diagnostic : Box :: new ( diagnostic) ,
279+ } ,
280+ _marker : PhantomData ,
281+ }
282+ }
283+ }
284+
285+ impl EmissionGuarantee for Noted {
286+ fn diagnostic_builder_emit_producing_guarantee ( db : & mut DiagnosticBuilder < ' _ , Self > ) -> Self {
287+ match db. inner . state {
288+ // First `.emit()` call, the `&Handler` is still available.
289+ DiagnosticBuilderState :: Emittable ( handler) => {
290+ db. inner . state = DiagnosticBuilderState :: AlreadyEmittedOrDuringCancellation ;
291+ handler. emit_diagnostic ( & mut db. inner . diagnostic ) ;
292+ }
293+ // `.emit()` was previously called, disallowed from repeating it.
294+ DiagnosticBuilderState :: AlreadyEmittedOrDuringCancellation => { }
295+ }
296+
297+ Noted
298+ }
299+
300+ fn make_diagnostic_builder (
301+ handler : & Handler ,
302+ msg : impl Into < DiagnosticMessage > ,
303+ ) -> DiagnosticBuilder < ' _ , Self > {
304+ DiagnosticBuilder :: new_note ( handler, msg)
305+ }
306+ }
307+
258308impl < ' a > DiagnosticBuilder < ' a , !> {
259309 /// Convenience function for internal use, clients should use one of the
260310 /// `struct_*` methods on [`Handler`].
0 commit comments