|
| 1 | +use crate::errors::{ |
| 2 | + CheckNameDeprecated, CheckNameRemoved, CheckNameRenamed, CheckNameUnknown, |
| 3 | + CheckNameUnknownTool, RequestedLevel, UnsupportedGroup, |
| 4 | +}; |
1 | 5 | use crate::{
|
2 | 6 | builtin::MISSING_DOCS,
|
3 | 7 | context::{CheckLintNameResult, LintStore},
|
@@ -552,12 +556,56 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
552 | 556 |
|
553 | 557 | fn add_command_line(&mut self) {
|
554 | 558 | for &(ref lint_name, level) in &self.sess.opts.lint_opts {
|
555 |
| - self.store.check_lint_name_cmdline(self.sess, &lint_name, level, self.registered_tools); |
| 559 | + // Checks the validity of lint names derived from the command line. |
| 560 | + let (tool_name, lint_name_only) = parse_lint_and_tool_name(lint_name); |
| 561 | + if lint_name_only == crate::WARNINGS.name_lower() |
| 562 | + && matches!(level, Level::ForceWarn(_)) |
| 563 | + { |
| 564 | + self.sess.emit_err(UnsupportedGroup { lint_group: crate::WARNINGS.name_lower() }); |
| 565 | + } |
| 566 | + match self.store.check_lint_name(lint_name_only, tool_name, self.registered_tools) { |
| 567 | + CheckLintNameResult::Renamed(replace) => { |
| 568 | + self.sess.emit_warning(CheckNameRenamed { |
| 569 | + lint_name, |
| 570 | + replace: &replace, |
| 571 | + sub: RequestedLevel { level, lint_name }, |
| 572 | + }); |
| 573 | + } |
| 574 | + CheckLintNameResult::Removed(reason) => { |
| 575 | + self.sess.emit_warning(CheckNameRemoved { |
| 576 | + lint_name, |
| 577 | + reason: &reason, |
| 578 | + sub: RequestedLevel { level, lint_name }, |
| 579 | + }); |
| 580 | + } |
| 581 | + CheckLintNameResult::NoLint(suggestion) => { |
| 582 | + self.sess.emit_err(CheckNameUnknown { |
| 583 | + lint_name, |
| 584 | + suggestion, |
| 585 | + sub: RequestedLevel { level, lint_name }, |
| 586 | + }); |
| 587 | + } |
| 588 | + CheckLintNameResult::Tool(Err((Some(_), new_name))) => { |
| 589 | + self.sess.emit_warning(CheckNameDeprecated { |
| 590 | + lint_name, |
| 591 | + new_name: &new_name, |
| 592 | + sub: RequestedLevel { level, lint_name }, |
| 593 | + }); |
| 594 | + } |
| 595 | + CheckLintNameResult::NoTool => { |
| 596 | + self.sess.emit_err(CheckNameUnknownTool { |
| 597 | + tool_name: tool_name.unwrap(), |
| 598 | + sub: RequestedLevel { level, lint_name }, |
| 599 | + }); |
| 600 | + } |
| 601 | + _ => {} |
| 602 | + }; |
| 603 | + |
556 | 604 | let orig_level = level;
|
557 | 605 | let lint_flag_val = Symbol::intern(lint_name);
|
558 | 606 |
|
559 | 607 | let Ok(ids) = self.store.find_lints(&lint_name) else {
|
560 |
| - // errors handled in check_lint_name_cmdline above |
| 608 | + // errors already handled above |
561 | 609 | continue;
|
562 | 610 | };
|
563 | 611 | for id in ids {
|
@@ -1092,3 +1140,14 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
1092 | 1140 | pub(crate) fn provide(providers: &mut Providers) {
|
1093 | 1141 | *providers = Providers { shallow_lint_levels_on, lint_expectations, ..*providers };
|
1094 | 1142 | }
|
| 1143 | + |
| 1144 | +pub fn parse_lint_and_tool_name(lint_name: &str) -> (Option<Symbol>, &str) { |
| 1145 | + match lint_name.split_once("::") { |
| 1146 | + Some((tool_name, lint_name)) => { |
| 1147 | + let tool_name = Symbol::intern(tool_name); |
| 1148 | + |
| 1149 | + (Some(tool_name), lint_name) |
| 1150 | + } |
| 1151 | + None => (None, lint_name), |
| 1152 | + } |
| 1153 | +} |
0 commit comments