1
1
//! Some lints that are only useful in the compiler or crates that use compiler internals, such as
2
2
//! Clippy.
3
3
4
+ #![ deny( rustc:: untranslatable_diagnostic) ]
5
+ #![ deny( rustc:: diagnostic_outside_of_impl) ]
6
+ use crate :: lints:: {
7
+ BadOptAccessDiag , DefaultHashTypesDiag , DiagOutOfImpl , LintPassByHand , NonExistantDocKeyword ,
8
+ QueryInstability , TyQualified , TykindDiag , TykindKind , UntranslatableDiag ,
9
+ } ;
4
10
use crate :: { EarlyContext , EarlyLintPass , LateContext , LateLintPass , LintContext } ;
5
11
use rustc_ast as ast;
6
- use rustc_errors:: { fluent, Applicability } ;
7
12
use rustc_hir:: def:: Res ;
8
13
use rustc_hir:: { def_id:: DefId , Expr , ExprKind , GenericArg , PatKind , Path , PathSegment , QPath } ;
9
14
use rustc_hir:: { HirId , Impl , Item , ItemKind , Node , Pat , Ty , TyKind } ;
@@ -29,20 +34,15 @@ impl LateLintPass<'_> for DefaultHashTypes {
29
34
// don't lint imports, only actual usages
30
35
return ;
31
36
}
32
- let replace = match cx. tcx . get_diagnostic_name ( def_id) {
37
+ let preferred = match cx. tcx . get_diagnostic_name ( def_id) {
33
38
Some ( sym:: HashMap ) => "FxHashMap" ,
34
39
Some ( sym:: HashSet ) => "FxHashSet" ,
35
40
_ => return ,
36
41
} ;
37
- cx. struct_span_lint (
42
+ cx. emit_spanned_lint (
38
43
DEFAULT_HASH_TYPES ,
39
44
path. span ,
40
- fluent:: lint_default_hash_types,
41
- |lint| {
42
- lint. set_arg ( "preferred" , replace)
43
- . set_arg ( "used" , cx. tcx . item_name ( def_id) )
44
- . note ( fluent:: note)
45
- } ,
45
+ DefaultHashTypesDiag { preferred, used : cx. tcx . item_name ( def_id) } ,
46
46
) ;
47
47
}
48
48
}
@@ -83,12 +83,11 @@ impl LateLintPass<'_> for QueryStability {
83
83
if let Ok ( Some ( instance) ) = ty:: Instance :: resolve ( cx. tcx , cx. param_env , def_id, substs) {
84
84
let def_id = instance. def_id ( ) ;
85
85
if cx. tcx . has_attr ( def_id, sym:: rustc_lint_query_instability) {
86
- cx. struct_span_lint (
86
+ cx. emit_spanned_lint (
87
87
POTENTIAL_QUERY_INSTABILITY ,
88
88
span,
89
- fluent:: lint_query_instability,
90
- |lint| lint. set_arg ( "query" , cx. tcx . item_name ( def_id) ) . note ( fluent:: note) ,
91
- )
89
+ QueryInstability { query : cx. tcx . item_name ( def_id) } ,
90
+ ) ;
92
91
}
93
92
}
94
93
}
@@ -126,14 +125,8 @@ impl<'tcx> LateLintPass<'tcx> for TyTyKind {
126
125
let span = path. span . with_hi (
127
126
segment. args . map_or ( segment. ident . span , |a| a. span_ext ) . hi ( )
128
127
) ;
129
- cx. struct_span_lint ( USAGE_OF_TY_TYKIND , path. span , fluent:: lint_tykind_kind, |lint| {
130
- lint
131
- . span_suggestion (
132
- span,
133
- fluent:: suggestion,
134
- "ty" ,
135
- Applicability :: MaybeIncorrect , // ty maybe needs an import
136
- )
128
+ cx. emit_spanned_lint ( USAGE_OF_TY_TYKIND , path. span , TykindKind {
129
+ suggestion : span,
137
130
} ) ;
138
131
}
139
132
}
@@ -190,39 +183,17 @@ impl<'tcx> LateLintPass<'tcx> for TyTyKind {
190
183
191
184
match span {
192
185
Some ( span) => {
193
- cx. struct_span_lint (
194
- USAGE_OF_TY_TYKIND ,
195
- path. span ,
196
- fluent:: lint_tykind_kind,
197
- |lint| lint. span_suggestion (
198
- span,
199
- fluent:: suggestion,
200
- "ty" ,
201
- Applicability :: MaybeIncorrect , // ty maybe needs an import
202
- )
203
- )
186
+ cx. emit_spanned_lint ( USAGE_OF_TY_TYKIND , path. span , TykindKind {
187
+ suggestion : span,
188
+ } ) ;
204
189
} ,
205
- None => cx. struct_span_lint (
206
- USAGE_OF_TY_TYKIND ,
207
- path. span ,
208
- fluent:: lint_tykind,
209
- |lint| lint. help ( fluent:: help)
210
- )
211
- }
212
- } else if !ty. span . from_expansion ( ) && let Some ( t) = is_ty_or_ty_ctxt ( cx, & path) {
213
- if path. segments . len ( ) > 1 {
214
- cx. struct_span_lint ( USAGE_OF_QUALIFIED_TY , path. span , fluent:: lint_ty_qualified, |lint| {
215
- lint
216
- . set_arg ( "ty" , t. clone ( ) )
217
- . span_suggestion (
218
- path. span ,
219
- fluent:: suggestion,
220
- t,
221
- // The import probably needs to be changed
222
- Applicability :: MaybeIncorrect ,
223
- )
224
- } )
190
+ None => cx. emit_spanned_lint ( USAGE_OF_TY_TYKIND , path. span , TykindDiag ) ,
225
191
}
192
+ } else if !ty. span . from_expansion ( ) && path. segments . len ( ) > 1 && let Some ( t) = is_ty_or_ty_ctxt ( cx, & path) {
193
+ cx. emit_spanned_lint ( USAGE_OF_QUALIFIED_TY , path. span , TyQualified {
194
+ ty : t. clone ( ) ,
195
+ suggestion : path. span ,
196
+ } ) ;
226
197
}
227
198
}
228
199
_ => { }
@@ -303,12 +274,11 @@ impl EarlyLintPass for LintPassImpl {
303
274
&& call_site. ctxt ( ) . outer_expn_data ( ) . kind
304
275
!= ExpnKind :: Macro ( MacroKind :: Bang , sym:: declare_lint_pass)
305
276
{
306
- cx. struct_span_lint (
277
+ cx. emit_spanned_lint (
307
278
LINT_PASS_IMPL_WITHOUT_MACRO ,
308
279
lint_pass. path . span ,
309
- fluent:: lint_lintpass_by_hand,
310
- |lint| lint. help ( fluent:: help) ,
311
- )
280
+ LintPassByHand ,
281
+ ) ;
312
282
}
313
283
}
314
284
}
@@ -338,17 +308,16 @@ impl<'tcx> LateLintPass<'tcx> for ExistingDocKeyword {
338
308
if let Some ( list) = attr. meta_item_list ( ) {
339
309
for nested in list {
340
310
if nested. has_name ( sym:: keyword) {
341
- let v = nested
311
+ let keyword = nested
342
312
. value_str ( )
343
313
. expect ( "#[doc(keyword = \" ...\" )] expected a value!" ) ;
344
- if is_doc_keyword ( v ) {
314
+ if is_doc_keyword ( keyword ) {
345
315
return ;
346
316
}
347
- cx. struct_span_lint (
317
+ cx. emit_spanned_lint (
348
318
EXISTING_DOC_KEYWORD ,
349
319
attr. span ,
350
- fluent:: lint_non_existant_doc_keyword,
351
- |lint| lint. set_arg ( "keyword" , v) . help ( fluent:: help) ,
320
+ NonExistantDocKeyword { keyword } ,
352
321
) ;
353
322
}
354
323
}
@@ -407,12 +376,7 @@ impl LateLintPass<'_> for Diagnostics {
407
376
}
408
377
debug ! ( ?found_impl) ;
409
378
if !found_parent_with_attr && !found_impl {
410
- cx. struct_span_lint (
411
- DIAGNOSTIC_OUTSIDE_OF_IMPL ,
412
- span,
413
- fluent:: lint_diag_out_of_impl,
414
- |lint| lint,
415
- )
379
+ cx. emit_spanned_lint ( DIAGNOSTIC_OUTSIDE_OF_IMPL , span, DiagOutOfImpl ) ;
416
380
}
417
381
418
382
let mut found_diagnostic_message = false ;
@@ -428,12 +392,7 @@ impl LateLintPass<'_> for Diagnostics {
428
392
}
429
393
debug ! ( ?found_diagnostic_message) ;
430
394
if !found_parent_with_attr && !found_diagnostic_message {
431
- cx. struct_span_lint (
432
- UNTRANSLATABLE_DIAGNOSTIC ,
433
- span,
434
- fluent:: lint_untranslatable_diag,
435
- |lint| lint,
436
- )
395
+ cx. emit_spanned_lint ( UNTRANSLATABLE_DIAGNOSTIC , span, UntranslatableDiag ) ;
437
396
}
438
397
}
439
398
}
@@ -465,9 +424,9 @@ impl LateLintPass<'_> for BadOptAccess {
465
424
let Some ( lit) = item. lit ( ) &&
466
425
let ast:: LitKind :: Str ( val, _) = lit. kind
467
426
{
468
- cx. struct_span_lint ( BAD_OPT_ACCESS , expr. span , val . as_str ( ) , |lint|
469
- lint
470
- ) ;
427
+ cx. emit_spanned_lint ( BAD_OPT_ACCESS , expr. span , BadOptAccessDiag {
428
+ msg : val . as_str ( ) ,
429
+ } ) ;
471
430
}
472
431
}
473
432
}
0 commit comments