11use std:: ops:: ControlFlow ;
22
33use clippy_config:: Conf ;
4- use clippy_utils:: diagnostics:: span_lint_and_help ;
4+ use clippy_utils:: diagnostics:: span_lint_and_then ;
55use clippy_utils:: is_lint_allowed;
66use clippy_utils:: source:: walk_span_to_context;
77use clippy_utils:: visitors:: { for_each_expr, Descend } ;
@@ -129,13 +129,15 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
129129 block. span
130130 } ;
131131
132- span_lint_and_help (
132+ #[ expect( clippy:: collapsible_span_lint_calls, reason = "rust-clippy#7797" ) ]
133+ span_lint_and_then (
133134 cx,
134135 UNDOCUMENTED_UNSAFE_BLOCKS ,
135136 span,
136137 "unsafe block missing a safety comment" ,
137- None ,
138- "consider adding a safety comment on the preceding line" ,
138+ |diag| {
139+ diag. help ( "consider adding a safety comment on the preceding line" ) ;
140+ } ,
139141 ) ;
140142 }
141143
@@ -145,13 +147,14 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
145147 && let HasSafetyComment :: Yes ( pos) = stmt_has_safety_comment ( cx, tail. span , tail. hir_id )
146148 && let Some ( help_span) = expr_has_unnecessary_safety_comment ( cx, tail, pos)
147149 {
148- span_lint_and_help (
150+ span_lint_and_then (
149151 cx,
150152 UNNECESSARY_SAFETY_COMMENT ,
151153 tail. span ,
152154 "expression has unnecessary safety comment" ,
153- Some ( help_span) ,
154- "consider removing the safety comment" ,
155+ |diag| {
156+ diag. span_help ( help_span, "consider removing the safety comment" ) ;
157+ } ,
155158 ) ;
156159 }
157160 }
@@ -168,13 +171,14 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
168171 && let HasSafetyComment :: Yes ( pos) = stmt_has_safety_comment ( cx, stmt. span , stmt. hir_id )
169172 && let Some ( help_span) = expr_has_unnecessary_safety_comment ( cx, expr, pos)
170173 {
171- span_lint_and_help (
174+ span_lint_and_then (
172175 cx,
173176 UNNECESSARY_SAFETY_COMMENT ,
174177 stmt. span ,
175178 "statement has unnecessary safety comment" ,
176- Some ( help_span) ,
177- "consider removing the safety comment" ,
179+ |diag| {
180+ diag. span_help ( help_span, "consider removing the safety comment" ) ;
181+ } ,
178182 ) ;
179183 }
180184 }
@@ -210,13 +214,15 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
210214 item. span
211215 } ;
212216
213- span_lint_and_help (
217+ #[ expect( clippy:: collapsible_span_lint_calls, reason = "rust-clippy#7797" ) ]
218+ span_lint_and_then (
214219 cx,
215220 UNDOCUMENTED_UNSAFE_BLOCKS ,
216221 span,
217222 "unsafe impl missing a safety comment" ,
218- None ,
219- "consider adding a safety comment on the preceding line" ,
223+ |diag| {
224+ diag. help ( "consider adding a safety comment on the preceding line" ) ;
225+ } ,
220226 ) ;
221227 }
222228 } ,
@@ -225,13 +231,14 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
225231 if !is_lint_allowed ( cx, UNNECESSARY_SAFETY_COMMENT , item. hir_id ( ) ) {
226232 let ( span, help_span) = mk_spans ( pos) ;
227233
228- span_lint_and_help (
234+ span_lint_and_then (
229235 cx,
230236 UNNECESSARY_SAFETY_COMMENT ,
231237 span,
232238 "impl has unnecessary safety comment" ,
233- Some ( help_span) ,
234- "consider removing the safety comment" ,
239+ |diag| {
240+ diag. span_help ( help_span, "consider removing the safety comment" ) ;
241+ } ,
235242 ) ;
236243 }
237244 } ,
@@ -246,13 +253,14 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
246253 ) {
247254 let ( span, help_span) = mk_spans ( pos) ;
248255
249- span_lint_and_help (
256+ span_lint_and_then (
250257 cx,
251258 UNNECESSARY_SAFETY_COMMENT ,
252259 span,
253260 format ! ( "{} has unnecessary safety comment" , item. kind. descr( ) ) ,
254- Some ( help_span) ,
255- "consider removing the safety comment" ,
261+ |diag| {
262+ diag. span_help ( help_span, "consider removing the safety comment" ) ;
263+ } ,
256264 ) ;
257265 }
258266 }
@@ -263,13 +271,14 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
263271 if !is_lint_allowed ( cx, UNNECESSARY_SAFETY_COMMENT , item. hir_id ( ) ) {
264272 let ( span, help_span) = mk_spans ( pos) ;
265273
266- span_lint_and_help (
274+ span_lint_and_then (
267275 cx,
268276 UNNECESSARY_SAFETY_COMMENT ,
269277 span,
270278 format ! ( "{} has unnecessary safety comment" , item. kind. descr( ) ) ,
271- Some ( help_span) ,
272- "consider removing the safety comment" ,
279+ |diag| {
280+ diag. span_help ( help_span, "consider removing the safety comment" ) ;
281+ } ,
273282 ) ;
274283 }
275284 } ,
0 commit comments