|
8 | 8 | //! Thank you! |
9 | 9 | //! ~The `INTERNAL_METADATA_COLLECTOR` lint |
10 | 10 |
|
11 | | -use rustc_errors::{Applicability, Diag, DiagMessage, MultiSpan}; |
| 11 | +use rustc_errors::{Applicability, Diag, Diagnostic, DiagCtxtHandle, DiagMessage, Level, MultiSpan}; |
12 | 12 | #[cfg(debug_assertions)] |
13 | 13 | use rustc_errors::{EmissionGuarantee, SubstitutionPart, Suggestions}; |
14 | 14 | use rustc_hir::HirId; |
@@ -240,15 +240,25 @@ where |
240 | 240 | M: Into<DiagMessage>, |
241 | 241 | F: FnOnce(&mut Diag<'_, ()>), |
242 | 242 | { |
| 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 | + |
243 | 253 | #[expect(clippy::disallowed_methods)] |
244 | | - cx.span_lint(lint, sp, |diag| { |
| 254 | + cx.emit_span_lint(lint, sp, ClippyDiag(|diag: &mut Diag<'_, ()>| { |
245 | 255 | diag.primary_message(msg); |
246 | 256 | f(diag); |
247 | 257 | docs_link(diag, lint); |
248 | 258 |
|
249 | 259 | #[cfg(debug_assertions)] |
250 | 260 | validate_diag(diag); |
251 | | - }); |
| 261 | + })); |
252 | 262 | } |
253 | 263 |
|
254 | 264 | /// Like [`span_lint`], but emits the lint at the node identified by the given `HirId`. |
|
0 commit comments