diff options
| author | Zack M. Davis <code@zackmdavis.net> | 2017-01-05 18:55:43 -0800 |
|---|---|---|
| committer | Zack M. Davis <code@zackmdavis.net> | 2017-02-04 10:51:11 -0800 |
| commit | 93014467f83435d4721616f9b5e4417fc01623aa (patch) | |
| tree | 4c96e47549ddc16d61d9c8e73f87104cb2c3b30e | |
| parent | 65b05541432c1fe7b75fb2dd3b020f933f3b5f4b (diff) | |
| download | rust-93014467f83435d4721616f9b5e4417fc01623aa.tar.gz rust-93014467f83435d4721616f9b5e4417fc01623aa.zip | |
note lint group set on command line triggering individual lint
Previously, the note/message for the source of a lint being the command line unconditionally named the individual lint, even if the actual command specified a lint group (e.g., `-D warnings`); here, we take note of the actual command options so we can be more specific. This remains in the matter of #36846.
| -rw-r--r-- | src/librustc/lint/context.rs | 28 | ||||
| -rw-r--r-- | src/librustc/lint/mod.rs | 3 | ||||
| -rw-r--r-- | src/test/compile-fail/lint-output-format-2.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/lint/command-line-lint-group-allow.rs | 15 | ||||
| -rw-r--r-- | src/test/ui/lint/command-line-lint-group-deny.rs | 15 | ||||
| -rw-r--r-- | src/test/ui/lint/command-line-lint-group-deny.stderr | 10 | ||||
| -rw-r--r-- | src/test/ui/lint/command-line-lint-group-forbid.rs | 15 | ||||
| -rw-r--r-- | src/test/ui/lint/command-line-lint-group-forbid.stderr | 10 | ||||
| -rw-r--r-- | src/test/ui/lint/command-line-lint-group-warn.rs | 15 | ||||
| -rw-r--r-- | src/test/ui/lint/command-line-lint-group-warn.stderr | 8 |
10 files changed, 110 insertions, 11 deletions
diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 62f19412d52..28600e3ab8e 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -43,6 +43,7 @@ use std::fmt; use std::ops::Deref; use syntax::attr; use syntax::ast; +use syntax::symbol::Symbol; use syntax_pos::{MultiSpan, Span}; use errors::{self, Diagnostic, DiagnosticBuilder}; use hir; @@ -300,8 +301,9 @@ impl LintStore { check_lint_name_cmdline(sess, self, &lint_name[..], level); + let lint_flag_val = Symbol::intern(&lint_name); match self.find_lint(&lint_name[..], sess, None) { - Ok(lint_id) => self.set_level(lint_id, (level, CommandLine)), + Ok(lint_id) => self.set_level(lint_id, (level, CommandLine(lint_flag_val))), Err(FindLintError::Removed) => { } Err(_) => { match self.lint_groups.iter().map(|(&x, pair)| (x, pair.0.clone())) @@ -311,7 +313,7 @@ impl LintStore { Some(v) => { v.iter() .map(|lint_id: &LintId| - self.set_level(*lint_id, (level, CommandLine))) + self.set_level(*lint_id, (level, CommandLine(lint_flag_val)))) .collect::<Vec<()>>(); } None => { @@ -470,12 +472,20 @@ pub fn raw_struct_lint<'a, S>(sess: &'a Session, Default => { err.note(&format!("#[{}({})] on by default", level.as_str(), name)); }, - CommandLine => { - err.note(&format!("[-{} {}]", - match level { - Warn => 'W', Deny => 'D', Forbid => 'F', - Allow => bug!() - }, name.replace("_", "-"))); + CommandLine(lint_flag_val) => { + let flag = match level { + Warn => "-W", Deny => "-D", Forbid => "-F", + Allow => bug!("earlier conditional return should handle Allow case") + }; + let hyphen_case_lint_name = name.replace("_", "-"); + if lint_flag_val.as_str().deref() == name { + err.note(&format!("requested on the command line with `{} {}`", + flag, hyphen_case_lint_name)); + } else { + let hyphen_case_flag_val = lint_flag_val.as_str().replace("_", "-"); + err.note(&format!("`{} {}` implies `{} {}`", + flag, hyphen_case_flag_val, flag, hyphen_case_lint_name)); + } }, Node(lint_attr_name, src) => { def = Some(src); @@ -671,7 +681,7 @@ pub trait LintContext<'tcx>: Sized { diag_builder.span_label(forbid_source_span, &format!("`forbid` level set here")) }, - LintSource::CommandLine => { + LintSource::CommandLine(_) => { diag_builder.note("`forbid` lint level was set on command line") } }.emit() diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 9c2a892a5fc..e9f603db15d 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -38,6 +38,7 @@ use std::ascii::AsciiExt; use syntax_pos::Span; use syntax::visit as ast_visit; use syntax::ast; +use syntax::symbol::Symbol; pub use lint::context::{LateContext, EarlyContext, LintContext, LintStore, raw_emit_lint, check_crate, check_ast_crate, gather_attrs, @@ -341,7 +342,7 @@ pub enum LintSource { Node(ast::Name, Span), /// Lint level was set by a command-line flag. - CommandLine, + CommandLine(Symbol), } pub type LevelSource = (Level, LintSource); diff --git a/src/test/compile-fail/lint-output-format-2.rs b/src/test/compile-fail/lint-output-format-2.rs index 8b76bedb003..0e68ff752e5 100644 --- a/src/test/compile-fail/lint-output-format-2.rs +++ b/src/test/compile-fail/lint-output-format-2.rs @@ -13,7 +13,7 @@ #![feature(foo)] //~^ ERROR unused or unknown feature -//~| NOTE [-F unused-features] +//~| NOTE requested on the command line with `-F unused-features` #![feature(test_feature)] diff --git a/src/test/ui/lint/command-line-lint-group-allow.rs b/src/test/ui/lint/command-line-lint-group-allow.rs new file mode 100644 index 00000000000..cdb9684933d --- /dev/null +++ b/src/test/ui/lint/command-line-lint-group-allow.rs @@ -0,0 +1,15 @@ +// Copyright 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. + +// compile-flags: -A bad-style + +fn main() { + let _InappropriateCamelCasing = true; +} diff --git a/src/test/ui/lint/command-line-lint-group-deny.rs b/src/test/ui/lint/command-line-lint-group-deny.rs new file mode 100644 index 00000000000..1248601c1e4 --- /dev/null +++ b/src/test/ui/lint/command-line-lint-group-deny.rs @@ -0,0 +1,15 @@ +// Copyright 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. + +// compile-flags: -D bad-style + +fn main() { + let _InappropriateCamelCasing = true; +} diff --git a/src/test/ui/lint/command-line-lint-group-deny.stderr b/src/test/ui/lint/command-line-lint-group-deny.stderr new file mode 100644 index 00000000000..eafbf944dea --- /dev/null +++ b/src/test/ui/lint/command-line-lint-group-deny.stderr @@ -0,0 +1,10 @@ +error: variable `_InappropriateCamelCasing` should have a snake case name such as `_inappropriate_camel_casing` + --> $DIR/command-line-lint-group-deny.rs:14:9 + | +14 | let _InappropriateCamelCasing = true; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D bad-style` implies `-D non-snake-case` + +error: aborting due to previous error + diff --git a/src/test/ui/lint/command-line-lint-group-forbid.rs b/src/test/ui/lint/command-line-lint-group-forbid.rs new file mode 100644 index 00000000000..ae16db44864 --- /dev/null +++ b/src/test/ui/lint/command-line-lint-group-forbid.rs @@ -0,0 +1,15 @@ +// Copyright 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. + +// compile-flags: -F bad-style + +fn main() { + let _InappropriateCamelCasing = true; +} diff --git a/src/test/ui/lint/command-line-lint-group-forbid.stderr b/src/test/ui/lint/command-line-lint-group-forbid.stderr new file mode 100644 index 00000000000..0cf896060a2 --- /dev/null +++ b/src/test/ui/lint/command-line-lint-group-forbid.stderr @@ -0,0 +1,10 @@ +error: variable `_InappropriateCamelCasing` should have a snake case name such as `_inappropriate_camel_casing` + --> $DIR/command-line-lint-group-forbid.rs:14:9 + | +14 | let _InappropriateCamelCasing = true; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-F bad-style` implies `-F non-snake-case` + +error: aborting due to previous error + diff --git a/src/test/ui/lint/command-line-lint-group-warn.rs b/src/test/ui/lint/command-line-lint-group-warn.rs new file mode 100644 index 00000000000..7d65c802788 --- /dev/null +++ b/src/test/ui/lint/command-line-lint-group-warn.rs @@ -0,0 +1,15 @@ +// Copyright 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. + +// compile-flags: -W bad-style + +fn main() { + let _InappropriateCamelCasing = true; +} diff --git a/src/test/ui/lint/command-line-lint-group-warn.stderr b/src/test/ui/lint/command-line-lint-group-warn.stderr new file mode 100644 index 00000000000..4ffbff6cdb7 --- /dev/null +++ b/src/test/ui/lint/command-line-lint-group-warn.stderr @@ -0,0 +1,8 @@ +warning: variable `_InappropriateCamelCasing` should have a snake case name such as `_inappropriate_camel_casing` + --> $DIR/command-line-lint-group-warn.rs:14:9 + | +14 | let _InappropriateCamelCasing = true; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-W bad-style` implies `-W non-snake-case` + |
