diff options
| author | bors <bors@rust-lang.org> | 2017-09-02 08:38:12 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-09-02 08:38:12 +0000 |
| commit | efceda220e92f02f7a29a15e4cf56f5a3cdf1792 (patch) | |
| tree | 2dfe3452678baf9da43e2f406b77fbe978629220 | |
| parent | f861b6ee46465097eec266c160ac53e230df7cf0 (diff) | |
| parent | ba643fadfea11fe137f0fa231384fda1379c05ce (diff) | |
| download | rust-efceda220e92f02f7a29a15e4cf56f5a3cdf1792.tar.gz rust-efceda220e92f02f7a29a15e4cf56f5a3cdf1792.zip | |
Auto merge of #44104 - llogiq:lowercase-lints, r=nikomatsakis
add a lowercase suggestion to unknown_lints I recently wrote some tests for a clippy lint, copied the (uppercase) lint name into my test file and forgot to toggle the case. This PR adds a suggestion that would have saved me 10 minutes of debugging, so it's likely a net win 🙂 . Also it adds a UI test for the `unknown_lints` lint.
| -rw-r--r-- | src/librustc/lint/levels.rs | 20 | ||||
| -rw-r--r-- | src/test/ui/lint/not_found.rs | 21 | ||||
| -rw-r--r-- | src/test/ui/lint/not_found.stderr | 20 |
3 files changed, 58 insertions, 3 deletions
diff --git a/src/librustc/lint/levels.rs b/src/librustc/lint/levels.rs index ab086e5b8e9..c5863b5618f 100644 --- a/src/librustc/lint/levels.rs +++ b/src/librustc/lint/levels.rs @@ -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(); + } } } } diff --git a/src/test/ui/lint/not_found.rs b/src/test/ui/lint/not_found.rs new file mode 100644 index 00000000000..5cdc19823cf --- /dev/null +++ b/src/test/ui/lint/not_found.rs @@ -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. + +// 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!(); +} diff --git a/src/test/ui/lint/not_found.stderr b/src/test/ui/lint/not_found.stderr new file mode 100644 index 00000000000..73265845494 --- /dev/null +++ b/src/test/ui/lint/not_found.stderr @@ -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` + |
