1+ // #![deny(rustc::diagnostic_outside_of_impl)]
2+ // #![deny(rustc::untranslatable_diagnostic)]
3+ //
14//! Implementation of lint checking.
25//!
36//! The lint checking is mostly consolidated into one pass which runs
1619
1720use self :: TargetLint :: * ;
1821
22+ use crate :: errors:: {
23+ CheckNameDeprecated , CheckNameUnknown , CheckNameUnknownTool , CheckNameWarning , RequestedLevel ,
24+ UnsupportedGroup ,
25+ } ;
1926use crate :: levels:: LintLevelsBuilder ;
2027use crate :: passes:: { EarlyLintPassObject , LateLintPassObject } ;
2128use rustc_ast:: util:: unicode:: TEXT_FLOW_CONTROL_CHARS ;
2229use rustc_data_structures:: fx:: FxHashMap ;
2330use 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;
2532use rustc_errors:: {
2633 Applicability , DecorateLint , LintDiagnosticBuilder , MultiSpan , SuggestionStyle ,
2734} ;
@@ -39,7 +46,7 @@ use rustc_session::lint::{FutureIncompatibleInfo, Level, Lint, LintBuffer, LintI
3946use rustc_session:: Session ;
4047use rustc_span:: lev_distance:: find_best_match_for_name;
4148use rustc_span:: symbol:: { sym, Ident , Symbol } ;
42- use rustc_span:: { BytePos , Span , DUMMY_SP } ;
49+ use rustc_span:: { BytePos , Span } ;
4350use rustc_target:: abi;
4451use tracing:: debug;
4552
@@ -326,68 +333,41 @@ impl LintStore {
326333 ) {
327334 let ( tool_name, lint_name_only) = parse_lint_and_tool_name ( lint_name) ;
328335 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 ( ) } ) ;
337337 return ;
338338 }
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+ }
342347 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+ } ) ;
348361 }
349-
350- Some ( err. forget_guarantee ( ) )
351362 }
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+ _ => { }
371370 } ;
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- }
391371 }
392372
393373 /// True if this symbol represents a lint group name.
0 commit comments