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.
This commit is contained in:
parent
65b0554143
commit
93014467f8
@ -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()
|
||||
|
@ -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);
|
||||
|
@ -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)]
|
||||
|
||||
|
15
src/test/ui/lint/command-line-lint-group-allow.rs
Normal file
15
src/test/ui/lint/command-line-lint-group-allow.rs
Normal file
@ -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;
|
||||
}
|
15
src/test/ui/lint/command-line-lint-group-deny.rs
Normal file
15
src/test/ui/lint/command-line-lint-group-deny.rs
Normal file
@ -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;
|
||||
}
|
10
src/test/ui/lint/command-line-lint-group-deny.stderr
Normal file
10
src/test/ui/lint/command-line-lint-group-deny.stderr
Normal file
@ -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
|
||||
|
15
src/test/ui/lint/command-line-lint-group-forbid.rs
Normal file
15
src/test/ui/lint/command-line-lint-group-forbid.rs
Normal file
@ -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;
|
||||
}
|
10
src/test/ui/lint/command-line-lint-group-forbid.stderr
Normal file
10
src/test/ui/lint/command-line-lint-group-forbid.stderr
Normal file
@ -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
|
||||
|
15
src/test/ui/lint/command-line-lint-group-warn.rs
Normal file
15
src/test/ui/lint/command-line-lint-group-warn.rs
Normal file
@ -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;
|
||||
}
|
8
src/test/ui/lint/command-line-lint-group-warn.stderr
Normal file
8
src/test/ui/lint/command-line-lint-group-warn.stderr
Normal file
@ -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`
|
||||
|
Loading…
Reference in New Issue
Block a user