pub fn span_lint_and_note<T: LintContext>(
cx: &T,
lint: &'static Lint,
span: impl Into<MultiSpan>,
msg: impl Into<DiagMessage>,
note_span: Option<Span>,
note: impl Into<SubdiagMessage>,
)
Expand description
Like span_lint
but with a note
section instead of a help
message.
The note
message is presented separately from the main lint message
and is attached to a specific 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_note
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: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing.
--> tests/ui/drop_forget_ref.rs:10:5
|
10 | forget(&SomeStruct);
| ^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::forget-ref` implied by `-D warnings`
note: argument has type &SomeStruct
--> tests/ui/drop_forget_ref.rs:10:12
|
10 | forget(&SomeStruct);
| ^^^^^^^^^^^