Skip to content

Commit 25c66a1

Browse files
committed
Suggest lint groups
1 parent 24acc38 commit 25c66a1

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
@@ -468,17 +468,17 @@ impl LintStore {
468468

469469
fn no_lint_suggestion(&self, lint_name: &str) -> CheckLintNameResult<'_> {
470470
let name_lower = lint_name.to_lowercase();
471-
let symbols =
472-
self.get_lints().iter().map(|l| Symbol::intern(&l.name_lower())).collect::<Vec<_>>();
473471

474472
if lint_name.chars().any(char::is_uppercase) && self.find_lints(&name_lower).is_ok() {
475473
// First check if the lint name is (partly) in upper case instead of lower case...
476-
CheckLintNameResult::NoLint(Some(Symbol::intern(&name_lower)))
477-
} else {
478-
// ...if not, search for lints with a similar name
479-
let suggestion = find_best_match_for_name(&symbols, Symbol::intern(&name_lower), None);
480-
CheckLintNameResult::NoLint(suggestion)
474+
return CheckLintNameResult::NoLint(Some(Symbol::intern(&name_lower)));
481475
}
476+
// ...if not, search for lints with a similar name
477+
let groups = self.lint_groups.keys().copied().map(Symbol::intern);
478+
let lints = self.lints.iter().map(|l| Symbol::intern(&l.name_lower()));
479+
let names: Vec<Symbol> = groups.chain(lints).collect();
480+
let suggestion = find_best_match_for_name(&names, Symbol::intern(&name_lower), None);
481+
CheckLintNameResult::NoLint(suggestion)
482482
}
483483

484484
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)