Skip to content

Commit c9aa259

Browse files
committed
Auto merge of #84959 - camsteffen:lint-suggest-group, r=estebank
Suggest lint groups Fixes rust-lang/rust-clippy#6986
2 parents 6535449 + 25c66a1 commit c9aa259

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

compiler/rustc_lint/src/context.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -481,17 +481,17 @@ impl LintStore {
481481

482482
fn no_lint_suggestion(&self, lint_name: &str) -> CheckLintNameResult<'_> {
483483
let name_lower = lint_name.to_lowercase();
484-
let symbols =
485-
self.get_lints().iter().map(|l| Symbol::intern(&l.name_lower())).collect::<Vec<_>>();
486484

487485
if lint_name.chars().any(char::is_uppercase) && self.find_lints(&name_lower).is_ok() {
488486
// First check if the lint name is (partly) in upper case instead of lower case...
489-
CheckLintNameResult::NoLint(Some(Symbol::intern(&name_lower)))
490-
} else {
491-
// ...if not, search for lints with a similar name
492-
let suggestion = find_best_match_for_name(&symbols, Symbol::intern(&name_lower), None);
493-
CheckLintNameResult::NoLint(suggestion)
487+
return CheckLintNameResult::NoLint(Some(Symbol::intern(&name_lower)));
494488
}
489+
// ...if not, search for lints with a similar name
490+
let groups = self.lint_groups.keys().copied().map(Symbol::intern);
491+
let lints = self.lints.iter().map(|l| Symbol::intern(&l.name_lower()));
492+
let names: Vec<Symbol> = groups.chain(lints).collect();
493+
let suggestion = find_best_match_for_name(&names, Symbol::intern(&name_lower), None);
494+
CheckLintNameResult::NoLint(suggestion)
495495
}
496496

497497
fn check_tool_name_for_backwards_compat(

src/test/rustdoc-ui/unknown-renamed-lints.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ error: unknown lint: `rustdoc::x`
1414
--> $DIR/unknown-renamed-lints.rs:7:9
1515
|
1616
LL | #![deny(rustdoc::x)]
17-
| ^^^^^^^^^^
17+
| ^^^^^^^^^^ help: did you mean: `rustdoc::all`
1818

1919
error: lint `intra_doc_link_resolution_failure` has been renamed to `rustdoc::broken_intra_doc_links`
2020
--> $DIR/unknown-renamed-lints.rs:9:9

src/test/ui/lint/lint-unknown-lint.rs

+4
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@
66
//~| HELP did you mean
77
//~| SUGGESTION dead_code
88

9+
#![deny(rust_2018_idiots)] //~ ERROR unknown lint
10+
//~| HELP did you mean
11+
//~| SUGGESTION rust_2018_idioms
12+
913
fn main() {}

src/test/ui/lint/lint-unknown-lint.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,11 @@ error: unknown lint: `dead_cod`
1616
LL | #![deny(dead_cod)]
1717
| ^^^^^^^^ help: did you mean: `dead_code`
1818

19-
error: aborting due to 2 previous errors
19+
error: unknown lint: `rust_2018_idiots`
20+
--> $DIR/lint-unknown-lint.rs:9:9
21+
|
22+
LL | #![deny(rust_2018_idiots)]
23+
| ^^^^^^^^^^^^^^^^ help: did you mean: `rust_2018_idioms`
24+
25+
error: aborting due to 3 previous errors
2026

0 commit comments

Comments
 (0)