11//! Some lints that are only useful in the compiler or crates that use compiler internals, such as
22//! Clippy.
33
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+ } ;
410use crate :: { EarlyContext , EarlyLintPass , LateContext , LateLintPass , LintContext } ;
511use rustc_ast as ast;
6- use rustc_errors:: { fluent, Applicability } ;
712use rustc_hir:: def:: Res ;
813use rustc_hir:: { def_id:: DefId , Expr , ExprKind , GenericArg , PatKind , Path , PathSegment , QPath } ;
914use rustc_hir:: { HirId , Impl , Item , ItemKind , Node , Pat , Ty , TyKind } ;
@@ -29,20 +34,15 @@ impl LateLintPass<'_> for DefaultHashTypes {
2934 // don't lint imports, only actual usages
3035 return ;
3136 }
32- let replace = match cx. tcx . get_diagnostic_name ( def_id) {
37+ let preferred = match cx. tcx . get_diagnostic_name ( def_id) {
3338 Some ( sym:: HashMap ) => "FxHashMap" ,
3439 Some ( sym:: HashSet ) => "FxHashSet" ,
3540 _ => return ,
3641 } ;
37- cx. struct_span_lint (
42+ cx. emit_spanned_lint (
3843 DEFAULT_HASH_TYPES ,
3944 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) } ,
4646 ) ;
4747 }
4848}
@@ -83,12 +83,11 @@ impl LateLintPass<'_> for QueryStability {
8383 if let Ok ( Some ( instance) ) = ty:: Instance :: resolve ( cx. tcx , cx. param_env , def_id, substs) {
8484 let def_id = instance. def_id ( ) ;
8585 if cx. tcx . has_attr ( def_id, sym:: rustc_lint_query_instability) {
86- cx. struct_span_lint (
86+ cx. emit_spanned_lint (
8787 POTENTIAL_QUERY_INSTABILITY ,
8888 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+ ) ;
9291 }
9392 }
9493 }
@@ -126,14 +125,8 @@ impl<'tcx> LateLintPass<'tcx> for TyTyKind {
126125 let span = path. span . with_hi (
127126 segment. args . map_or ( segment. ident . span , |a| a. span_ext ) . hi ( )
128127 ) ;
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,
137130 } ) ;
138131 }
139132 }
@@ -190,39 +183,17 @@ impl<'tcx> LateLintPass<'tcx> for TyTyKind {
190183
191184 match span {
192185 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+ } ) ;
204189 } ,
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 ) ,
225191 }
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+ } ) ;
226197 }
227198 }
228199 _ => { }
@@ -303,12 +274,11 @@ impl EarlyLintPass for LintPassImpl {
303274 && call_site. ctxt ( ) . outer_expn_data ( ) . kind
304275 != ExpnKind :: Macro ( MacroKind :: Bang , sym:: declare_lint_pass)
305276 {
306- cx. struct_span_lint (
277+ cx. emit_spanned_lint (
307278 LINT_PASS_IMPL_WITHOUT_MACRO ,
308279 lint_pass. path . span ,
309- fluent:: lint_lintpass_by_hand,
310- |lint| lint. help ( fluent:: help) ,
311- )
280+ LintPassByHand ,
281+ ) ;
312282 }
313283 }
314284 }
@@ -338,17 +308,16 @@ impl<'tcx> LateLintPass<'tcx> for ExistingDocKeyword {
338308 if let Some ( list) = attr. meta_item_list ( ) {
339309 for nested in list {
340310 if nested. has_name ( sym:: keyword) {
341- let v = nested
311+ let keyword = nested
342312 . value_str ( )
343313 . expect ( "#[doc(keyword = \" ...\" )] expected a value!" ) ;
344- if is_doc_keyword ( v ) {
314+ if is_doc_keyword ( keyword ) {
345315 return ;
346316 }
347- cx. struct_span_lint (
317+ cx. emit_spanned_lint (
348318 EXISTING_DOC_KEYWORD ,
349319 attr. span ,
350- fluent:: lint_non_existant_doc_keyword,
351- |lint| lint. set_arg ( "keyword" , v) . help ( fluent:: help) ,
320+ NonExistantDocKeyword { keyword } ,
352321 ) ;
353322 }
354323 }
@@ -407,12 +376,7 @@ impl LateLintPass<'_> for Diagnostics {
407376 }
408377 debug ! ( ?found_impl) ;
409378 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 ) ;
416380 }
417381
418382 let mut found_diagnostic_message = false ;
@@ -428,12 +392,7 @@ impl LateLintPass<'_> for Diagnostics {
428392 }
429393 debug ! ( ?found_diagnostic_message) ;
430394 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 ) ;
437396 }
438397 }
439398}
@@ -465,9 +424,9 @@ impl LateLintPass<'_> for BadOptAccess {
465424 let Some ( lit) = item. lit ( ) &&
466425 let ast:: LitKind :: Str ( val, _) = lit. kind
467426 {
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+ } ) ;
471430 }
472431 }
473432 }
0 commit comments