pub fn span_lint<T: LintContext>(
cx: &T,
lint: &'static Lint,
sp: impl Into<MultiSpan>,
msg: impl Into<DiagMessage>,
)
Expand description
Emit a basic lint message with a msg
and a span
.
This is the most primitive of our lint emission methods and can be a good way to get a new lint started.
Usually it’s nicer to provide more context for lint messages. Be sure the output is understandable when you use this method.
NOTE: Lint emissions are always bound to a node in the HIR, which is used to determine
the lint level.
For the span_lint
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
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
instead.
§Example
error: usage of mem::forget on Drop type
--> tests/ui/mem_forget.rs:17:5
|
17 | std::mem::forget(seven);
| ^^^^^^^^^^^^^^^^^^^^^^^