1
1
use crate :: { EarlyContext , EarlyLintPass , LateContext , LateLintPass , LintContext } ;
2
2
use rustc_ast as ast;
3
3
use rustc_attr as attr;
4
- use rustc_errors:: Applicability ;
4
+ use rustc_errors:: { fluent , Applicability } ;
5
5
use rustc_hir as hir;
6
6
use rustc_hir:: def:: { DefKind , Res } ;
7
7
use rustc_hir:: intravisit:: FnKind ;
@@ -137,22 +137,23 @@ impl NonCamelCaseTypes {
137
137
138
138
if !is_camel_case ( name) {
139
139
cx. struct_span_lint ( NON_CAMEL_CASE_TYPES , ident. span , |lint| {
140
- let msg = format ! ( "{} `{}` should have an upper camel case name" , sort, name) ;
141
- let mut err = lint. build ( & msg) ;
140
+ let mut err = lint. build ( fluent:: lint:: non_camel_case_type) ;
142
141
let cc = to_camel_case ( name) ;
143
142
// We cannot provide meaningful suggestions
144
143
// if the characters are in the category of "Lowercase Letter".
145
144
if * name != cc {
146
145
err. span_suggestion (
147
146
ident. span ,
148
- "convert the identifier to upper camel case" ,
147
+ fluent :: lint :: suggestion ,
149
148
to_camel_case ( name) ,
150
149
Applicability :: MaybeIncorrect ,
151
150
) ;
152
151
} else {
153
- err. span_label ( ident. span , "should have an UpperCamelCase name" ) ;
152
+ err. span_label ( ident. span , fluent :: lint :: label ) ;
154
153
}
155
154
155
+ err. set_arg ( "sort" , sort) ;
156
+ err. set_arg ( "name" , name) ;
156
157
err. emit ( ) ;
157
158
} )
158
159
}
@@ -281,11 +282,10 @@ impl NonSnakeCase {
281
282
if !is_snake_case ( name) {
282
283
cx. struct_span_lint ( NON_SNAKE_CASE , ident. span , |lint| {
283
284
let sc = NonSnakeCase :: to_snake_case ( name) ;
284
- let msg = format ! ( "{} `{}` should have a snake case name" , sort, name) ;
285
- let mut err = lint. build ( & msg) ;
285
+ let mut err = lint. build ( fluent:: lint:: non_snake_case) ;
286
286
// We cannot provide meaningful suggestions
287
287
// if the characters are in the category of "Uppercase Letter".
288
- if * name != sc {
288
+ if name != sc {
289
289
// We have a valid span in almost all cases, but we don't have one when linting a crate
290
290
// name provided via the command line.
291
291
if !ident. span . is_dummy ( ) {
@@ -295,13 +295,13 @@ impl NonSnakeCase {
295
295
// Instead, recommend renaming the identifier entirely or, if permitted,
296
296
// escaping it to create a raw identifier.
297
297
if sc_ident. name . can_be_raw ( ) {
298
- ( "rename the identifier or convert it to a snake case raw identifier" , sc_ident. to_string ( ) )
298
+ ( fluent :: lint :: rename_or_convert_suggestion , sc_ident. to_string ( ) )
299
299
} else {
300
- err. note ( & format ! ( "`{}` cannot be used as a raw identifier" , sc ) ) ;
301
- ( "rename the identifier" , String :: new ( ) )
300
+ err. note ( fluent :: lint :: cannot_convert_note ) ;
301
+ ( fluent :: lint :: rename_suggestion , String :: new ( ) )
302
302
}
303
303
} else {
304
- ( "convert the identifier to snake case" , sc)
304
+ ( fluent :: lint :: convert_suggestion , sc. clone ( ) )
305
305
} ;
306
306
307
307
err. span_suggestion (
@@ -311,12 +311,15 @@ impl NonSnakeCase {
311
311
Applicability :: MaybeIncorrect ,
312
312
) ;
313
313
} else {
314
- err. help ( & format ! ( "convert the identifier to snake case: `{}`" , sc ) ) ;
314
+ err. help ( fluent :: lint :: help ) ;
315
315
}
316
316
} else {
317
- err. span_label ( ident. span , "should have a snake_case name" ) ;
317
+ err. span_label ( ident. span , fluent :: lint :: label ) ;
318
318
}
319
319
320
+ err. set_arg ( "sort" , sort) ;
321
+ err. set_arg ( "name" , name) ;
322
+ err. set_arg ( "sc" , sc) ;
320
323
err. emit ( ) ;
321
324
} ) ;
322
325
}
@@ -488,21 +491,22 @@ impl NonUpperCaseGlobals {
488
491
if name. chars ( ) . any ( |c| c. is_lowercase ( ) ) {
489
492
cx. struct_span_lint ( NON_UPPER_CASE_GLOBALS , ident. span , |lint| {
490
493
let uc = NonSnakeCase :: to_snake_case ( & name) . to_uppercase ( ) ;
491
- let mut err =
492
- lint. build ( & format ! ( "{} `{}` should have an upper case name" , sort, name) ) ;
494
+ let mut err = lint. build ( fluent:: lint:: non_upper_case_global) ;
493
495
// We cannot provide meaningful suggestions
494
496
// if the characters are in the category of "Lowercase Letter".
495
497
if * name != uc {
496
498
err. span_suggestion (
497
499
ident. span ,
498
- "convert the identifier to upper case" ,
500
+ fluent :: lint :: suggestion ,
499
501
uc,
500
502
Applicability :: MaybeIncorrect ,
501
503
) ;
502
504
} else {
503
- err. span_label ( ident. span , "should have an UPPER_CASE name" ) ;
505
+ err. span_label ( ident. span , fluent :: lint :: label ) ;
504
506
}
505
507
508
+ err. set_arg ( "sort" , sort) ;
509
+ err. set_arg ( "name" , name) ;
506
510
err. emit ( ) ;
507
511
} )
508
512
}
0 commit comments