Skip to content

add a lowercase suggestion to unknown_lints #44104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/librustc/lint/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,27 @@ impl<'a> LintLevelsBuilder<'a> {
self.cur,
Some(&specs));
let msg = format!("unknown lint: `{}`", name);
lint::struct_lint_level(self.sess,
let mut db = lint::struct_lint_level(self.sess,
lint,
level,
src,
Some(li.span.into()),
&msg)
.emit();
&msg);
if name.as_str().chars().any(|c| c.is_uppercase()) {
let name_lower = name.as_str().to_lowercase();
if let CheckLintNameResult::NoLint =
store.check_lint_name(&name_lower) {
db.emit();
} else {
db.span_suggestion(
li.span,
"lowercase the lint name",
name_lower
).emit();
}
} else {
db.emit();
}
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/test/ui/lint/not_found.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2014–2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment explaining the purpose of this test is to test the "lint case" suggestion?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

// this tests the `unknown_lint` lint, especially the suggestions

// the suggestion only appears if a lint with the lowercase name exists
#[allow(FOO_BAR)]
// the suggestion appears on all-uppercase names
#[warn(DEAD_CODE)]
// the suggestion appears also on mixed-case names
#[deny(Warnings)]
fn main() {
unimplemented!();
}
20 changes: 20 additions & 0 deletions src/test/ui/lint/not_found.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
warning: unknown lint: `FOO_BAR`
--> $DIR/not_found.rs:14:9
|
14 | #[allow(FOO_BAR)]
| ^^^^^^^
|
= note: #[warn(unknown_lints)] on by default

warning: unknown lint: `DEAD_CODE`
--> $DIR/not_found.rs:16:8
|
16 | #[warn(DEAD_CODE)]
| ^^^^^^^^^ help: lowercase the lint name: `dead_code`

warning: unknown lint: `Warnings`
--> $DIR/not_found.rs:18:8
|
18 | #[deny(Warnings)]
| ^^^^^^^^ help: lowercase the lint name: `warnings`