diff --git a/clippy_utils/src/diagnostics.rs b/clippy_utils/src/diagnostics.rs index 4ba9af58f90a..81b06ea0c539 100644 --- a/clippy_utils/src/diagnostics.rs +++ b/clippy_utils/src/diagnostics.rs @@ -104,14 +104,7 @@ fn validate_diag(diag: &Diag<'_, impl EmissionGuarantee>) { /// ``` #[track_caller] pub fn span_lint(cx: &T, lint: &'static Lint, sp: impl Into, msg: impl Into) { - #[expect(clippy::disallowed_methods)] - cx.span_lint(lint, sp, |diag| { - diag.primary_message(msg); - docs_link(diag, lint); - - #[cfg(debug_assertions)] - validate_diag(diag); - }); + span_lint_and_then(cx, lint, sp, msg, |_| {}); } /// Same as [`span_lint`] but with an extra `help` message. @@ -157,18 +150,12 @@ pub fn span_lint_and_help( help_span: Option, help: impl Into, ) { - #[expect(clippy::disallowed_methods)] - cx.span_lint(lint, span, |diag| { - diag.primary_message(msg); + span_lint_and_then(cx, lint, span, msg, |diag| { if let Some(help_span) = help_span { diag.span_help(help_span, help.into()); } else { diag.help(help.into()); } - docs_link(diag, lint); - - #[cfg(debug_assertions)] - validate_diag(diag); }); } @@ -218,18 +205,12 @@ pub fn span_lint_and_note( note_span: Option, note: impl Into, ) { - #[expect(clippy::disallowed_methods)] - cx.span_lint(lint, span, |diag| { - diag.primary_message(msg); + span_lint_and_then(cx, lint, span, msg, |diag| { if let Some(note_span) = note_span { diag.span_note(note_span, note.into()); } else { diag.note(note.into()); } - docs_link(diag, lint); - - #[cfg(debug_assertions)] - validate_diag(diag); }); } @@ -296,14 +277,7 @@ pub fn span_lint_and_then(cx: &C, lint: &'static Lint, sp: S, msg: M /// the `#[allow]` will work. #[track_caller] pub fn span_lint_hir(cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, sp: Span, msg: impl Into) { - #[expect(clippy::disallowed_methods)] - cx.tcx.node_span_lint(lint, hir_id, sp, |diag| { - diag.primary_message(msg); - docs_link(diag, lint); - - #[cfg(debug_assertions)] - validate_diag(diag); - }); + span_lint_hir_and_then(cx, lint, hir_id, sp, msg, |_| {}); } /// Like [`span_lint_and_then`], but emits the lint at the node identified by the given `HirId`. @@ -383,7 +357,6 @@ pub fn span_lint_hir_and_then( /// | /// = note: `-D fold-any` implied by `-D warnings` /// ``` -#[cfg_attr(not(debug_assertions), expect(clippy::collapsible_span_lint_calls))] #[track_caller] pub fn span_lint_and_sugg( cx: &T, @@ -397,7 +370,9 @@ pub fn span_lint_and_sugg( span_lint_and_then(cx, lint, sp, msg.into(), |diag| { diag.span_suggestion(sp, help.into(), sugg, applicability); - #[cfg(debug_assertions)] - validate_diag(diag); + // This dummy construct is here to prevent the internal `clippy::collapsible_span_lint_calls` + // lint from triggering. We don't want to allow/expect it as internal lints might or might + // not be activated when linting, and we don't want an unknown lint warning either. + std::hint::black_box(()); }); }