1
+ #![ deny( rustc:: untranslatable_diagnostic) ]
2
+ #![ deny( rustc:: diagnostic_outside_of_impl) ]
3
+ use crate :: lints:: { NonFmtPanicBraces , NonFmtPanicUnused } ;
1
4
use crate :: { LateContext , LateLintPass , LintContext } ;
2
5
use rustc_ast as ast;
3
6
use rustc_errors:: { fluent, Applicability } ;
@@ -118,6 +121,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
118
121
arg_span = expn. call_site ;
119
122
}
120
123
124
+ #[ allow( rustc:: diagnostic_outside_of_impl) ]
121
125
cx. struct_span_lint ( NON_FMT_PANICS , arg_span, fluent:: lint_non_fmt_panic, |lint| {
122
126
lint. set_arg ( "name" , symbol) ;
123
127
lint. note ( fluent:: note) ;
@@ -253,25 +257,14 @@ fn check_panic_str<'tcx>(
253
257
. map ( |span| fmt_span. from_inner ( InnerSpan :: new ( span. start , span. end ) ) )
254
258
. collect ( ) ,
255
259
} ;
256
- cx. struct_span_lint ( NON_FMT_PANICS , arg_spans, fluent:: lint_non_fmt_panic_unused, |lint| {
257
- lint. set_arg ( "count" , n_arguments) ;
258
- lint. note ( fluent:: note) ;
259
- if is_arg_inside_call ( arg. span , span) {
260
- lint. span_suggestion (
261
- arg. span . shrink_to_hi ( ) ,
262
- fluent:: add_args_suggestion,
263
- ", ..." ,
264
- Applicability :: HasPlaceholders ,
265
- ) ;
266
- lint. span_suggestion (
267
- arg. span . shrink_to_lo ( ) ,
268
- fluent:: add_fmt_suggestion,
269
- "\" {}\" , " ,
270
- Applicability :: MachineApplicable ,
271
- ) ;
272
- }
273
- lint
274
- } ) ;
260
+ cx. emit_spanned_lint (
261
+ NON_FMT_PANICS ,
262
+ arg_spans,
263
+ NonFmtPanicUnused {
264
+ count : n_arguments,
265
+ suggestion : is_arg_inside_call ( arg. span , span) . then_some ( arg. span ) ,
266
+ } ,
267
+ ) ;
275
268
} else {
276
269
let brace_spans: Option < Vec < _ > > =
277
270
snippet. filter ( |s| s. starts_with ( '"' ) || s. starts_with ( "r#" ) ) . map ( |s| {
@@ -281,22 +274,12 @@ fn check_panic_str<'tcx>(
281
274
. collect ( )
282
275
} ) ;
283
276
let count = brace_spans. as_ref ( ) . map ( |v| v. len ( ) ) . unwrap_or ( /* any number >1 */ 2 ) ;
284
- cx. struct_span_lint (
277
+ cx. emit_spanned_lint (
285
278
NON_FMT_PANICS ,
286
279
brace_spans. unwrap_or_else ( || vec ! [ span] ) ,
287
- fluent:: lint_non_fmt_panic_braces,
288
- |lint| {
289
- lint. set_arg ( "count" , count) ;
290
- lint. note ( fluent:: note) ;
291
- if is_arg_inside_call ( arg. span , span) {
292
- lint. span_suggestion (
293
- arg. span . shrink_to_lo ( ) ,
294
- fluent:: suggestion,
295
- "\" {}\" , " ,
296
- Applicability :: MachineApplicable ,
297
- ) ;
298
- }
299
- lint
280
+ NonFmtPanicBraces {
281
+ count,
282
+ suggestion : is_arg_inside_call ( arg. span , span) . then_some ( arg. span . shrink_to_lo ( ) ) ,
300
283
} ,
301
284
) ;
302
285
}
0 commit comments