clippy_utils::diagnostics

Function span_lint_and_help

source
pub fn span_lint_and_help<T: LintContext>(
    cx: &T,
    lint: &'static Lint,
    span: impl Into<MultiSpan>,
    msg: impl Into<DiagMessage>,
    help_span: Option<Span>,
    help: impl Into<SubdiagMessage>,
)
Expand description

Same as span_lint but with an extra help message.

Use this if you want to provide some general help but can’t provide a specific machine applicable suggestion.

The help message can be optionally attached to a Span.

If you change the signature, remember to update the internal lint CollapsibleCalls

NOTE: Lint emissions are always bound to a node in the HIR, which is used to determine the lint level. For the span_lint_and_help function, the node that was passed into the LintPass::check_* function is used.

If you’re emitting the lint at the span of a different node than the one provided by the LintPass::check_* function, consider using span_lint_hir_and_then instead. This is needed for #[allow] and #[expect] attributes to work on the node highlighted in the displayed warning.

If you’re unsure which function you should use, you can test if the #[allow] attribute works where you would expect it to. If it doesn’t, you likely need to use span_lint_hir_and_then instead.

§Example

error: constant division of 0.0 with 0.0 will always result in NaN
  --> tests/ui/zero_div_zero.rs:6:25
   |
6  |     let other_f64_nan = 0.0f64 / 0.0;
   |                         ^^^^^^^^^^^^
   |
   = help: consider using `f64::NAN` if you would like a constant representing NaN