pub fn struct_lint_level(
    sess: &Session,
    lint: &'static Lint,
    level: Level,
    src: LintLevelSource,
    span: Option<MultiSpan>,
    msg: impl Into<DiagnosticMessage>,
    decorate: impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>) -> &'b mut DiagnosticBuilder<'a, ()>
)
Expand description

The innermost function for emitting lints.

If you are looking to implement a lint, look for higher level functions, for example:

decorate signature

The return value of decorate is ignored by this function. So what is the point of returning &'b mut DiagnosticBuilder<'a, ()>?

There are 2 reasons for this signature.

First of all, it prevents accidental use of .emit() – it’s clear that the builder will be later used and shouldn’t be emitted right away (this is especially important because the old API expected you to call .emit() in the closure).

Second of all, it makes the most common case of adding just a single label /suggestion much nicer, since DiagnosticBuilder methods return &mut DiagnosticBuilder, you can just chain methods, without needed awkward { ...; }:

struct_lint_level(
    ...,
    |lint| lint.span_label(sp, "lbl")
    //          ^^^^^^^^^^^^^^^^^^^^^ returns `&mut DiagnosticBuilder` by default
)