@@ -108,6 +108,25 @@ impl EmissionGuarantee for rustc_span::fatal_error::FatalError {
108108
109109/// Trait implemented by error types. This is rarely implemented manually. Instead, use
110110/// `#[derive(Diagnostic)]` -- see [rustc_macros::Diagnostic].
111+ ///
112+ /// When implemented manually, it should be generic over the emission
113+ /// guarantee, i.e.:
114+ /// ```ignore (fragment)
115+ /// impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for Foo { ... }
116+ /// ```
117+ /// rather than being specific:
118+ /// ```ignore (fragment)
119+ /// impl<'a> IntoDiagnostic<'a> for Bar { ... } // the default type param is `ErrorGuaranteed`
120+ /// impl<'a> IntoDiagnostic<'a, ()> for Baz { ... }
121+ /// ```
122+ /// There are two reasons for this.
123+ /// - A diagnostic like `Foo` *could* be emitted at any level -- `level` is
124+ /// passed in to `into_diagnostic` from outside. Even if in practice it is
125+ /// always emitted at a single level, we let the diagnostic creation/emission
126+ /// site determine the level (by using `create_err`, `emit_warn`, etc.)
127+ /// rather than the `IntoDiagnostic` impl.
128+ /// - Derived impls are always generic, and it's good for the hand-written
129+ /// impls to be consistent with them.
111130#[ rustc_diagnostic_item = "IntoDiagnostic" ]
112131pub trait IntoDiagnostic < ' a , G : EmissionGuarantee = ErrorGuaranteed > {
113132 /// Write out as a diagnostic out of `DiagCtxt`.
0 commit comments