diff options
19 files changed, 113 insertions, 25 deletions
diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index c1d6a4f1de1..5c54f06acfa 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -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 } } diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index 4f3d98304e7..0ee434f5fb5 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -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 }); diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs index f3088326db8..85080354e4d 100644 --- a/compiler/rustc_middle/src/lint.rs +++ b/compiler/rustc_middle/src/lint.rs @@ -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))); } diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 5a9da2f2590..9306abc85ba 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -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 mut debugging_opts = DebuggingOptions::build(matches, error_format); let (lint_opts, describe_lints, lint_cap, force_warns) = - get_cmd_lint_options(matches, error_format); + get_cmd_lint_options(matches, error_format, &debugging_opts); - let mut debugging_opts = DebuggingOptions::build(matches, error_format); check_debug_option_stability(&debugging_opts, error_format, json_rendered); if !debugging_opts.unstable_options && json_unused_externs { diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 6e1fdf67a65..29e8578d944 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -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, diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 6488625c5a8..3ad3a530690 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -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") }), diff --git a/src/test/ui/lint/force-warn/force-allow-by-default.rs b/src/test/ui/lint/force-warn/force-allowed-by-default-lint.rs index d4a5056ddf3..d4a5056ddf3 100644 --- a/src/test/ui/lint/force-warn/force-allow-by-default.rs +++ b/src/test/ui/lint/force-warn/force-allowed-by-default-lint.rs diff --git a/src/test/ui/lint/force-warn/force-allow-by-default.stderr b/src/test/ui/lint/force-warn/force-allowed-by-default-lint.stderr index 9f62e85e545..24ccfe61077 100644 --- a/src/test/ui/lint/force-warn/force-allow-by-default.stderr +++ b/src/test/ui/lint/force-warn/force-allowed-by-default-lint.stderr @@ -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: `<'_>` diff --git a/src/test/ui/lint/force-warn/force-allowed-deny.rs b/src/test/ui/lint/force-warn/force-allowed-deny-by-default-lint.rs index b34fb5d8b84..b34fb5d8b84 100644 --- a/src/test/ui/lint/force-warn/force-allowed-deny.rs +++ b/src/test/ui/lint/force-warn/force-allowed-deny-by-default-lint.rs diff --git a/src/test/ui/lint/force-warn/force-allow-all-warnings.rs b/src/test/ui/lint/force-warn/force-lint-allow-all-warnings.rs index 5501faa437a..5501faa437a 100644 --- a/src/test/ui/lint/force-warn/force-allow-all-warnings.rs +++ b/src/test/ui/lint/force-warn/force-lint-allow-all-warnings.rs diff --git a/src/test/ui/lint/force-warn/force-allow-all-warnings.stderr b/src/test/ui/lint/force-warn/force-lint-allow-all-warnings.stderr index c19f1fe780f..dc9af8997b2 100644 --- a/src/test/ui/lint/force-warn/force-allow-all-warnings.stderr +++ b/src/test/ui/lint/force-warn/force-lint-allow-all-warnings.stderr @@ -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() {} | ^^^^^^^^^^^^^ diff --git a/src/test/ui/lint/force-warn/force-lint-group-allow-all-warnings.rs b/src/test/ui/lint/force-warn/force-lint-group-allow-all-warnings.rs new file mode 100644 index 00000000000..9009971f0cf --- /dev/null +++ b/src/test/ui/lint/force-warn/force-lint-group-allow-all-warnings.rs @@ -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() {} diff --git a/src/test/ui/lint/force-warn/force-lint-group-allow-all-warnings.stderr b/src/test/ui/lint/force-warn/force-lint-group-allow-all-warnings.stderr new file mode 100644 index 00000000000..3965d5ca238 --- /dev/null +++ b/src/test/ui/lint/force-warn/force-lint-group-allow-all-warnings.stderr @@ -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 + diff --git a/src/test/ui/lint/force-warn/force-allowed-group.rs b/src/test/ui/lint/force-warn/force-lint-in-allowed-group.rs index b68b979ca11..b68b979ca11 100644 --- a/src/test/ui/lint/force-warn/force-allowed-group.rs +++ b/src/test/ui/lint/force-warn/force-lint-in-allowed-group.rs diff --git a/src/test/ui/lint/force-warn/force-lint-in-allowed-group.stderr b/src/test/ui/lint/force-warn/force-lint-in-allowed-group.stderr new file mode 100644 index 00000000000..a28b14ebc9b --- /dev/null +++ b/src/test/ui/lint/force-warn/force-lint-in-allowed-group.stderr @@ -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 + diff --git a/src/test/ui/lint/force-warn/force-warn-group-allow-warning.rs b/src/test/ui/lint/force-warn/force-warn-group-allow-warning.rs new file mode 100644 index 00000000000..357a79b383d --- /dev/null +++ b/src/test/ui/lint/force-warn/force-warn-group-allow-warning.rs @@ -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() {} diff --git a/src/test/ui/lint/force-warn/force-warn-group-allow-warning.stderr b/src/test/ui/lint/force-warn/force-warn-group-allow-warning.stderr new file mode 100644 index 00000000000..f57dd1e70dc --- /dev/null +++ b/src/test/ui/lint/force-warn/force-warn-group-allow-warning.stderr @@ -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 + diff --git a/src/test/ui/lint/force-warn/force-warn-group.rs b/src/test/ui/lint/force-warn/force-warn-group.rs index 3206d75e940..a4615df42de 100644 --- a/src/test/ui/lint/force-warn/force-warn-group.rs +++ b/src/test/ui/lint/force-warn/force-warn-group.rs @@ -1,4 +1,3 @@ -// ignore-test // compile-flags: --force-warns rust_2018_idioms // check-pass diff --git a/src/test/ui/lint/force-warn/force-allowed-group.stderr b/src/test/ui/lint/force-warn/force-warn-group.stderr index 9fdd998ebf4..f2b0ce04b54 100644 --- a/src/test/ui/lint/force-warn/force-allowed-group.stderr +++ b/src/test/ui/lint/force-warn/force-warn-group.stderr @@ -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` |
