Skip to content

Commit dbb159a

Browse files
Remove usage of LintContext::span_lint in clippy
1 parent 86e6165 commit dbb159a

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

clippy_utils/src/diagnostics.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//! Thank you!
99
//! ~The `INTERNAL_METADATA_COLLECTOR` lint
1010
11-
use rustc_errors::{Applicability, Diag, DiagMessage, MultiSpan};
11+
use rustc_errors::{Applicability, Diag, Diagnostic, DiagCtxtHandle, DiagMessage, Level, MultiSpan};
1212
#[cfg(debug_assertions)]
1313
use rustc_errors::{EmissionGuarantee, SubstitutionPart, Suggestions};
1414
use rustc_hir::HirId;
@@ -240,15 +240,25 @@ where
240240
M: Into<DiagMessage>,
241241
F: FnOnce(&mut Diag<'_, ()>),
242242
{
243+
struct ClippyDiag<F: FnOnce(&mut Diag<'_, ()>)>(F);
244+
245+
impl<'a, F: FnOnce(&mut Diag<'_, ()>)> Diagnostic<'a, ()> for ClippyDiag<F> {
246+
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
247+
let mut lint = Diag::new(dcx, level, "");
248+
(self.0)(&mut lint);
249+
lint
250+
}
251+
}
252+
243253
#[expect(clippy::disallowed_methods)]
244-
cx.span_lint(lint, sp, |diag| {
254+
cx.emit_span_lint(lint, sp, ClippyDiag(|diag: &mut Diag<'_, ()>| {
245255
diag.primary_message(msg);
246256
f(diag);
247257
docs_link(diag, lint);
248258

249259
#[cfg(debug_assertions)]
250260
validate_diag(diag);
251-
});
261+
}));
252262
}
253263

254264
/// Like [`span_lint`], but emits the lint at the node identified by the given `HirId`.

0 commit comments

Comments
 (0)