1
1
use std:: ops:: ControlFlow ;
2
2
3
3
use clippy_config:: Conf ;
4
- use clippy_utils:: diagnostics:: span_lint_and_help ;
4
+ use clippy_utils:: diagnostics:: span_lint_and_then ;
5
5
use clippy_utils:: is_lint_allowed;
6
6
use clippy_utils:: source:: walk_span_to_context;
7
7
use clippy_utils:: visitors:: { for_each_expr, Descend } ;
@@ -129,13 +129,15 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
129
129
block. span
130
130
} ;
131
131
132
- span_lint_and_help (
132
+ #[ expect( clippy:: collapsible_span_lint_calls, reason = "rust-clippy#7797" ) ]
133
+ span_lint_and_then (
133
134
cx,
134
135
UNDOCUMENTED_UNSAFE_BLOCKS ,
135
136
span,
136
137
"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
+ } ,
139
141
) ;
140
142
}
141
143
@@ -145,13 +147,14 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
145
147
&& let HasSafetyComment :: Yes ( pos) = stmt_has_safety_comment ( cx, tail. span , tail. hir_id )
146
148
&& let Some ( help_span) = expr_has_unnecessary_safety_comment ( cx, tail, pos)
147
149
{
148
- span_lint_and_help (
150
+ span_lint_and_then (
149
151
cx,
150
152
UNNECESSARY_SAFETY_COMMENT ,
151
153
tail. span ,
152
154
"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
+ } ,
155
158
) ;
156
159
}
157
160
}
@@ -168,13 +171,14 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
168
171
&& let HasSafetyComment :: Yes ( pos) = stmt_has_safety_comment ( cx, stmt. span , stmt. hir_id )
169
172
&& let Some ( help_span) = expr_has_unnecessary_safety_comment ( cx, expr, pos)
170
173
{
171
- span_lint_and_help (
174
+ span_lint_and_then (
172
175
cx,
173
176
UNNECESSARY_SAFETY_COMMENT ,
174
177
stmt. span ,
175
178
"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
+ } ,
178
182
) ;
179
183
}
180
184
}
@@ -210,13 +214,15 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
210
214
item. span
211
215
} ;
212
216
213
- span_lint_and_help (
217
+ #[ expect( clippy:: collapsible_span_lint_calls, reason = "rust-clippy#7797" ) ]
218
+ span_lint_and_then (
214
219
cx,
215
220
UNDOCUMENTED_UNSAFE_BLOCKS ,
216
221
span,
217
222
"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
+ } ,
220
226
) ;
221
227
}
222
228
} ,
@@ -225,13 +231,14 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
225
231
if !is_lint_allowed ( cx, UNNECESSARY_SAFETY_COMMENT , item. hir_id ( ) ) {
226
232
let ( span, help_span) = mk_spans ( pos) ;
227
233
228
- span_lint_and_help (
234
+ span_lint_and_then (
229
235
cx,
230
236
UNNECESSARY_SAFETY_COMMENT ,
231
237
span,
232
238
"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
+ } ,
235
242
) ;
236
243
}
237
244
} ,
@@ -246,13 +253,14 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
246
253
) {
247
254
let ( span, help_span) = mk_spans ( pos) ;
248
255
249
- span_lint_and_help (
256
+ span_lint_and_then (
250
257
cx,
251
258
UNNECESSARY_SAFETY_COMMENT ,
252
259
span,
253
260
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
+ } ,
256
264
) ;
257
265
}
258
266
}
@@ -263,13 +271,14 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
263
271
if !is_lint_allowed ( cx, UNNECESSARY_SAFETY_COMMENT , item. hir_id ( ) ) {
264
272
let ( span, help_span) = mk_spans ( pos) ;
265
273
266
- span_lint_and_help (
274
+ span_lint_and_then (
267
275
cx,
268
276
UNNECESSARY_SAFETY_COMMENT ,
269
277
span,
270
278
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
+ } ,
273
282
) ;
274
283
}
275
284
} ,
0 commit comments