Initial support for force-warns
This commit is contained in:
parent
ce0d64e03e
commit
69a19bfd43
13 changed files with 146 additions and 7 deletions
|
@ -109,6 +109,11 @@ impl<'s> LintLevelsBuilder<'s> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for lint_name in &sess.opts.force_warns {
|
||||||
|
store.check_lint_name_cmdline(sess, &lint_name, Level::Allow); // FIXME level is wrong
|
||||||
|
self.sets.force_warns.insert(lint_name.to_uppercase());
|
||||||
|
}
|
||||||
|
|
||||||
self.sets.list.push(LintSet::CommandLine { specs });
|
self.sets.list.push(LintSet::CommandLine { specs });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,6 +147,9 @@ impl<'s> LintLevelsBuilder<'s> {
|
||||||
LintLevelSource::Default => false,
|
LintLevelSource::Default => false,
|
||||||
LintLevelSource::Node(symbol, _, _) => self.store.is_lint_group(symbol),
|
LintLevelSource::Node(symbol, _, _) => self.store.is_lint_group(symbol),
|
||||||
LintLevelSource::CommandLine(symbol, _) => self.store.is_lint_group(symbol),
|
LintLevelSource::CommandLine(symbol, _) => self.store.is_lint_group(symbol),
|
||||||
|
LintLevelSource::ForceWarn(symbol) => {
|
||||||
|
bug!("forced warn lint returned a forbid lint level")
|
||||||
|
}
|
||||||
};
|
};
|
||||||
debug!(
|
debug!(
|
||||||
"fcw_warning={:?}, specs.get(&id) = {:?}, old_src={:?}, id_name={:?}",
|
"fcw_warning={:?}, specs.get(&id) = {:?}, old_src={:?}, id_name={:?}",
|
||||||
|
@ -166,6 +174,7 @@ impl<'s> LintLevelsBuilder<'s> {
|
||||||
LintLevelSource::CommandLine(_, _) => {
|
LintLevelSource::CommandLine(_, _) => {
|
||||||
diag_builder.note("`forbid` lint level was set on command line");
|
diag_builder.note("`forbid` lint level was set on command line");
|
||||||
}
|
}
|
||||||
|
_ => bug!("forced warn lint returned a forbid lint level"),
|
||||||
}
|
}
|
||||||
diag_builder.emit();
|
diag_builder.emit();
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
|
||||||
use crate::ich::StableHashingContext;
|
use crate::ich::StableHashingContext;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use chalk_ir::Substitution;
|
||||||
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||||
use rustc_errors::{DiagnosticBuilder, DiagnosticId};
|
use rustc_errors::{DiagnosticBuilder, DiagnosticId};
|
||||||
use rustc_hir::HirId;
|
use rustc_hir::HirId;
|
||||||
|
@ -28,6 +29,9 @@ pub enum LintLevelSource {
|
||||||
/// The provided `Level` is the level specified on the command line.
|
/// The provided `Level` is the level specified on the command line.
|
||||||
/// (The actual level may be lower due to `--cap-lints`.)
|
/// (The actual level may be lower due to `--cap-lints`.)
|
||||||
CommandLine(Symbol, Level),
|
CommandLine(Symbol, Level),
|
||||||
|
|
||||||
|
/// Lint is being forced to warn no matter what.
|
||||||
|
ForceWarn(Symbol),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LintLevelSource {
|
impl LintLevelSource {
|
||||||
|
@ -36,6 +40,7 @@ impl LintLevelSource {
|
||||||
LintLevelSource::Default => symbol::kw::Default,
|
LintLevelSource::Default => symbol::kw::Default,
|
||||||
LintLevelSource::Node(name, _, _) => name,
|
LintLevelSource::Node(name, _, _) => name,
|
||||||
LintLevelSource::CommandLine(name, _) => name,
|
LintLevelSource::CommandLine(name, _) => name,
|
||||||
|
LintLevelSource::ForceWarn(name) => name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +49,7 @@ impl LintLevelSource {
|
||||||
LintLevelSource::Default => DUMMY_SP,
|
LintLevelSource::Default => DUMMY_SP,
|
||||||
LintLevelSource::Node(_, span, _) => span,
|
LintLevelSource::Node(_, span, _) => span,
|
||||||
LintLevelSource::CommandLine(_, _) => DUMMY_SP,
|
LintLevelSource::CommandLine(_, _) => DUMMY_SP,
|
||||||
|
LintLevelSource::ForceWarn(_) => DUMMY_SP,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,6 +61,7 @@ pub type LevelAndSource = (Level, LintLevelSource);
|
||||||
pub struct LintLevelSets {
|
pub struct LintLevelSets {
|
||||||
pub list: Vec<LintSet>,
|
pub list: Vec<LintSet>,
|
||||||
pub lint_cap: Level,
|
pub lint_cap: Level,
|
||||||
|
pub force_warns: FxHashSet<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -73,7 +80,11 @@ pub enum LintSet {
|
||||||
|
|
||||||
impl LintLevelSets {
|
impl LintLevelSets {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
LintLevelSets { list: Vec::new(), lint_cap: Level::Forbid }
|
LintLevelSets {
|
||||||
|
list: Vec::new(),
|
||||||
|
lint_cap: Level::Forbid,
|
||||||
|
force_warns: FxHashSet::default(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_lint_level(
|
pub fn get_lint_level(
|
||||||
|
@ -83,6 +94,11 @@ impl LintLevelSets {
|
||||||
aux: Option<&FxHashMap<LintId, LevelAndSource>>,
|
aux: Option<&FxHashMap<LintId, LevelAndSource>>,
|
||||||
sess: &Session,
|
sess: &Session,
|
||||||
) -> LevelAndSource {
|
) -> LevelAndSource {
|
||||||
|
// Check whether we should always warn
|
||||||
|
if self.force_warns.contains(lint.name) {
|
||||||
|
return (Level::Warn, LintLevelSource::ForceWarn(Symbol::intern(lint.name)));
|
||||||
|
}
|
||||||
|
|
||||||
let (level, mut src) = self.get_lint_id_level(LintId::of(lint), idx, aux);
|
let (level, mut src) = self.get_lint_id_level(LintId::of(lint), idx, aux);
|
||||||
|
|
||||||
// If `level` is none then we actually assume the default level for this
|
// If `level` is none then we actually assume the default level for this
|
||||||
|
@ -176,11 +192,11 @@ impl LintLevelMap {
|
||||||
impl<'a> HashStable<StableHashingContext<'a>> for LintLevelMap {
|
impl<'a> HashStable<StableHashingContext<'a>> for LintLevelMap {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
|
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
|
||||||
let LintLevelMap { ref sets, ref id_to_set } = *self;
|
let LintLevelMap { ref sets, ref id_to_set, .. } = *self;
|
||||||
|
|
||||||
id_to_set.hash_stable(hcx, hasher);
|
id_to_set.hash_stable(hcx, hasher);
|
||||||
|
|
||||||
let LintLevelSets { ref list, lint_cap } = *sets;
|
let LintLevelSets { ref list, lint_cap, .. } = *sets;
|
||||||
|
|
||||||
lint_cap.hash_stable(hcx, hasher);
|
lint_cap.hash_stable(hcx, hasher);
|
||||||
|
|
||||||
|
@ -346,6 +362,13 @@ pub fn struct_lint_level<'s, 'd>(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
LintLevelSource::ForceWarn(_) => {
|
||||||
|
sess.diag_note_once(
|
||||||
|
&mut err,
|
||||||
|
DiagnosticMessageId::from(lint),
|
||||||
|
"Warning forced by `force-warns` commandline option",
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err.code(DiagnosticId::Lint { name, has_future_breakage });
|
err.code(DiagnosticId::Lint { name, has_future_breakage });
|
||||||
|
|
|
@ -677,6 +677,7 @@ impl Default for Options {
|
||||||
optimize: OptLevel::No,
|
optimize: OptLevel::No,
|
||||||
debuginfo: DebugInfo::None,
|
debuginfo: DebugInfo::None,
|
||||||
lint_opts: Vec::new(),
|
lint_opts: Vec::new(),
|
||||||
|
force_warns: Vec::new(),
|
||||||
lint_cap: None,
|
lint_cap: None,
|
||||||
describe_lints: false,
|
describe_lints: false,
|
||||||
output_types: OutputTypes(BTreeMap::new()),
|
output_types: OutputTypes(BTreeMap::new()),
|
||||||
|
@ -1092,6 +1093,13 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
|
||||||
level",
|
level",
|
||||||
"LEVEL",
|
"LEVEL",
|
||||||
),
|
),
|
||||||
|
opt::multi_s(
|
||||||
|
"",
|
||||||
|
"force-warns",
|
||||||
|
"Specifiy lints that should warn even if \
|
||||||
|
they are allowed somewhere else",
|
||||||
|
"LINT",
|
||||||
|
),
|
||||||
opt::multi_s("C", "codegen", "Set a codegen option", "OPT[=VALUE]"),
|
opt::multi_s("C", "codegen", "Set a codegen option", "OPT[=VALUE]"),
|
||||||
opt::flag_s("V", "version", "Print version info and exit"),
|
opt::flag_s("V", "version", "Print version info and exit"),
|
||||||
opt::flag_s("v", "verbose", "Use verbose output"),
|
opt::flag_s("v", "verbose", "Use verbose output"),
|
||||||
|
@ -1156,7 +1164,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
|
||||||
pub fn get_cmd_lint_options(
|
pub fn get_cmd_lint_options(
|
||||||
matches: &getopts::Matches,
|
matches: &getopts::Matches,
|
||||||
error_format: ErrorOutputType,
|
error_format: ErrorOutputType,
|
||||||
) -> (Vec<(String, lint::Level)>, bool, Option<lint::Level>) {
|
) -> (Vec<(String, lint::Level)>, bool, Option<lint::Level>, Vec<String>) {
|
||||||
let mut lint_opts_with_position = vec![];
|
let mut lint_opts_with_position = vec![];
|
||||||
let mut describe_lints = false;
|
let mut describe_lints = false;
|
||||||
|
|
||||||
|
@ -1189,7 +1197,10 @@ pub fn get_cmd_lint_options(
|
||||||
lint::Level::from_str(&cap)
|
lint::Level::from_str(&cap)
|
||||||
.unwrap_or_else(|| early_error(error_format, &format!("unknown lint level: `{}`", cap)))
|
.unwrap_or_else(|| early_error(error_format, &format!("unknown lint level: `{}`", cap)))
|
||||||
});
|
});
|
||||||
(lint_opts, describe_lints, lint_cap)
|
|
||||||
|
let force_warns = matches.opt_strs("force-warns");
|
||||||
|
|
||||||
|
(lint_opts, describe_lints, lint_cap, force_warns)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses the `--color` flag.
|
/// Parses the `--color` flag.
|
||||||
|
@ -1926,7 +1937,8 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
||||||
let crate_types = parse_crate_types_from_list(unparsed_crate_types)
|
let crate_types = parse_crate_types_from_list(unparsed_crate_types)
|
||||||
.unwrap_or_else(|e| early_error(error_format, &e[..]));
|
.unwrap_or_else(|e| early_error(error_format, &e[..]));
|
||||||
|
|
||||||
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);
|
let (lint_opts, describe_lints, lint_cap, force_warns) =
|
||||||
|
get_cmd_lint_options(matches, error_format);
|
||||||
|
|
||||||
let mut debugging_opts = DebuggingOptions::build(matches, error_format);
|
let mut debugging_opts = DebuggingOptions::build(matches, error_format);
|
||||||
check_debug_option_stability(&debugging_opts, error_format, json_rendered);
|
check_debug_option_stability(&debugging_opts, error_format, json_rendered);
|
||||||
|
@ -2100,6 +2112,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
||||||
optimize: opt_level,
|
optimize: opt_level,
|
||||||
debuginfo,
|
debuginfo,
|
||||||
lint_opts,
|
lint_opts,
|
||||||
|
force_warns,
|
||||||
lint_cap,
|
lint_cap,
|
||||||
describe_lints,
|
describe_lints,
|
||||||
output_types,
|
output_types,
|
||||||
|
|
|
@ -130,6 +130,7 @@ top_level_options!(
|
||||||
debuginfo: DebugInfo [TRACKED],
|
debuginfo: DebugInfo [TRACKED],
|
||||||
lint_opts: Vec<(String, lint::Level)> [TRACKED],
|
lint_opts: Vec<(String, lint::Level)> [TRACKED],
|
||||||
lint_cap: Option<lint::Level> [TRACKED],
|
lint_cap: Option<lint::Level> [TRACKED],
|
||||||
|
force_warns: Vec<String> [TRACKED],
|
||||||
describe_lints: bool [UNTRACKED],
|
describe_lints: bool [UNTRACKED],
|
||||||
output_types: OutputTypes [TRACKED],
|
output_types: OutputTypes [TRACKED],
|
||||||
search_paths: Vec<SearchPath> [UNTRACKED],
|
search_paths: Vec<SearchPath> [UNTRACKED],
|
||||||
|
|
9
src/test/ui/lint/force-warn/force-allow-all-warnings.rs
Normal file
9
src/test/ui/lint/force-warn/force-allow-all-warnings.rs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
// compile-flags: --force-warns dead_code
|
||||||
|
// check-pass
|
||||||
|
|
||||||
|
#![allow(warnings)]
|
||||||
|
|
||||||
|
fn dead_function() {}
|
||||||
|
//~^ WARN function is never used
|
||||||
|
|
||||||
|
fn main() {}
|
10
src/test/ui/lint/force-warn/force-allow-all-warnings.stderr
Normal file
10
src/test/ui/lint/force-warn/force-allow-all-warnings.stderr
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
warning: function is never used: `dead_function`
|
||||||
|
--> $DIR/force-allow-all-warnings.rs:6:4
|
||||||
|
|
|
||||||
|
LL | fn dead_function() {}
|
||||||
|
| ^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: Warning forced by `force-warns` commandline option
|
||||||
|
|
||||||
|
warning: 1 warning emitted
|
||||||
|
|
11
src/test/ui/lint/force-warn/force-allow-by-default.rs
Normal file
11
src/test/ui/lint/force-warn/force-allow-by-default.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
// compile-flags: --force-warns elided_lifetimes_in_paths
|
||||||
|
// check-pass
|
||||||
|
|
||||||
|
struct Foo<'a> {
|
||||||
|
x: &'a u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo(x: &Foo) {}
|
||||||
|
//~^ WARN hidden lifetime parameters in types are deprecated
|
||||||
|
|
||||||
|
fn main() {}
|
10
src/test/ui/lint/force-warn/force-allow-by-default.stderr
Normal file
10
src/test/ui/lint/force-warn/force-allow-by-default.stderr
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
warning: hidden lifetime parameters in types are deprecated
|
||||||
|
--> $DIR/force-allow-by-default.rs:8:12
|
||||||
|
|
|
||||||
|
LL | fn foo(x: &Foo) {}
|
||||||
|
| ^^^- help: indicate the anonymous lifetime: `<'_>`
|
||||||
|
|
|
||||||
|
= note: Warning forced by `force-warns` commandline option
|
||||||
|
|
||||||
|
warning: 1 warning emitted
|
||||||
|
|
10
src/test/ui/lint/force-warn/force-allowed-deny.rs
Normal file
10
src/test/ui/lint/force-warn/force-allowed-deny.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
// ignore-test
|
||||||
|
// compile-flags: --force-warns arithmetic_overflow
|
||||||
|
// check-pass
|
||||||
|
|
||||||
|
#![allow(arithmetic_overflow)]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
1_i32 << 32;
|
||||||
|
//~^ WARN this arithmetic operation will overflow
|
||||||
|
}
|
12
src/test/ui/lint/force-warn/force-allowed-group.rs
Normal file
12
src/test/ui/lint/force-warn/force-allowed-group.rs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
// compile-flags: --force-warns bare_trait_objects
|
||||||
|
// check-pass
|
||||||
|
|
||||||
|
#![allow(rust_2018_compatibility)]
|
||||||
|
|
||||||
|
pub trait SomeTrait {}
|
||||||
|
|
||||||
|
pub fn function(_x: Box<SomeTrait>) {}
|
||||||
|
//~^ WARN trait objects without an explicit `dyn` are deprecated
|
||||||
|
//~| WARN this was previously accepted by the compiler
|
||||||
|
|
||||||
|
fn main() {}
|
12
src/test/ui/lint/force-warn/force-allowed-group.stderr
Normal file
12
src/test/ui/lint/force-warn/force-allowed-group.stderr
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
warning: trait objects without an explicit `dyn` are deprecated
|
||||||
|
--> $DIR/force-allowed-group.rs:8:25
|
||||||
|
|
|
||||||
|
LL | pub fn function(_x: Box<SomeTrait>) {}
|
||||||
|
| ^^^^^^^^^ help: use `dyn`: `dyn SomeTrait`
|
||||||
|
|
|
||||||
|
= note: Warning forced by `force-warns` commandline option
|
||||||
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
|
||||||
|
= note: for more information, see issue #80165 <https://github.com/rust-lang/rust/issues/80165>
|
||||||
|
|
||||||
|
warning: 1 warning emitted
|
||||||
|
|
9
src/test/ui/lint/force-warn/force-allowed-warning.rs
Normal file
9
src/test/ui/lint/force-warn/force-allowed-warning.rs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
// compile-flags: --force-warns dead_code
|
||||||
|
// check-pass
|
||||||
|
|
||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
fn dead_function() {}
|
||||||
|
//~^ WARN function is never used
|
||||||
|
|
||||||
|
fn main() {}
|
10
src/test/ui/lint/force-warn/force-allowed-warning.stderr
Normal file
10
src/test/ui/lint/force-warn/force-allowed-warning.stderr
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
warning: function is never used: `dead_function`
|
||||||
|
--> $DIR/force-allowed-warning.rs:6:4
|
||||||
|
|
|
||||||
|
LL | fn dead_function() {}
|
||||||
|
| ^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: Warning forced by `force-warns` commandline option
|
||||||
|
|
||||||
|
warning: 1 warning emitted
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue