Force warn on lint groups as well
This commit is contained in:
parent
4675690ac4
commit
3b206b7a70
19 changed files with 114 additions and 26 deletions
|
@ -334,8 +334,14 @@ impl LintStore {
|
|||
}
|
||||
}
|
||||
|
||||
/// Checks the validity of lint names derived from the command line
|
||||
pub fn check_lint_name_cmdline(&self, sess: &Session, lint_name: &str, level: Level) {
|
||||
/// Checks the validity of lint names derived from the command line. Returns
|
||||
/// true if the lint is valid, false otherwise.
|
||||
pub fn check_lint_name_cmdline(
|
||||
&self,
|
||||
sess: &Session,
|
||||
lint_name: &str,
|
||||
level: Option<Level>,
|
||||
) -> bool {
|
||||
let db = match self.check_lint_name(lint_name, None) {
|
||||
CheckLintNameResult::Ok(_) => None,
|
||||
CheckLintNameResult::Warning(ref msg, _) => Some(sess.struct_warn(msg)),
|
||||
|
@ -361,18 +367,23 @@ impl LintStore {
|
|||
};
|
||||
|
||||
if let Some(mut db) = db {
|
||||
let msg = format!(
|
||||
"requested on the command line with `{} {}`",
|
||||
match level {
|
||||
Level::Allow => "-A",
|
||||
Level::Warn => "-W",
|
||||
Level::Deny => "-D",
|
||||
Level::Forbid => "-F",
|
||||
},
|
||||
lint_name
|
||||
);
|
||||
db.note(&msg);
|
||||
if let Some(level) = level {
|
||||
let msg = format!(
|
||||
"requested on the command line with `{} {}`",
|
||||
match level {
|
||||
Level::Allow => "-A",
|
||||
Level::Warn => "-W",
|
||||
Level::Deny => "-D",
|
||||
Level::Forbid => "-F",
|
||||
},
|
||||
lint_name
|
||||
);
|
||||
db.note(&msg);
|
||||
}
|
||||
db.emit();
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ impl<'s> LintLevelsBuilder<'s> {
|
|||
self.sets.lint_cap = sess.opts.lint_cap.unwrap_or(Level::Forbid);
|
||||
|
||||
for &(ref lint_name, level) in &sess.opts.lint_opts {
|
||||
store.check_lint_name_cmdline(sess, &lint_name, level);
|
||||
store.check_lint_name_cmdline(sess, &lint_name, Some(level));
|
||||
let orig_level = level;
|
||||
|
||||
// If the cap is less than this specified level, e.g., if we've got
|
||||
|
@ -110,8 +110,13 @@ 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());
|
||||
let valid = store.check_lint_name_cmdline(sess, lint_name, None);
|
||||
if valid {
|
||||
let lints = store
|
||||
.find_lints(lint_name)
|
||||
.unwrap_or_else(|_| bug!("A valid lint failed to produce a lint ids"));
|
||||
self.sets.force_warns.extend(&lints);
|
||||
}
|
||||
}
|
||||
|
||||
self.sets.list.push(LintSet::CommandLine { specs });
|
||||
|
|
|
@ -60,7 +60,7 @@ pub type LevelAndSource = (Level, LintLevelSource);
|
|||
pub struct LintLevelSets {
|
||||
pub list: Vec<LintSet>,
|
||||
pub lint_cap: Level,
|
||||
pub force_warns: FxHashSet<String>,
|
||||
pub force_warns: FxHashSet<LintId>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -94,7 +94,7 @@ impl LintLevelSets {
|
|||
sess: &Session,
|
||||
) -> LevelAndSource {
|
||||
// Check whether we should always warn
|
||||
if self.force_warns.contains(lint.name) {
|
||||
if self.force_warns.contains(&LintId::of(lint)) {
|
||||
return (Level::Warn, LintLevelSource::ForceWarn(Symbol::intern(lint.name)));
|
||||
}
|
||||
|
||||
|
|
|
@ -1164,6 +1164,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
|
|||
pub fn get_cmd_lint_options(
|
||||
matches: &getopts::Matches,
|
||||
error_format: ErrorOutputType,
|
||||
debugging_opts: &DebuggingOptions,
|
||||
) -> (Vec<(String, lint::Level)>, bool, Option<lint::Level>, Vec<String>) {
|
||||
let mut lint_opts_with_position = vec![];
|
||||
let mut describe_lints = false;
|
||||
|
@ -1198,6 +1199,14 @@ pub fn get_cmd_lint_options(
|
|||
.unwrap_or_else(|| early_error(error_format, &format!("unknown lint level: `{}`", cap)))
|
||||
});
|
||||
|
||||
if !debugging_opts.unstable_options && matches.opt_present("force-warns") {
|
||||
early_error(
|
||||
error_format,
|
||||
"the `-Z unstable-options` flag must also be passed to enable \
|
||||
the flag `--force-warns=lints`",
|
||||
);
|
||||
}
|
||||
|
||||
let force_warns = matches.opt_strs("force-warns");
|
||||
|
||||
(lint_opts, describe_lints, lint_cap, force_warns)
|
||||
|
@ -1937,10 +1946,10 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
|||
let crate_types = parse_crate_types_from_list(unparsed_crate_types)
|
||||
.unwrap_or_else(|e| early_error(error_format, &e[..]));
|
||||
|
||||
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 (lint_opts, describe_lints, lint_cap, force_warns) =
|
||||
get_cmd_lint_options(matches, error_format, &debugging_opts);
|
||||
|
||||
check_debug_option_stability(&debugging_opts, error_format, json_rendered);
|
||||
|
||||
if !debugging_opts.unstable_options && json_unused_externs {
|
||||
|
|
|
@ -635,7 +635,8 @@ impl Options {
|
|||
let generate_redirect_map = matches.opt_present("generate-redirect-map");
|
||||
let show_type_layout = matches.opt_present("show-type-layout");
|
||||
|
||||
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);
|
||||
let (lint_opts, describe_lints, lint_cap, _) =
|
||||
get_cmd_lint_options(matches, error_format, &debugging_opts);
|
||||
|
||||
Ok(Options {
|
||||
input,
|
||||
|
|
|
@ -510,6 +510,14 @@ fn opts() -> Vec<RustcOptGroup> {
|
|||
"LEVEL",
|
||||
)
|
||||
}),
|
||||
unstable("force-warns", |o| {
|
||||
o.optopt(
|
||||
"",
|
||||
"force-warns",
|
||||
"Lints that will warn even if allowed somewhere else",
|
||||
"LINTS",
|
||||
)
|
||||
}),
|
||||
unstable("index-page", |o| {
|
||||
o.optopt("", "index-page", "Markdown file to be used as index page", "PATH")
|
||||
}),
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
warning: hidden lifetime parameters in types are deprecated
|
||||
--> $DIR/force-allow-by-default.rs:8:12
|
||||
--> $DIR/force-allowed-by-default-lint.rs:8:12
|
||||
|
|
||||
LL | fn foo(x: &Foo) {}
|
||||
| ^^^- help: indicate the anonymous lifetime: `<'_>`
|
|
@ -1,5 +1,5 @@
|
|||
warning: function is never used: `dead_function`
|
||||
--> $DIR/force-allow-all-warnings.rs:6:4
|
||||
--> $DIR/force-lint-allow-all-warnings.rs:6:4
|
||||
|
|
||||
LL | fn dead_function() {}
|
||||
| ^^^^^^^^^^^^^
|
|
@ -0,0 +1,9 @@
|
|||
// compile-flags: --force-warns nonstandard_style
|
||||
// check-pass
|
||||
|
||||
#![allow(warnings)]
|
||||
|
||||
pub fn FUNCTION() {}
|
||||
//~^ WARN function `FUNCTION` should have a snake case name
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,10 @@
|
|||
warning: function `FUNCTION` should have a snake case name
|
||||
--> $DIR/force-lint-group-allow-all-warnings.rs:6:8
|
||||
|
|
||||
LL | pub fn FUNCTION() {}
|
||||
| ^^^^^^^^ help: convert the identifier to snake case: `function`
|
||||
|
|
||||
= note: Warning forced by `force-warns` commandline option
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
warning: trait objects without an explicit `dyn` are deprecated
|
||||
--> $DIR/force-lint-in-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
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
// compile-flags: --force-warns rust_2018_idioms
|
||||
// check-pass
|
||||
|
||||
#![allow(bare_trait_objects)]
|
||||
|
||||
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() {}
|
|
@ -0,0 +1,12 @@
|
|||
warning: trait objects without an explicit `dyn` are deprecated
|
||||
--> $DIR/force-warn-group-allow-warning.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
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
// ignore-test
|
||||
// compile-flags: --force-warns rust_2018_idioms
|
||||
// check-pass
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
warning: trait objects without an explicit `dyn` are deprecated
|
||||
--> $DIR/force-allowed-group.rs:8:25
|
||||
--> $DIR/force-warn-group.rs:8:25
|
||||
|
|
||||
LL | pub fn function(_x: Box<SomeTrait>) {}
|
||||
| ^^^^^^^^^ help: use `dyn`: `dyn SomeTrait`
|
Loading…
Add table
Add a link
Reference in a new issue