1+ #![ deny( rustc:: untranslatable_diagnostic) ]
2+ #![ deny( rustc:: diagnostic_outside_of_impl) ]
3+ use crate :: lints:: { NonFmtPanicBraces , NonFmtPanicUnused } ;
14use crate :: { LateContext , LateLintPass , LintContext } ;
25use rustc_ast as ast;
36use rustc_errors:: { fluent, Applicability } ;
@@ -118,6 +121,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
118121 arg_span = expn. call_site ;
119122 }
120123
124+ #[ allow( rustc:: diagnostic_outside_of_impl) ]
121125 cx. struct_span_lint ( NON_FMT_PANICS , arg_span, fluent:: lint_non_fmt_panic, |lint| {
122126 lint. set_arg ( "name" , symbol) ;
123127 lint. note ( fluent:: note) ;
@@ -253,25 +257,14 @@ fn check_panic_str<'tcx>(
253257 . map ( |span| fmt_span. from_inner ( InnerSpan :: new ( span. start , span. end ) ) )
254258 . collect ( ) ,
255259 } ;
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+ ) ;
275268 } else {
276269 let brace_spans: Option < Vec < _ > > =
277270 snippet. filter ( |s| s. starts_with ( '"' ) || s. starts_with ( "r#" ) ) . map ( |s| {
@@ -281,22 +274,12 @@ fn check_panic_str<'tcx>(
281274 . collect ( )
282275 } ) ;
283276 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 (
285278 NON_FMT_PANICS ,
286279 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 ( ) ) ,
300283 } ,
301284 ) ;
302285 }
0 commit comments