diff options
| author | inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com> | 2021-07-08 00:05:38 -0700 |
|---|---|---|
| committer | inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com> | 2021-07-17 23:13:59 -0700 |
| commit | 2f2db99432c7fd5bd7e8bf274bb449107e1bd116 (patch) | |
| tree | 10fc444777af210ebdb37bd12feb738b86dd2a6b /compiler | |
| parent | 77d155973c6c22a0e1af49a4a9bac024f697851d (diff) | |
| download | rust-2f2db99432c7fd5bd7e8bf274bb449107e1bd116.tar.gz rust-2f2db99432c7fd5bd7e8bf274bb449107e1bd116.zip | |
Make `--force-warns` a normal lint level option
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_lint/src/levels.rs | 24 | ||||
| -rw-r--r-- | compiler/rustc_session/src/config.rs | 39 | ||||
| -rw-r--r-- | compiler/rustc_session/src/options.rs | 1 |
3 files changed, 18 insertions, 46 deletions
diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index bc6956f5797..069fa41fa88 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -26,8 +26,6 @@ use rustc_span::symbol::{sym, Symbol}; use rustc_span::{source_map::MultiSpan, Span, DUMMY_SP}; use tracing::debug; -use std::cmp; - fn lint_levels(tcx: TyCtxt<'_>, (): ()) -> LintLevelMap { let store = unerased_lint_store(tcx); let crate_attrs = tcx.hir().attrs(CRATE_HIR_ID); @@ -91,12 +89,6 @@ impl<'s> LintLevelsBuilder<'s> { for &(ref lint_name, level) in &sess.opts.lint_opts { store.check_lint_name_cmdline(sess, &lint_name, level, self.crate_attrs); let orig_level = level; - - // If the cap is less than this specified level, e.g., if we've got - // `--cap-lints allow` but we've also got `-D foo` then we ignore - // this specification as the lint cap will set it to allow anyway. - let level = cmp::min(level, self.sets.lint_cap); - let lint_flag_val = Symbol::intern(lint_name); let ids = match store.find_lints(&lint_name) { @@ -104,23 +96,17 @@ impl<'s> LintLevelsBuilder<'s> { Err(_) => continue, // errors handled in check_lint_name_cmdline above }; for id in ids { + // ForceWarn and Forbid cannot be overriden + if let Some((Level::ForceWarn | Level::Forbid, _)) = specs.get(&id) { + continue; + } + self.check_gated_lint(id, DUMMY_SP); let src = LintLevelSource::CommandLine(lint_flag_val, orig_level); specs.insert(id, (level, src)); } } - for lint_name in &sess.opts.force_warns { - store.check_lint_name_cmdline(sess, lint_name, Level::ForceWarn, self.crate_attrs); - let lints = store - .find_lints(lint_name) - .unwrap_or_else(|_| bug!("A valid lint failed to produce a lint ids")); - for id in lints { - let src = LintLevelSource::CommandLine(Symbol::intern(lint_name), Level::ForceWarn); - specs.insert(id, (Level::ForceWarn, src)); - } - } - self.cur = self.sets.list.push(LintSet { specs, parent: COMMAND_LINE }); } diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index b444f66258a..9e5a38b8dc0 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -677,7 +677,6 @@ impl Default for Options { optimize: OptLevel::No, debuginfo: DebugInfo::None, lint_opts: Vec::new(), - force_warns: Vec::new(), lint_cap: None, describe_lints: false, output_types: OutputTypes(BTreeMap::new()), @@ -1172,20 +1171,20 @@ 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>) { +) -> (Vec<(String, lint::Level)>, bool, Option<lint::Level>) { let mut lint_opts_with_position = vec![]; let mut describe_lints = false; - for level in [lint::Allow, lint::Warn, lint::Deny, lint::Forbid] { - for (passed_arg_pos, lint_name) in matches.opt_strs_pos(level.as_str()) { - let arg_pos = if let lint::Forbid = level { - // HACK: forbid is always specified last, so it can't be overridden. - // FIXME: remove this once <https://github.com/rust-lang/rust/issues/70819> is - // fixed and `forbid` works as expected. - usize::MAX - } else { - passed_arg_pos - }; + 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`", + ); + } + + for level in [lint::Allow, lint::Warn, lint::ForceWarn, lint::Deny, lint::Forbid] { + for (arg_pos, lint_name) in matches.opt_strs_pos(level.as_str()) { if lint_name == "help" { describe_lints = true; } else { @@ -1206,18 +1205,7 @@ 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").into_iter().map(|name| name.replace('-', "_")).collect(); - - (lint_opts, describe_lints, lint_cap, force_warns) + (lint_opts, describe_lints, lint_cap) } /// Parses the `--color` flag. @@ -1955,7 +1943,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { .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) = + let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format, &debugging_opts); check_debug_option_stability(&debugging_opts, error_format, json_rendered); @@ -2129,7 +2117,6 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { optimize: opt_level, debuginfo, lint_opts, - force_warns, lint_cap, describe_lints, output_types, diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 8e2e33f2d51..d7b9c911737 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -135,7 +135,6 @@ top_level_options!( debuginfo: DebugInfo [TRACKED], lint_opts: Vec<(String, lint::Level)> [TRACKED_NO_CRATE_HASH], lint_cap: Option<lint::Level> [TRACKED_NO_CRATE_HASH], - force_warns: Vec<String> [TRACKED_NO_CRATE_HASH], describe_lints: bool [UNTRACKED], output_types: OutputTypes [TRACKED], search_paths: Vec<SearchPath> [UNTRACKED], |
