Skip to content

Commit 9301446

Browse files
committed
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.
1 parent 65b0554 commit 9301446

10 files changed

+110
-11
lines changed

src/librustc/lint/context.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ use std::fmt;
4343
use std::ops::Deref;
4444
use syntax::attr;
4545
use syntax::ast;
46+
use syntax::symbol::Symbol;
4647
use syntax_pos::{MultiSpan, Span};
4748
use errors::{self, Diagnostic, DiagnosticBuilder};
4849
use hir;
@@ -300,8 +301,9 @@ impl LintStore {
300301
check_lint_name_cmdline(sess, self,
301302
&lint_name[..], level);
302303

304+
let lint_flag_val = Symbol::intern(&lint_name);
303305
match self.find_lint(&lint_name[..], sess, None) {
304-
Ok(lint_id) => self.set_level(lint_id, (level, CommandLine)),
306+
Ok(lint_id) => self.set_level(lint_id, (level, CommandLine(lint_flag_val))),
305307
Err(FindLintError::Removed) => { }
306308
Err(_) => {
307309
match self.lint_groups.iter().map(|(&x, pair)| (x, pair.0.clone()))
@@ -311,7 +313,7 @@ impl LintStore {
311313
Some(v) => {
312314
v.iter()
313315
.map(|lint_id: &LintId|
314-
self.set_level(*lint_id, (level, CommandLine)))
316+
self.set_level(*lint_id, (level, CommandLine(lint_flag_val))))
315317
.collect::<Vec<()>>();
316318
}
317319
None => {
@@ -470,12 +472,20 @@ pub fn raw_struct_lint<'a, S>(sess: &'a Session,
470472
Default => {
471473
err.note(&format!("#[{}({})] on by default", level.as_str(), name));
472474
},
473-
CommandLine => {
474-
err.note(&format!("[-{} {}]",
475-
match level {
476-
Warn => 'W', Deny => 'D', Forbid => 'F',
477-
Allow => bug!()
478-
}, name.replace("_", "-")));
475+
CommandLine(lint_flag_val) => {
476+
let flag = match level {
477+
Warn => "-W", Deny => "-D", Forbid => "-F",
478+
Allow => bug!("earlier conditional return should handle Allow case")
479+
};
480+
let hyphen_case_lint_name = name.replace("_", "-");
481+
if lint_flag_val.as_str().deref() == name {
482+
err.note(&format!("requested on the command line with `{} {}`",
483+
flag, hyphen_case_lint_name));
484+
} else {
485+
let hyphen_case_flag_val = lint_flag_val.as_str().replace("_", "-");
486+
err.note(&format!("`{} {}` implies `{} {}`",
487+
flag, hyphen_case_flag_val, flag, hyphen_case_lint_name));
488+
}
479489
},
480490
Node(lint_attr_name, src) => {
481491
def = Some(src);
@@ -671,7 +681,7 @@ pub trait LintContext<'tcx>: Sized {
671681
diag_builder.span_label(forbid_source_span,
672682
&format!("`forbid` level set here"))
673683
},
674-
LintSource::CommandLine => {
684+
LintSource::CommandLine(_) => {
675685
diag_builder.note("`forbid` lint level was set on command line")
676686
}
677687
}.emit()

src/librustc/lint/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use std::ascii::AsciiExt;
3838
use syntax_pos::Span;
3939
use syntax::visit as ast_visit;
4040
use syntax::ast;
41+
use syntax::symbol::Symbol;
4142

4243
pub use lint::context::{LateContext, EarlyContext, LintContext, LintStore,
4344
raw_emit_lint, check_crate, check_ast_crate, gather_attrs,
@@ -341,7 +342,7 @@ pub enum LintSource {
341342
Node(ast::Name, Span),
342343

343344
/// Lint level was set by a command-line flag.
344-
CommandLine,
345+
CommandLine(Symbol),
345346
}
346347

347348
pub type LevelSource = (Level, LintSource);

src/test/compile-fail/lint-output-format-2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#![feature(foo)]
1515
//~^ ERROR unused or unknown feature
16-
//~| NOTE [-F unused-features]
16+
//~| NOTE requested on the command line with `-F unused-features`
1717

1818
#![feature(test_feature)]
1919

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: -A bad-style
12+
13+
fn main() {
14+
let _InappropriateCamelCasing = true;
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: -D bad-style
12+
13+
fn main() {
14+
let _InappropriateCamelCasing = true;
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: variable `_InappropriateCamelCasing` should have a snake case name such as `_inappropriate_camel_casing`
2+
--> $DIR/command-line-lint-group-deny.rs:14:9
3+
|
4+
14 | let _InappropriateCamelCasing = true;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `-D bad-style` implies `-D non-snake-case`
8+
9+
error: aborting due to previous error
10+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: -F bad-style
12+
13+
fn main() {
14+
let _InappropriateCamelCasing = true;
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: variable `_InappropriateCamelCasing` should have a snake case name such as `_inappropriate_camel_casing`
2+
--> $DIR/command-line-lint-group-forbid.rs:14:9
3+
|
4+
14 | let _InappropriateCamelCasing = true;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `-F bad-style` implies `-F non-snake-case`
8+
9+
error: aborting due to previous error
10+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: -W bad-style
12+
13+
fn main() {
14+
let _InappropriateCamelCasing = true;
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
warning: variable `_InappropriateCamelCasing` should have a snake case name such as `_inappropriate_camel_casing`
2+
--> $DIR/command-line-lint-group-warn.rs:14:9
3+
|
4+
14 | let _InappropriateCamelCasing = true;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `-W bad-style` implies `-W non-snake-case`
8+

0 commit comments

Comments
 (0)