# Macro rustc_errors::diagnostic_builder::forward

source ·

    macro_rules! forward {
        (
            ($n:ident, $n_mv:ident)($($name:ident: $ty:ty),* $(,)?)
        ) => { ... };
    }

Expand description

`DiagnosticBuilder` impls `DerefMut`, which allows access to the fields and methods of the embedded `Diagnostic`. However, that doesn’t allow method chaining at the `DiagnosticBuilder` level. Each use of this macro defines two builder methods at that level, both of which wrap the equivalent method in `Diagnostic`.

- A `&mut self -> &mut Self` method, with the same name as the underlying `Diagnostic` method. It is mostly to modify existing diagnostics, either in a standalone fashion, e.g. `err.code(code)`, or in a chained fashion to make multiple modifications, e.g. `err.code(code).span(span)`.
- A `self -> Self` method, with `_mv` suffix added (short for “move”). It is mostly used in a chained fashion when producing a new diagnostic, e.g. `let err = struct_err(msg).code_mv(code)`, or when emitting a new diagnostic , e.g. `struct_err(msg).code_mv(code).emit()`.

Although the latter method can be used to modify an existing diagnostic, e.g. `err = err.code_mv(code)`, this should be avoided because the former method give shorter code, e.g. `err.code(code)`.