From 65b05541432c1fe7b75fb2dd3b020f933f3b5f4b Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Thu, 5 Jan 2017 18:55:36 -0800 Subject: [PATCH 1/4] note individual lint name set via lint group attribute in notes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Warning or error messages set via a lint group attribute (e.g. `#[deny(warnings)]`) should still make it clear which individual lint (by name) was triggered, similarly to how we include "on by default" language for default lints. This—and, while we're here, the existing "on by default" language—can be tucked into a note rather than cluttering the main error message. This occasions the slightest of refactorings (we now have to get the diagnostic-builder with the main message first, before matching on the lint source). This is in the matter of #36846. --- src/librustc/lint/context.rs | 53 +++++++++++-------- src/librustc/lint/mod.rs | 2 +- .../imports/rfc-1560-warning-cycle.rs | 1 + src/test/compile-fail/issue-30730.rs | 4 +- src/test/compile-fail/lint-group-style.rs | 20 +++++-- src/test/compile-fail/lint-output-format-2.rs | 11 ++-- src/test/run-pass/path-lookahead.rs | 6 +-- .../proj-outlives-region.stderr | 3 +- .../ui/compare-method/region-unrelated.stderr | 3 +- src/test/ui/span/issue-24690.stderr | 4 ++ src/test/ui/span/multispan-import-lint.stderr | 4 +- 11 files changed, 72 insertions(+), 39 deletions(-) diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 362117d860a5c..62f19412d52f0 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -40,6 +40,7 @@ use std::cmp; use std::default::Default as StdDefault; use std::mem; use std::fmt; +use std::ops::Deref; use syntax::attr; use syntax::ast; use syntax_pos::{MultiSpan, Span}; @@ -446,35 +447,18 @@ pub fn raw_struct_lint<'a, S>(sess: &'a Session, -> DiagnosticBuilder<'a> where S: Into { - let (mut level, source) = lvlsrc; + let (level, source) = lvlsrc; if level == Allow { return sess.diagnostic().struct_dummy(); } let name = lint.name_lower(); let mut def = None; - let msg = match source { - Default => { - format!("{}, #[{}({})] on by default", msg, - level.as_str(), name) - }, - CommandLine => { - format!("{} [-{} {}]", msg, - match level { - Warn => 'W', Deny => 'D', Forbid => 'F', - Allow => bug!() - }, name.replace("_", "-")) - }, - Node(src) => { - def = Some(src); - msg.to_string() - } - }; - // For purposes of printing, we can treat forbid as deny. - if level == Forbid { level = Deny; } + // Except for possible note details, forbid behaves like deny. + let effective_level = if level == Forbid { Deny } else { level }; - let mut err = match (level, span) { + let mut err = match (effective_level, span) { (Warn, Some(sp)) => sess.struct_span_warn(sp, &msg[..]), (Warn, None) => sess.struct_warn(&msg[..]), (Deny, Some(sp)) => sess.struct_span_err(sp, &msg[..]), @@ -482,6 +466,27 @@ pub fn raw_struct_lint<'a, S>(sess: &'a Session, _ => bug!("impossible level in raw_emit_lint"), }; + match source { + 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("_", "-"))); + }, + Node(lint_attr_name, src) => { + def = Some(src); + if lint_attr_name.as_str().deref() != name { + let level_str = level.as_str(); + err.note(&format!("#[{}({})] implies #[{}({})]", + level_str, lint_attr_name, level_str, name)); + } + } + } + // Check for future incompatibility lints and issue a stronger warning. if let Some(future_incompatible) = lints.future_incompatible(LintId::of(lint)) { let explanation = format!("this was previously accepted by the compiler \ @@ -649,6 +654,8 @@ pub trait LintContext<'tcx>: Sized { } }; + let lint_attr_name = result.expect("lint attribute should be well-formed").0; + for (lint_id, level, span) in v { let (now, now_source) = self.lints().get_level_source(lint_id); if now == Forbid && level != Forbid { @@ -660,7 +667,7 @@ pub trait LintContext<'tcx>: Sized { diag_builder.span_label(span, &format!("overruled by previous forbid")); match now_source { LintSource::Default => &mut diag_builder, - LintSource::Node(forbid_source_span) => { + LintSource::Node(_, forbid_source_span) => { diag_builder.span_label(forbid_source_span, &format!("`forbid` level set here")) }, @@ -672,7 +679,7 @@ pub trait LintContext<'tcx>: Sized { let src = self.lints().get_level_source(lint_id).1; self.level_stack().push((lint_id, (now, src))); pushed += 1; - self.mut_lints().set_level(lint_id, (level, Node(span))); + self.mut_lints().set_level(lint_id, (level, Node(lint_attr_name, span))); } } } diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index d12065ca86e14..9c2a892a5fc7d 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -338,7 +338,7 @@ pub enum LintSource { Default, /// Lint level was set by an attribute. - Node(Span), + Node(ast::Name, Span), /// Lint level was set by a command-line flag. CommandLine, diff --git a/src/test/compile-fail/imports/rfc-1560-warning-cycle.rs b/src/test/compile-fail/imports/rfc-1560-warning-cycle.rs index eb36129799a4e..1d67bf3a1cdda 100644 --- a/src/test/compile-fail/imports/rfc-1560-warning-cycle.rs +++ b/src/test/compile-fail/imports/rfc-1560-warning-cycle.rs @@ -23,6 +23,7 @@ mod bar { //~^ WARN `Foo` is ambiguous //~| WARN hard error in a future release //~| NOTE see issue #38260 + //~| NOTE #[warn(legacy_imports)] on by default } } diff --git a/src/test/compile-fail/issue-30730.rs b/src/test/compile-fail/issue-30730.rs index 82804bb747406..6082740f427d7 100644 --- a/src/test/compile-fail/issue-30730.rs +++ b/src/test/compile-fail/issue-30730.rs @@ -9,5 +9,7 @@ // except according to those terms. #![deny(warnings)] //~ NOTE: lint level defined here -use std::thread; //~ ERROR: unused import +use std::thread; +//~^ ERROR: unused import +//~| NOTE: #[deny(warnings)] implies #[deny(unused_imports)] fn main() {} diff --git a/src/test/compile-fail/lint-group-style.rs b/src/test/compile-fail/lint-group-style.rs index b2e6072c9855c..a8c377034756a 100644 --- a/src/test/compile-fail/lint-group-style.rs +++ b/src/test/compile-fail/lint-group-style.rs @@ -12,7 +12,9 @@ //~^ NOTE lint level defined here #![allow(dead_code)] -fn CamelCase() {} //~ ERROR function `CamelCase` should have a snake case name +fn CamelCase() {} +//~^ ERROR function `CamelCase` should have a snake case name +//~| NOTE #[deny(bad_style)] implies #[deny(non_snake_case)] #[allow(bad_style)] mod test { @@ -22,9 +24,13 @@ mod test { //~^ NOTE lint level defined here //~^^ NOTE lint level defined here mod bad { - fn CamelCase() {} //~ ERROR function `CamelCase` should have a snake case name + fn CamelCase() {} + //~^ ERROR function `CamelCase` should have a snake case name + //~| NOTE #[forbid(bad_style)] implies #[forbid(non_snake_case)] - static bad: isize = 1; //~ ERROR static variable `bad` should have an upper case name + static bad: isize = 1; + //~^ ERROR static variable `bad` should have an upper case name + //~| NOTE #[forbid(bad_style)] implies #[forbid(non_upper_case_globals)] } mod warn { @@ -32,9 +38,13 @@ mod test { //~^ NOTE lint level defined here //~| NOTE lint level defined here - fn CamelCase() {} //~ WARN function `CamelCase` should have a snake case name + fn CamelCase() {} + //~^ WARN function `CamelCase` should have a snake case name + //~| NOTE #[warn(bad_style)] implies #[warn(non_snake_case)] - struct snake_case; //~ WARN type `snake_case` should have a camel case name + struct snake_case; + //~^ WARN type `snake_case` should have a camel case name + //~| NOTE #[warn(bad_style)] implies #[warn(non_camel_case_types)] } } diff --git a/src/test/compile-fail/lint-output-format-2.rs b/src/test/compile-fail/lint-output-format-2.rs index 2f74325d19c7d..8b76bedb003c0 100644 --- a/src/test/compile-fail/lint-output-format-2.rs +++ b/src/test/compile-fail/lint-output-format-2.rs @@ -11,15 +11,20 @@ // compile-flags: -F unused_features // aux-build:lint_output_format.rs -#![feature(foo)] //~ ERROR unused or unknown feature +#![feature(foo)] +//~^ ERROR unused or unknown feature +//~| NOTE [-F unused-features] #![feature(test_feature)] extern crate lint_output_format; use lint_output_format::{foo, bar}; -//~^ WARNING use of deprecated item: text, +//~^ WARNING use of deprecated item: text +//~| NOTE #[warn(deprecated)] on by default fn main() { - let _x = foo(); //~ WARNING #[warn(deprecated)] on by default + let _x = foo(); + //~^ WARNING use of deprecated item: text + //~| NOTE #[warn(deprecated)] on by default let _y = bar(); } diff --git a/src/test/run-pass/path-lookahead.rs b/src/test/run-pass/path-lookahead.rs index 017259af190fc..5c195c8a4c63a 100644 --- a/src/test/run-pass/path-lookahead.rs +++ b/src/test/run-pass/path-lookahead.rs @@ -10,11 +10,11 @@ // Parser test for #37765 -fn with_parens(arg: T) -> String { //~WARN dead_code - return (::to_string(&arg)); //~WARN unused_parens +fn with_parens(arg: T) -> String { //~WARN function is never used: `with_parens` + return (::to_string(&arg)); //~WARN unnecessary parentheses around `return` value } -fn no_parens(arg: T) -> String { //~WARN dead_code +fn no_parens(arg: T) -> String { //~WARN function is never used: `no_parens` return ::to_string(&arg); } diff --git a/src/test/ui/compare-method/proj-outlives-region.stderr b/src/test/ui/compare-method/proj-outlives-region.stderr index 021b571fe793c..2a707c6eb8b10 100644 --- a/src/test/ui/compare-method/proj-outlives-region.stderr +++ b/src/test/ui/compare-method/proj-outlives-region.stderr @@ -1,4 +1,4 @@ -error[E0276]: impl has stricter requirements than trait, #[deny(extra_requirement_in_impl)] on by default +error[E0276]: impl has stricter requirements than trait --> $DIR/proj-outlives-region.rs:22:5 | 17 | fn foo() where T: 'a; @@ -7,6 +7,7 @@ error[E0276]: impl has stricter requirements than trait, #[deny(extra_requiremen 22 | fn foo() where U: 'a { } //~ ERROR E0276 | ^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `U: 'a` | + = note: #[deny(extra_requirement_in_impl)] on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #37166 diff --git a/src/test/ui/compare-method/region-unrelated.stderr b/src/test/ui/compare-method/region-unrelated.stderr index 4df337c525743..9e822bd8b0790 100644 --- a/src/test/ui/compare-method/region-unrelated.stderr +++ b/src/test/ui/compare-method/region-unrelated.stderr @@ -1,4 +1,4 @@ -error[E0276]: impl has stricter requirements than trait, #[deny(extra_requirement_in_impl)] on by default +error[E0276]: impl has stricter requirements than trait --> $DIR/region-unrelated.rs:22:5 | 17 | fn foo() where T: 'a; @@ -7,6 +7,7 @@ error[E0276]: impl has stricter requirements than trait, #[deny(extra_requiremen 22 | fn foo() where V: 'a { } | ^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `V: 'a` | + = note: #[deny(extra_requirement_in_impl)] on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #37166 diff --git a/src/test/ui/span/issue-24690.stderr b/src/test/ui/span/issue-24690.stderr index dbe5e31287e97..623bb4a0d2697 100644 --- a/src/test/ui/span/issue-24690.stderr +++ b/src/test/ui/span/issue-24690.stderr @@ -4,6 +4,7 @@ error: variable `theTwo` should have a snake case name such as `the_two` 19 | let theTwo = 2; | ^^^^^^ | + = note: #[deny(warnings)] implies #[deny(non_snake_case)] note: lint level defined here --> $DIR/issue-24690.rs:16:9 | @@ -15,6 +16,8 @@ error: variable `theOtherTwo` should have a snake case name such as `the_other_t | 20 | let theOtherTwo = 2; | ^^^^^^^^^^^ + | + = note: #[deny(warnings)] implies #[deny(non_snake_case)] error: unused variable: `theOtherTwo` --> $DIR/issue-24690.rs:20:9 @@ -22,6 +25,7 @@ error: unused variable: `theOtherTwo` 20 | let theOtherTwo = 2; | ^^^^^^^^^^^ | + = note: #[deny(warnings)] implies #[deny(unused_variables)] note: lint level defined here --> $DIR/issue-24690.rs:16:9 | diff --git a/src/test/ui/span/multispan-import-lint.stderr b/src/test/ui/span/multispan-import-lint.stderr index b581584eee7e2..4b1ca7f98bbf6 100644 --- a/src/test/ui/span/multispan-import-lint.stderr +++ b/src/test/ui/span/multispan-import-lint.stderr @@ -1,6 +1,8 @@ -warning: unused imports: `Eq`, `Ord`, `PartialEq`, `PartialOrd`, #[warn(unused_imports)] on by default +warning: unused imports: `Eq`, `Ord`, `PartialEq`, `PartialOrd` --> $DIR/multispan-import-lint.rs:11:16 | 11 | use std::cmp::{Eq, Ord, min, PartialEq, PartialOrd}; | ^^ ^^^ ^^^^^^^^^ ^^^^^^^^^^ + | + = note: #[warn(unused_imports)] on by default From 93014467f83435d4721616f9b5e4417fc01623aa Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Thu, 5 Jan 2017 18:55:43 -0800 Subject: [PATCH 2/4] 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. --- src/librustc/lint/context.rs | 28 +++++++++++++------ src/librustc/lint/mod.rs | 3 +- src/test/compile-fail/lint-output-format-2.rs | 2 +- .../ui/lint/command-line-lint-group-allow.rs | 15 ++++++++++ .../ui/lint/command-line-lint-group-deny.rs | 15 ++++++++++ .../lint/command-line-lint-group-deny.stderr | 10 +++++++ .../ui/lint/command-line-lint-group-forbid.rs | 15 ++++++++++ .../command-line-lint-group-forbid.stderr | 10 +++++++ .../ui/lint/command-line-lint-group-warn.rs | 15 ++++++++++ .../lint/command-line-lint-group-warn.stderr | 8 ++++++ 10 files changed, 110 insertions(+), 11 deletions(-) create mode 100644 src/test/ui/lint/command-line-lint-group-allow.rs create mode 100644 src/test/ui/lint/command-line-lint-group-deny.rs create mode 100644 src/test/ui/lint/command-line-lint-group-deny.stderr create mode 100644 src/test/ui/lint/command-line-lint-group-forbid.rs create mode 100644 src/test/ui/lint/command-line-lint-group-forbid.stderr create mode 100644 src/test/ui/lint/command-line-lint-group-warn.rs create mode 100644 src/test/ui/lint/command-line-lint-group-warn.stderr diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 62f19412d52f0..28600e3ab8eb8 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::>(); } 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 9c2a892a5fc7d..e9f603db15d62 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 8b76bedb003c0..0e68ff752e5a9 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 0000000000000..cdb9684933d9b --- /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 or the MIT license +// , 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 0000000000000..1248601c1e44a --- /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 or the MIT license +// , 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 0000000000000..eafbf944dea97 --- /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 0000000000000..ae16db44864c9 --- /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 or the MIT license +// , 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 0000000000000..0cf896060a27f --- /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 0000000000000..7d65c802788bf --- /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 or the MIT license +// , 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 0000000000000..4ffbff6cdb7ec --- /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` + From 778958f25661a41081878ffbb1a589d926d5bd2a Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Wed, 4 Jan 2017 23:32:09 -0800 Subject: [PATCH 3/4] make lint-group-style test a UI rather than a compile-fail test As suggested by Niko Matsakis in review (https://github.com/rust-lang/rust/pull/38103#discussion_r94460982) regarding the endeavor prompted by #36846. --- src/test/compile-fail/lint-group-style.rs | 51 ----------------- src/test/ui/lint/lint-group-style.rs | 36 ++++++++++++ src/test/ui/lint/lint-group-style.stderr | 67 +++++++++++++++++++++++ 3 files changed, 103 insertions(+), 51 deletions(-) delete mode 100644 src/test/compile-fail/lint-group-style.rs create mode 100644 src/test/ui/lint/lint-group-style.rs create mode 100644 src/test/ui/lint/lint-group-style.stderr diff --git a/src/test/compile-fail/lint-group-style.rs b/src/test/compile-fail/lint-group-style.rs deleted file mode 100644 index a8c377034756a..0000000000000 --- a/src/test/compile-fail/lint-group-style.rs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2014 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![deny(bad_style)] -//~^ NOTE lint level defined here -#![allow(dead_code)] - -fn CamelCase() {} -//~^ ERROR function `CamelCase` should have a snake case name -//~| NOTE #[deny(bad_style)] implies #[deny(non_snake_case)] - -#[allow(bad_style)] -mod test { - fn CamelCase() {} - - #[forbid(bad_style)] - //~^ NOTE lint level defined here - //~^^ NOTE lint level defined here - mod bad { - fn CamelCase() {} - //~^ ERROR function `CamelCase` should have a snake case name - //~| NOTE #[forbid(bad_style)] implies #[forbid(non_snake_case)] - - static bad: isize = 1; - //~^ ERROR static variable `bad` should have an upper case name - //~| NOTE #[forbid(bad_style)] implies #[forbid(non_upper_case_globals)] - } - - mod warn { - #![warn(bad_style)] - //~^ NOTE lint level defined here - //~| NOTE lint level defined here - - fn CamelCase() {} - //~^ WARN function `CamelCase` should have a snake case name - //~| NOTE #[warn(bad_style)] implies #[warn(non_snake_case)] - - struct snake_case; - //~^ WARN type `snake_case` should have a camel case name - //~| NOTE #[warn(bad_style)] implies #[warn(non_camel_case_types)] - } -} - -fn main() {} diff --git a/src/test/ui/lint/lint-group-style.rs b/src/test/ui/lint/lint-group-style.rs new file mode 100644 index 0000000000000..2bd760e417a89 --- /dev/null +++ b/src/test/ui/lint/lint-group-style.rs @@ -0,0 +1,36 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![deny(bad_style)] +#![allow(dead_code)] + +fn CamelCase() {} + +#[allow(bad_style)] +mod test { + fn CamelCase() {} + + #[forbid(bad_style)] + mod bad { + fn CamelCase() {} + + static bad: isize = 1; + } + + mod warn { + #![warn(bad_style)] + + fn CamelCase() {} + + struct snake_case; + } +} + +fn main() {} diff --git a/src/test/ui/lint/lint-group-style.stderr b/src/test/ui/lint/lint-group-style.stderr new file mode 100644 index 0000000000000..93f6399b22726 --- /dev/null +++ b/src/test/ui/lint/lint-group-style.stderr @@ -0,0 +1,67 @@ +error: function `CamelCase` should have a snake case name such as `camel_case` + --> $DIR/lint-group-style.rs:14:1 + | +14 | fn CamelCase() {} + | ^^^^^^^^^^^^^^^^^ + | + = note: #[deny(bad_style)] implies #[deny(non_snake_case)] +note: lint level defined here + --> $DIR/lint-group-style.rs:11:9 + | +11 | #![deny(bad_style)] + | ^^^^^^^^^ + +error: function `CamelCase` should have a snake case name such as `camel_case` + --> $DIR/lint-group-style.rs:22:9 + | +22 | fn CamelCase() {} + | ^^^^^^^^^^^^^^^^^ + | + = note: #[forbid(bad_style)] implies #[forbid(non_snake_case)] +note: lint level defined here + --> $DIR/lint-group-style.rs:20:14 + | +20 | #[forbid(bad_style)] + | ^^^^^^^^^ + +error: static variable `bad` should have an upper case name such as `BAD` + --> $DIR/lint-group-style.rs:24:9 + | +24 | static bad: isize = 1; + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[forbid(bad_style)] implies #[forbid(non_upper_case_globals)] +note: lint level defined here + --> $DIR/lint-group-style.rs:20:14 + | +20 | #[forbid(bad_style)] + | ^^^^^^^^^ + +warning: function `CamelCase` should have a snake case name such as `camel_case` + --> $DIR/lint-group-style.rs:30:9 + | +30 | fn CamelCase() {} + | ^^^^^^^^^^^^^^^^^ + | + = note: #[warn(bad_style)] implies #[warn(non_snake_case)] +note: lint level defined here + --> $DIR/lint-group-style.rs:28:17 + | +28 | #![warn(bad_style)] + | ^^^^^^^^^ + +warning: type `snake_case` should have a camel case name such as `SnakeCase` + --> $DIR/lint-group-style.rs:32:9 + | +32 | struct snake_case; + | ^^^^^^^^^^^^^^^^^^ + | + = note: #[warn(bad_style)] implies #[warn(non_camel_case_types)] +note: lint level defined here + --> $DIR/lint-group-style.rs:28:17 + | +28 | #![warn(bad_style)] + | ^^^^^^^^^ + +error: aborting due to 3 previous errors + From 72af42e8974f521e3fed753feac3d0638ad61025 Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Thu, 5 Jan 2017 20:01:22 -0800 Subject: [PATCH 4/4] note wording: lint implied by lint group, not lint group implies lint --- src/librustc/lint/context.rs | 8 ++++---- src/test/compile-fail/issue-30730.rs | 2 +- src/test/ui/lint/command-line-lint-group-deny.stderr | 2 +- src/test/ui/lint/command-line-lint-group-forbid.stderr | 2 +- src/test/ui/lint/command-line-lint-group-warn.stderr | 2 +- src/test/ui/lint/lint-group-style.stderr | 10 +++++----- src/test/ui/span/issue-24690.stderr | 6 +++--- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 28600e3ab8eb8..32bc81e947037 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -483,16 +483,16 @@ pub fn raw_struct_lint<'a, S>(sess: &'a Session, 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)); + err.note(&format!("`{} {}` implied by `{} {}`", + flag, hyphen_case_lint_name, flag, hyphen_case_flag_val)); } }, Node(lint_attr_name, src) => { def = Some(src); if lint_attr_name.as_str().deref() != name { let level_str = level.as_str(); - err.note(&format!("#[{}({})] implies #[{}({})]", - level_str, lint_attr_name, level_str, name)); + err.note(&format!("#[{}({})] implied by #[{}({})]", + level_str, name, level_str, lint_attr_name)); } } } diff --git a/src/test/compile-fail/issue-30730.rs b/src/test/compile-fail/issue-30730.rs index 6082740f427d7..086938334c78a 100644 --- a/src/test/compile-fail/issue-30730.rs +++ b/src/test/compile-fail/issue-30730.rs @@ -11,5 +11,5 @@ #![deny(warnings)] //~ NOTE: lint level defined here use std::thread; //~^ ERROR: unused import -//~| NOTE: #[deny(warnings)] implies #[deny(unused_imports)] +//~| NOTE: #[deny(unused_imports)] implied by #[deny(warnings)] fn main() {} diff --git a/src/test/ui/lint/command-line-lint-group-deny.stderr b/src/test/ui/lint/command-line-lint-group-deny.stderr index eafbf944dea97..23fac66cc6c98 100644 --- a/src/test/ui/lint/command-line-lint-group-deny.stderr +++ b/src/test/ui/lint/command-line-lint-group-deny.stderr @@ -4,7 +4,7 @@ error: variable `_InappropriateCamelCasing` should have a snake case name such a 14 | let _InappropriateCamelCasing = true; | ^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D bad-style` implies `-D non-snake-case` + = note: `-D non-snake-case` implied by `-D bad-style` error: aborting due to previous error diff --git a/src/test/ui/lint/command-line-lint-group-forbid.stderr b/src/test/ui/lint/command-line-lint-group-forbid.stderr index 0cf896060a27f..0babd7f6fe47a 100644 --- a/src/test/ui/lint/command-line-lint-group-forbid.stderr +++ b/src/test/ui/lint/command-line-lint-group-forbid.stderr @@ -4,7 +4,7 @@ error: variable `_InappropriateCamelCasing` should have a snake case name such a 14 | let _InappropriateCamelCasing = true; | ^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-F bad-style` implies `-F non-snake-case` + = note: `-F non-snake-case` implied by `-F bad-style` error: aborting due to previous error diff --git a/src/test/ui/lint/command-line-lint-group-warn.stderr b/src/test/ui/lint/command-line-lint-group-warn.stderr index 4ffbff6cdb7ec..998c892c7e349 100644 --- a/src/test/ui/lint/command-line-lint-group-warn.stderr +++ b/src/test/ui/lint/command-line-lint-group-warn.stderr @@ -4,5 +4,5 @@ warning: variable `_InappropriateCamelCasing` should have a snake case name such 14 | let _InappropriateCamelCasing = true; | ^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-W bad-style` implies `-W non-snake-case` + = note: `-W non-snake-case` implied by `-W bad-style` diff --git a/src/test/ui/lint/lint-group-style.stderr b/src/test/ui/lint/lint-group-style.stderr index 93f6399b22726..9c0f4866af690 100644 --- a/src/test/ui/lint/lint-group-style.stderr +++ b/src/test/ui/lint/lint-group-style.stderr @@ -4,7 +4,7 @@ error: function `CamelCase` should have a snake case name such as `camel_case` 14 | fn CamelCase() {} | ^^^^^^^^^^^^^^^^^ | - = note: #[deny(bad_style)] implies #[deny(non_snake_case)] + = note: #[deny(non_snake_case)] implied by #[deny(bad_style)] note: lint level defined here --> $DIR/lint-group-style.rs:11:9 | @@ -17,7 +17,7 @@ error: function `CamelCase` should have a snake case name such as `camel_case` 22 | fn CamelCase() {} | ^^^^^^^^^^^^^^^^^ | - = note: #[forbid(bad_style)] implies #[forbid(non_snake_case)] + = note: #[forbid(non_snake_case)] implied by #[forbid(bad_style)] note: lint level defined here --> $DIR/lint-group-style.rs:20:14 | @@ -30,7 +30,7 @@ error: static variable `bad` should have an upper case name such as `BAD` 24 | static bad: isize = 1; | ^^^^^^^^^^^^^^^^^^^^^^ | - = note: #[forbid(bad_style)] implies #[forbid(non_upper_case_globals)] + = note: #[forbid(non_upper_case_globals)] implied by #[forbid(bad_style)] note: lint level defined here --> $DIR/lint-group-style.rs:20:14 | @@ -43,7 +43,7 @@ warning: function `CamelCase` should have a snake case name such as `camel_case` 30 | fn CamelCase() {} | ^^^^^^^^^^^^^^^^^ | - = note: #[warn(bad_style)] implies #[warn(non_snake_case)] + = note: #[warn(non_snake_case)] implied by #[warn(bad_style)] note: lint level defined here --> $DIR/lint-group-style.rs:28:17 | @@ -56,7 +56,7 @@ warning: type `snake_case` should have a camel case name such as `SnakeCase` 32 | struct snake_case; | ^^^^^^^^^^^^^^^^^^ | - = note: #[warn(bad_style)] implies #[warn(non_camel_case_types)] + = note: #[warn(non_camel_case_types)] implied by #[warn(bad_style)] note: lint level defined here --> $DIR/lint-group-style.rs:28:17 | diff --git a/src/test/ui/span/issue-24690.stderr b/src/test/ui/span/issue-24690.stderr index 623bb4a0d2697..c4f2616f5945b 100644 --- a/src/test/ui/span/issue-24690.stderr +++ b/src/test/ui/span/issue-24690.stderr @@ -4,7 +4,7 @@ error: variable `theTwo` should have a snake case name such as `the_two` 19 | let theTwo = 2; | ^^^^^^ | - = note: #[deny(warnings)] implies #[deny(non_snake_case)] + = note: #[deny(non_snake_case)] implied by #[deny(warnings)] note: lint level defined here --> $DIR/issue-24690.rs:16:9 | @@ -17,7 +17,7 @@ error: variable `theOtherTwo` should have a snake case name such as `the_other_t 20 | let theOtherTwo = 2; | ^^^^^^^^^^^ | - = note: #[deny(warnings)] implies #[deny(non_snake_case)] + = note: #[deny(non_snake_case)] implied by #[deny(warnings)] error: unused variable: `theOtherTwo` --> $DIR/issue-24690.rs:20:9 @@ -25,7 +25,7 @@ error: unused variable: `theOtherTwo` 20 | let theOtherTwo = 2; | ^^^^^^^^^^^ | - = note: #[deny(warnings)] implies #[deny(unused_variables)] + = note: #[deny(unused_variables)] implied by #[deny(warnings)] note: lint level defined here --> $DIR/issue-24690.rs:16:9 |