Macro rustc_errors::diagnostic_builder::forward
source · macro_rules! forward { ( ($f:ident, $with_f: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 Selfmethod, with the same name as the underlyingDiagnosticmethod. 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 -> Selfmethod, which has awith_prefix added. It is mostly used in a chained fashion when producing a new diagnostic, e.g.let err = struct_err(msg).with_code(code), or when emitting a new diagnostic , e.g.struct_err(msg).with_code(code).emit().
Although the latter method can be used to modify an existing diagnostic,
e.g. err = err.with_code(code), this should be avoided because the former
method gives shorter code, e.g. err.code(code).