1
+ // #![deny(rustc::diagnostic_outside_of_impl)]
2
+ // #![deny(rustc::untranslatable_diagnostic)]
3
+ //
1
4
//! Implementation of lint checking.
2
5
//!
3
6
//! The lint checking is mostly consolidated into one pass which runs
16
19
17
20
use self :: TargetLint :: * ;
18
21
22
+ use crate :: errors:: {
23
+ CheckNameDeprecated , CheckNameUnknown , CheckNameUnknownTool , CheckNameWarning , RequestedLevel ,
24
+ UnsupportedGroup ,
25
+ } ;
19
26
use crate :: levels:: LintLevelsBuilder ;
20
27
use crate :: passes:: { EarlyLintPassObject , LateLintPassObject } ;
21
28
use rustc_ast:: util:: unicode:: TEXT_FLOW_CONTROL_CHARS ;
22
29
use rustc_data_structures:: fx:: FxHashMap ;
23
30
use rustc_data_structures:: sync;
24
- use rustc_errors:: { add_elided_lifetime_in_path_suggestion, struct_span_err } ;
31
+ use rustc_errors:: add_elided_lifetime_in_path_suggestion;
25
32
use rustc_errors:: {
26
33
Applicability , DecorateLint , LintDiagnosticBuilder , MultiSpan , SuggestionStyle ,
27
34
} ;
@@ -39,7 +46,7 @@ use rustc_session::lint::{FutureIncompatibleInfo, Level, Lint, LintBuffer, LintI
39
46
use rustc_session:: Session ;
40
47
use rustc_span:: lev_distance:: find_best_match_for_name;
41
48
use rustc_span:: symbol:: { sym, Ident , Symbol } ;
42
- use rustc_span:: { BytePos , Span , DUMMY_SP } ;
49
+ use rustc_span:: { BytePos , Span } ;
43
50
use rustc_target:: abi;
44
51
use tracing:: debug;
45
52
@@ -326,68 +333,41 @@ impl LintStore {
326
333
) {
327
334
let ( tool_name, lint_name_only) = parse_lint_and_tool_name ( lint_name) ;
328
335
if lint_name_only == crate :: WARNINGS . name_lower ( ) && matches ! ( level, Level :: ForceWarn ( _) ) {
329
- struct_span_err ! (
330
- sess,
331
- DUMMY_SP ,
332
- E0602 ,
333
- "`{}` lint group is not supported with ´--force-warn´" ,
334
- crate :: WARNINGS . name_lower( )
335
- )
336
- . emit ( ) ;
336
+ sess. emit_err ( UnsupportedGroup { lint_group : crate :: WARNINGS . name_lower ( ) } ) ;
337
337
return ;
338
338
}
339
- let db = match self . check_lint_name ( lint_name_only, tool_name, registered_tools) {
340
- CheckLintNameResult :: Ok ( _) => None ,
341
- CheckLintNameResult :: Warning ( ref msg, _) => Some ( sess. struct_warn ( msg) ) ,
339
+ let lint_name = lint_name. to_string ( ) ;
340
+ match self . check_lint_name ( lint_name_only, tool_name, registered_tools) {
341
+ CheckLintNameResult :: Warning ( msg, _) => {
342
+ sess. emit_warning ( CheckNameWarning {
343
+ msg,
344
+ sub : RequestedLevel { level, lint_name } ,
345
+ } ) ;
346
+ }
342
347
CheckLintNameResult :: NoLint ( suggestion) => {
343
- let mut err =
344
- struct_span_err ! ( sess, DUMMY_SP , E0602 , "unknown lint: `{}`" , lint_name) ;
345
-
346
- if let Some ( suggestion) = suggestion {
347
- err. help ( & format ! ( "did you mean: `{}`" , suggestion) ) ;
348
+ sess. emit_err ( CheckNameUnknown {
349
+ lint_name : lint_name. clone ( ) ,
350
+ suggestion,
351
+ sub : RequestedLevel { level, lint_name } ,
352
+ } ) ;
353
+ }
354
+ CheckLintNameResult :: Tool ( result) => {
355
+ if let Err ( ( Some ( _) , new_name) ) = result {
356
+ sess. emit_warning ( CheckNameDeprecated {
357
+ lint_name : lint_name. clone ( ) ,
358
+ new_name,
359
+ sub : RequestedLevel { level, lint_name } ,
360
+ } ) ;
348
361
}
349
-
350
- Some ( err. forget_guarantee ( ) )
351
362
}
352
- CheckLintNameResult :: Tool ( result) => match result {
353
- Err ( ( Some ( _) , new_name) ) => Some ( sess. struct_warn ( & format ! (
354
- "lint name `{}` is deprecated \
355
- and does not have an effect anymore. \
356
- Use: {}",
357
- lint_name, new_name
358
- ) ) ) ,
359
- _ => None ,
360
- } ,
361
- CheckLintNameResult :: NoTool => Some (
362
- struct_span_err ! (
363
- sess,
364
- DUMMY_SP ,
365
- E0602 ,
366
- "unknown lint tool: `{}`" ,
367
- tool_name. unwrap( )
368
- )
369
- . forget_guarantee ( ) ,
370
- ) ,
363
+ CheckLintNameResult :: NoTool => {
364
+ sess. emit_err ( CheckNameUnknownTool {
365
+ tool_name : tool_name. unwrap ( ) ,
366
+ sub : RequestedLevel { level, lint_name } ,
367
+ } ) ;
368
+ }
369
+ _ => { }
371
370
} ;
372
-
373
- if let Some ( mut db) = db {
374
- let msg = format ! (
375
- "requested on the command line with `{} {}`" ,
376
- match level {
377
- Level :: Allow => "-A" ,
378
- Level :: Warn => "-W" ,
379
- Level :: ForceWarn ( _) => "--force-warn" ,
380
- Level :: Deny => "-D" ,
381
- Level :: Forbid => "-F" ,
382
- Level :: Expect ( _) => {
383
- unreachable!( "lints with the level of `expect` should not run this code" ) ;
384
- }
385
- } ,
386
- lint_name
387
- ) ;
388
- db. note ( & msg) ;
389
- db. emit ( ) ;
390
- }
391
371
}
392
372
393
373
/// True if this symbol represents a lint group name.
0 commit comments