Add emit_span_lint_lazy to lazily create LintDiagnostic structs
This commit is contained in:
@@ -524,6 +524,20 @@ pub trait LintContext {
|
||||
});
|
||||
}
|
||||
|
||||
/// Emit a lint at `span` from a lazily-constructed lint struct (some type that implements
|
||||
/// `LintDiagnostic`, typically generated by `#[derive(LintDiagnostic)]`).
|
||||
fn emit_span_lint_lazy<S: Into<MultiSpan>, L: for<'a> LintDiagnostic<'a, ()>>(
|
||||
&self,
|
||||
lint: &'static Lint,
|
||||
span: S,
|
||||
decorator: impl FnOnce() -> L,
|
||||
) {
|
||||
self.opt_span_lint(lint, Some(span), |lint| {
|
||||
let decorator = decorator();
|
||||
decorator.decorate_lint(lint);
|
||||
});
|
||||
}
|
||||
|
||||
/// Emit a lint at the appropriate level, with an associated span.
|
||||
///
|
||||
/// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
|
||||
|
||||
Reference in New Issue
Block a user